micw/common/common.go

32 lines
709 B
Go
Raw Normal View History

2024-11-17 21:24:19 +00:00
package common
import (
"encoding/base64"
"encoding/binary"
2024-11-24 14:04:52 +00:00
"github.com/matchsystems/werr"
2024-11-17 21:24:19 +00:00
)
const (
EncodingRawUrl = "encoring_row_url"
EncodingRawStd = "encoring_row_std"
)
2024-11-24 14:04:52 +00:00
// GetEncoding Returns base64 encoding based on the provided string
2024-11-17 21:24:19 +00:00
func GetEncoding(encoding string) (*base64.Encoding, error) {
switch encoding {
case EncodingRawUrl:
return base64.RawURLEncoding, nil
case EncodingRawStd:
return base64.RawStdEncoding, nil
default:
2024-11-24 14:04:52 +00:00
return nil, werr.Wrapf(ErrInvalidArgument, "unknown encoding %s", encoding)
2024-11-17 21:24:19 +00:00
}
}
// float64ToBytes converts float64 to []byte
func float64ToBytes(f float64) []byte {
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, uint64(f))
return buf
}