gh-ost/vendor/github.com/go-mysql-org/go-mysql/mysql/parse_binary.go

54 lines
1.2 KiB
Go
Raw Normal View History

2016-06-16 09:15:56 +00:00
package mysql
import (
"encoding/binary"
"math"
)
func ParseBinaryInt8(data []byte) int8 {
return int8(data[0])
}
func ParseBinaryUint8(data []byte) uint8 {
return data[0]
}
func ParseBinaryInt16(data []byte) int16 {
return int16(binary.LittleEndian.Uint16(data))
}
func ParseBinaryUint16(data []byte) uint16 {
return binary.LittleEndian.Uint16(data)
}
func ParseBinaryInt24(data []byte) int32 {
u32 := ParseBinaryUint24(data)
2016-06-16 09:15:56 +00:00
if u32&0x00800000 != 0 {
u32 |= 0xFF000000
}
return int32(u32)
}
func ParseBinaryUint24(data []byte) uint32 {
return uint32(data[0]) | uint32(data[1])<<8 | uint32(data[2])<<16
}
func ParseBinaryInt32(data []byte) int32 {
return int32(binary.LittleEndian.Uint32(data))
}
func ParseBinaryUint32(data []byte) uint32 {
return binary.LittleEndian.Uint32(data)
}
func ParseBinaryInt64(data []byte) int64 {
return int64(binary.LittleEndian.Uint64(data))
}
func ParseBinaryUint64(data []byte) uint64 {
return binary.LittleEndian.Uint64(data)
}
func ParseBinaryFloat32(data []byte) float32 {
return math.Float32frombits(binary.LittleEndian.Uint32(data))
}
func ParseBinaryFloat64(data []byte) float64 {
return math.Float64frombits(binary.LittleEndian.Uint64(data))
}