micw/common/common.go
2024-11-24 15:04:52 +01:00

32 lines
709 B
Go

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