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"
)
type DataType uint
type DataType uint32
const (
TypeNone DataType = iota
TypeInt DataType = iota
TypeMetric DataType = iota
TypeDuration DataType = iota
TypeString DataType = iota
TypeDirectory DataType = iota
TypeBool DataType = iota
TypeHex DataType = iota
sizeBitmask DataType = 0xffff
typeBitmask DataType = sizeBitmask << 16
)
func FixedHex(size uint) DataType {
return (DataType)(size<<16) | TypeHex
const (
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 {
return dtype & 0xffff
return dtype & typeBitmask
}
func (dtype DataType) typeAndSize() (DataType, uint) {
return (dtype & 0xffff), uint(dtype >> 16)
func (dtype DataType) typeAndSize() (DataType, int) {
return (dtype & typeBitmask), int(dtype & sizeBitmask)
}
type cValue struct {

View File

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

View File

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