fix constants

This commit is contained in:
Roy Olav Purser 2022-01-29 13:03:17 +01:00
parent 02d36e3d69
commit 179666c8f9
Signed by: roypur
GPG Key ID: E14D26A036F21656
3 changed files with 28 additions and 23 deletions

View File

@ -5,29 +5,34 @@ import (
"time" "time"
) )
type DataType uint type DataType uint32
const ( const (
TypeNone DataType = iota sizeBitmask DataType = 0xffff
TypeInt DataType = iota typeBitmask DataType = sizeBitmask << 16
TypeMetric DataType = iota
TypeDuration DataType = iota
TypeString DataType = iota
TypeDirectory DataType = iota
TypeBool DataType = iota
TypeHex DataType = iota
) )
func FixedHex(size uint) DataType { const (
return (DataType)(size<<16) | TypeHex TypeNone DataType = iota << 16
TypeInt DataType = iota << 16
TypeMetric DataType = iota << 16
TypeDuration DataType = iota << 16
TypeString DataType = iota << 16
TypeDirectory DataType = iota << 16
TypeBool DataType = iota << 16
TypeHex DataType = iota << 16
)
func FixedHex(size uint16) DataType {
return TypeHex | DataType(size)
} }
func (dtype DataType) baseType() DataType { func (dtype DataType) baseType() DataType {
return dtype & 0xffff return dtype & typeBitmask
} }
func (dtype DataType) typeAndSize() (DataType, uint) { func (dtype DataType) typeAndSize() (DataType, int) {
return (dtype & 0xffff), uint(dtype >> 16) return (dtype & typeBitmask), int(dtype & sizeBitmask)
} }
type cValue struct { type cValue struct {

View File

@ -11,7 +11,7 @@ import (
"time" "time"
) )
func parseInt(key string, str string, _ uint) (ret cValue) { func parseInt(key string, str string, _ int) (ret cValue) {
val, err := strconv.ParseInt(str, 10, 64) val, err := strconv.ParseInt(str, 10, 64)
if err == nil { if err == nil {
ret.intval = val ret.intval = val
@ -21,7 +21,7 @@ func parseInt(key string, str string, _ uint) (ret cValue) {
return return
} }
func parseMetric(key string, str string, _ uint) (ret cValue) { func parseMetric(key string, str string, _ int) (ret cValue) {
mod := int64(1) mod := int64(1)
str = strings.ToUpper(str) str = strings.ToUpper(str)
if strings.HasSuffix(str, "K") { if strings.HasSuffix(str, "K") {
@ -46,7 +46,7 @@ func parseMetric(key string, str string, _ uint) (ret cValue) {
return return
} }
func parseDuration(key string, str string, _ uint) (ret cValue) { func parseDuration(key string, str string, _ int) (ret cValue) {
val, err := time.ParseDuration(str) val, err := time.ParseDuration(str)
if err == nil { if err == nil {
ret.durval = val ret.durval = val
@ -56,7 +56,7 @@ func parseDuration(key string, str string, _ uint) (ret cValue) {
return return
} }
func parseBool(key string, str string, _ uint) (ret cValue) { func parseBool(key string, str string, _ int) (ret cValue) {
val, err := strconv.ParseBool(str) val, err := strconv.ParseBool(str)
if err == nil { if err == nil {
ret.boolval = val ret.boolval = val
@ -66,9 +66,9 @@ func parseBool(key string, str string, _ uint) (ret cValue) {
return return
} }
func parseHex(key string, str string, size uint) (ret cValue) { func parseHex(key string, str string, size int) (ret cValue) {
val, err := hex.DecodeString(str) val, err := hex.DecodeString(str)
if err == nil && (size == 0 || size == uint(len(val))) { if err == nil && (size == 0 || size == len(val)) {
ret.binval = val ret.binval = val
} else { } else {
if size == 0 { if size == 0 {
@ -80,7 +80,7 @@ func parseHex(key string, str string, size uint) (ret cValue) {
return return
} }
func parseDirectory(_ string, str string, _ uint) (ret cValue) { func parseDirectory(_ string, str string, _ int) (ret cValue) {
wd, err := os.Getwd() wd, err := os.Getwd()
if err == nil { if err == nil {
if path.IsAbs(str) { if path.IsAbs(str) {
@ -94,7 +94,7 @@ func parseDirectory(_ string, str string, _ uint) (ret cValue) {
return return
} }
func parseString(_ string, str string, _ uint) (ret cValue) { func parseString(_ string, str string, _ int) (ret cValue) {
ret.strval = str ret.strval = str
return return
} }

View File

@ -1,7 +1,7 @@
package envconf package envconf
type dataTypeInfo struct { type dataTypeInfo struct {
parser func(string, string, uint) cValue parser func(string, string, int) cValue
name string name string
} }