Documentation
¶
Overview ¶
Package protocol contains functions for zero-copy casting between typed slices and byte slices.
Index ¶
- Constants
- Variables
- func ByteSliceFromFloat32Slice(b []float32) []byte
- func ByteSliceFromFloat64Slice(b []float64) []byte
- func ByteSliceFromInt8Slice(b []int8) []byte
- func ByteSliceFromInt16Slice(b []int16) []byte
- func ByteSliceFromInt32Slice(b []int32) []byte
- func ByteSliceFromInt64Slice(b []int64) []byte
- func ByteSliceFromString(s string) []byte
- func ByteSliceFromUint8Slice(b []uint8) []byte
- func ByteSliceFromUint16Slice(b []uint16) []byte
- func ByteSliceFromUint32Slice(b []uint32) []byte
- func ByteSliceFromUint64Slice(b []uint64) []byte
- func Float32SliceFromByteSlice(b []byte) []float32
- func Float64SliceFromByteSlice(b []byte) []float64
- func Int8SliceFromByteSlice(b []byte) []int8
- func Int16SliceFromByteSlice(b []byte) []int16
- func Int32SliceFromByteSlice(b []byte) []int32
- func Int64SliceFromByteSlice(b []byte) []int64
- func StringFromByteSlice(b []byte) string
- func Uint8SliceFromByteSlice(b []byte) []uint8
- func Uint16SliceFromByteSlice(b []byte) []uint16
- func Uint32SliceFromByteSlice(b []byte) []uint32
- func Uint64SliceFromByteSlice(b []byte) []uint64
- type Buffer
- type ByteOrder
- type Reader
- type Writer
Constants ¶
const ( // BigEndianByte is the byte type of BigEndian. BigEndianByte byte = '0' // LittleEndianByte is the byte type of LittleEndian. LittleEndianByte byte = '1' )
const ( // NewLine is the byte format of \n. NewLine byte = '\n' // EmptySpace is the bytes format of space. EmptySpace byte = ' ' // StringSep is the bytes format of string sep. StringSep byte = 0 )
const ( TwoUint64Size = 16 Uint64Size = 8 Uint32Size = 4 Uint16Size = 2 Uint8Size = 1 )
Useful constants.
Variables ¶
var ( // BigEndian is the big-endian implementation of ByteOrder. BigEndian = &bigEndian{binary.BigEndian} // LittleEndian is the little-endian implementation of ByteOrder. LittleEndian = &littleEndian{binary.LittleEndian} )
var ( // APIBytes is the bytes format of API. APIBytes = []byte("API") // RespOK is the bytes format of OK. RespOK = []byte("OK") )
Functions ¶
func ByteSliceFromFloat32Slice ¶
ByteSliceFromFloat32Slice casts b to []byte.
func ByteSliceFromFloat64Slice ¶
ByteSliceFromFloat64Slice casts b to []byte.
func ByteSliceFromInt8Slice ¶
ByteSliceFromInt8Slice casts b to []byte.
func ByteSliceFromInt16Slice ¶
ByteSliceFromInt16Slice casts b to []byte.
func ByteSliceFromInt32Slice ¶
ByteSliceFromInt32Slice casts b to []byte.
func ByteSliceFromInt64Slice ¶
ByteSliceFromInt64Slice casts b to []byte.
func ByteSliceFromString ¶
ByteSliceFromString casts b to []byte.
func ByteSliceFromUint8Slice ¶
ByteSliceFromUint8Slice casts b to []byte.
func ByteSliceFromUint16Slice ¶
ByteSliceFromUint16Slice casts b to []byte.
func ByteSliceFromUint32Slice ¶
ByteSliceFromUint32Slice casts b to []byte.
func ByteSliceFromUint64Slice ¶
ByteSliceFromUint64Slice casts b to []byte.
func Float32SliceFromByteSlice ¶
Float32SliceFromByteSlice casts b to []byte.
func Float64SliceFromByteSlice ¶
Float64SliceFromByteSlice casts b to []byte.
func Int8SliceFromByteSlice ¶
Int8SliceFromByteSlice casts b to []int8.
func Int16SliceFromByteSlice ¶
Int16SliceFromByteSlice casts b to []int16.
func Int32SliceFromByteSlice ¶
Int32SliceFromByteSlice casts b to []int32.
func Int64SliceFromByteSlice ¶
Int64SliceFromByteSlice casts b to []int6.
func StringFromByteSlice ¶
StringFromByteSlice casts b to string.
func Uint8SliceFromByteSlice ¶
Uint8SliceFromByteSlice casts b to []uint8.
func Uint16SliceFromByteSlice ¶
Uint16SliceFromByteSlice casts b to []uint16.
func Uint32SliceFromByteSlice ¶
Uint32SliceFromByteSlice casts b to []uint32.
func Uint64SliceFromByteSlice ¶
Uint64SliceFromByteSlice casts b to []uint64.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer helps to read blobs efficiently.
type ByteOrder ¶
ByteOrder interface declares functions about how to handle data.
func GetByteOrder ¶
GetByteOrder returns the BigEndian or LittleEndian according to the b. '0' return BigEndian or '1' return LittleEndian.
type Reader ¶
type Reader interface {
// ReadCertainBytes reads exactly count bytes from reader.
// It returns the number of bytes copied and an error if fewer bytes were read.
// The error is EOF only if no bytes were read.
// If an EOF happens after reading some but not all the bytes,
ReadCertainBytes(count int) ([]byte, error)
// ReadByte reads and returns a single byte.
// If no byte is available, returns an error.
ReadByte() (byte, error)
// ReadBytes reads until the first occurrence of delim in the input,
// returning a slice containing the data up to and including the delimiter.
// If ReadBytes encounters an error before finding a delimiter,
// it returns the data read before the error and the error itself (often io.EOF).
// ReadBytes returns err != nil if and only if the returned data does not end in
// delim.
// For simple uses, a Scanner may be more convenient.
ReadBytes(delim byte) ([]byte, error)
// Read reads data into p.
// It returns the number of bytes read into p.
// The bytes are taken from at most one Read on the underlying Reader,
// hence n may be less than len(p).
// To read exactly len(p) bytes, use io.ReadFull(b, p).
// At EOF, the count will be zero and err will be io.EOF.
Read(buf []byte) (int, error)
}
Reader interface declares functions to read data from reader.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer declares functions to writer data into io.Writer.
func (*Writer) Write ¶
Write writes the contents of p into the buffer. It returns the number of bytes written. If nn < len(p), it also returns an error explaining why the write is short.
func (*Writer) WriteString ¶
WriteString writes a string. It returns the number of bytes written. If the count is less than len(s), it also returns an error explaining why the write is short.