2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2017-12-29 16:03:30 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2017-12-29 16:03:30 +08:00
|
|
|
|
2019-01-15 23:27:47 +08:00
|
|
|
// Package gbinary provides useful API for handling binary/bytes data.
|
2019-04-29 23:54:47 +08:00
|
|
|
//
|
2020-02-08 23:46:10 +08:00
|
|
|
// Note that package gbinary encodes the data using LittleEndian in default.
|
2017-11-23 10:21:28 +08:00
|
|
|
package gbinary
|
|
|
|
|
2019-07-11 18:58:31 +08:00
|
|
|
func Encode(values ...interface{}) []byte {
|
|
|
|
return LeEncode(values...)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 18:58:31 +08:00
|
|
|
func EncodeByLength(length int, values ...interface{}) []byte {
|
|
|
|
return LeEncodeByLength(length, values...)
|
2018-07-04 19:32:51 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 18:58:31 +08:00
|
|
|
func Decode(b []byte, values ...interface{}) error {
|
|
|
|
return LeDecode(b, values...)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeString(s string) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeString(s)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToString(b []byte) string {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToString(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
2018-01-18 12:02:56 +08:00
|
|
|
func EncodeBool(b bool) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeBool(b)
|
2018-01-18 12:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeInt(i int) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeInt(i)
|
2018-01-18 12:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeUint(i uint) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeUint(i)
|
2018-01-18 12:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-11-23 10:21:28 +08:00
|
|
|
func EncodeInt8(i int8) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeInt8(i)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeUint8(i uint8) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeUint8(i)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeInt16(i int16) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeInt16(i)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeUint16(i uint16) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeUint16(i)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeInt32(i int32) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeInt32(i)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeUint32(i uint32) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeUint32(i)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeInt64(i int64) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeInt64(i)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeUint64(i uint64) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeUint64(i)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeFloat32(f float32) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeFloat32(f)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func EncodeFloat64(f float64) []byte {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeEncodeFloat64(f)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
2018-01-18 12:02:56 +08:00
|
|
|
func DecodeToInt(b []byte) int {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToInt(b)
|
2018-01-18 12:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToUint(b []byte) uint {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToUint(b)
|
2018-01-18 12:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToBool(b []byte) bool {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToBool(b)
|
2018-01-18 12:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-11-23 10:21:28 +08:00
|
|
|
func DecodeToInt8(b []byte) int8 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToInt8(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToUint8(b []byte) uint8 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToUint8(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToInt16(b []byte) int16 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToInt16(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToUint16(b []byte) uint16 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToUint16(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToInt32(b []byte) int32 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToInt32(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToUint32(b []byte) uint32 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToUint32(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToInt64(b []byte) int64 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToInt64(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToUint64(b []byte) uint64 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToUint64(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToFloat32(b []byte) float32 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToFloat32(b)
|
2017-11-23 10:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeToFloat64(b []byte) float64 {
|
2019-07-11 18:58:31 +08:00
|
|
|
return LeDecodeToFloat64(b)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|