All checks were successful
* Add plugin option for protogen in Makefile * Fix the generator for the plugin in util/protogen * Erase convertable types, move helpful methods to gRPC protobufs * Erase helpers for convertations * Generate StableMarshlal/StableSize for protobufs by the protoc plugin Signed-off-by: Airat Arifullin a.arifullin@yadro.com
88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
package status
|
|
|
|
const sectionBitSize = 10
|
|
|
|
// EqualNumber checks if the numerical Code equals num.
|
|
func EqualNumber(code, num uint32) bool {
|
|
return code == num
|
|
}
|
|
|
|
// InSections checks if the Code is in [i,j] section list.
|
|
func InSections(code, i, j uint32) bool {
|
|
return code >= i<<sectionBitSize && code < (j+1)<<sectionBitSize
|
|
}
|
|
|
|
// LocalizeSection localizes the Code to the sec-th section.
|
|
//
|
|
// Does not make sense if the Code is outside the section.
|
|
func LocalizeSection(code *uint32, sec uint32) {
|
|
*code = *code - sec<<sectionBitSize
|
|
}
|
|
|
|
// GlobalizeSection globalizes the Code of the sec-th section.
|
|
//
|
|
// Does not make sense if the Code is outside the section.
|
|
func GlobalizeSection(code *uint32, sec uint32) {
|
|
*code = *code + sec<<sectionBitSize
|
|
}
|
|
|
|
// IsInSection returns true if the Code belongs to sec-th section.
|
|
func IsInSection(code uint32, sec uint32) bool {
|
|
return InSections(code, sec, sec)
|
|
}
|
|
|
|
const successSections = 1
|
|
|
|
// IsSuccess checks if the Code is a success code.
|
|
func IsSuccess(c uint32) bool {
|
|
return InSections(c, 0, successSections-1)
|
|
}
|
|
|
|
// LocalizeSuccess localizes the Code to the success section.
|
|
func LocalizeSuccess(c *uint32) {
|
|
LocalizeSection(c, 0)
|
|
}
|
|
|
|
// GlobalizeSuccess globalizes the Code to the success section.
|
|
func GlobalizeSuccess(c *uint32) {
|
|
GlobalizeSection(c, 0)
|
|
}
|
|
|
|
func sectionAfterSuccess(sec uint32) uint32 {
|
|
return successSections + sec
|
|
}
|
|
|
|
const (
|
|
_ = iota - 1
|
|
sectionCommon
|
|
)
|
|
|
|
// IsCommonFail checks if the Code is a common failure code.
|
|
func IsCommonFail(c uint32) bool {
|
|
return IsInSection(c, sectionAfterSuccess(sectionCommon))
|
|
}
|
|
|
|
// LocalizeCommonFail localizes the Code to the common fail section.
|
|
func LocalizeCommonFail(c *uint32) {
|
|
LocalizeSection(c, sectionAfterSuccess(sectionCommon))
|
|
}
|
|
|
|
// GlobalizeCommonFail globalizes the Code to the common fail section.
|
|
func GlobalizeCommonFail(c *uint32) {
|
|
GlobalizeSection(c, sectionAfterSuccess(sectionCommon))
|
|
}
|
|
|
|
// LocalizeIfInSection checks if passed global status.Code belongs to the section and:
|
|
//
|
|
// then localizes the code and returns true,
|
|
// else leaves the code unchanged and returns false.
|
|
//
|
|
// Arg must not be nil.
|
|
func LocalizeIfInSection(c *uint32, sec uint32) bool {
|
|
if IsInSection(*c, sec) {
|
|
LocalizeSection(c, sec)
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|