micw/common/common.go

32 lines
624 B
Go

package common
import (
"encoding/base64"
"encoding/binary"
"errors"
)
const (
EncodingRawUrl = "encoring_row_url"
EncodingRawStd = "encoring_row_std"
)
func GetEncoding(encoding string) (*base64.Encoding, error) {
switch encoding {
case EncodingRawUrl:
return base64.RawURLEncoding, nil
case EncodingRawStd:
return base64.RawStdEncoding, nil
default:
return nil, errors.New("unsupported encoding")
}
}
// float64ToBytes converts float64 to []byte
// May be moved to nettools later
func float64ToBytes(f float64) []byte {
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, uint64(f))
return buf
}