protocol

package
v1.30.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2023 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package protocol contains functions for zero-copy casting between typed slices and byte slices.

Index

Constants

View Source
const (
	// BigEndianByte is the byte type of BigEndian.
	BigEndianByte byte = '0'
	// LittleEndianByte is the byte type of LittleEndian.
	LittleEndianByte byte = '1'
)
View Source
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
)
View Source
const (
	TwoUint64Size = 16
	Uint64Size    = 8
	Uint32Size    = 4
	Uint16Size    = 2
	Uint8Size     = 1
)

Useful constants.

Variables

View Source
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}
)
View Source
var (
	// APIBytes is the bytes format of API.
	APIBytes = []byte("API")
	// RespOK is the bytes format of OK.
	RespOK = []byte("OK")
)

Functions

func ByteSliceFromFloat32Slice

func ByteSliceFromFloat32Slice(b []float32) []byte

ByteSliceFromFloat32Slice casts b to []byte.

func ByteSliceFromFloat64Slice

func ByteSliceFromFloat64Slice(b []float64) []byte

ByteSliceFromFloat64Slice casts b to []byte.

func ByteSliceFromInt8Slice

func ByteSliceFromInt8Slice(b []int8) []byte

ByteSliceFromInt8Slice casts b to []byte.

func ByteSliceFromInt16Slice

func ByteSliceFromInt16Slice(b []int16) []byte

ByteSliceFromInt16Slice casts b to []byte.

func ByteSliceFromInt32Slice

func ByteSliceFromInt32Slice(b []int32) []byte

ByteSliceFromInt32Slice casts b to []byte.

func ByteSliceFromInt64Slice

func ByteSliceFromInt64Slice(b []int64) []byte

ByteSliceFromInt64Slice casts b to []byte.

func ByteSliceFromString

func ByteSliceFromString(s string) []byte

ByteSliceFromString casts b to []byte.

func ByteSliceFromUint8Slice

func ByteSliceFromUint8Slice(b []uint8) []byte

ByteSliceFromUint8Slice casts b to []byte.

func ByteSliceFromUint16Slice

func ByteSliceFromUint16Slice(b []uint16) []byte

ByteSliceFromUint16Slice casts b to []byte.

func ByteSliceFromUint32Slice

func ByteSliceFromUint32Slice(b []uint32) []byte

ByteSliceFromUint32Slice casts b to []byte.

func ByteSliceFromUint64Slice

func ByteSliceFromUint64Slice(b []uint64) []byte

ByteSliceFromUint64Slice casts b to []byte.

func Float32SliceFromByteSlice

func Float32SliceFromByteSlice(b []byte) []float32

Float32SliceFromByteSlice casts b to []byte.

func Float64SliceFromByteSlice

func Float64SliceFromByteSlice(b []byte) []float64

Float64SliceFromByteSlice casts b to []byte.

func Int8SliceFromByteSlice

func Int8SliceFromByteSlice(b []byte) []int8

Int8SliceFromByteSlice casts b to []int8.

func Int16SliceFromByteSlice

func Int16SliceFromByteSlice(b []byte) []int16

Int16SliceFromByteSlice casts b to []int16.

func Int32SliceFromByteSlice

func Int32SliceFromByteSlice(b []byte) []int32

Int32SliceFromByteSlice casts b to []int32.

func Int64SliceFromByteSlice

func Int64SliceFromByteSlice(b []byte) []int64

Int64SliceFromByteSlice casts b to []int6.

func StringFromByteSlice

func StringFromByteSlice(b []byte) string

StringFromByteSlice casts b to string.

func Uint8SliceFromByteSlice

func Uint8SliceFromByteSlice(b []byte) []uint8

Uint8SliceFromByteSlice casts b to []uint8.

func Uint16SliceFromByteSlice

func Uint16SliceFromByteSlice(b []byte) []uint16

Uint16SliceFromByteSlice casts b to []uint16.

func Uint32SliceFromByteSlice

func Uint32SliceFromByteSlice(b []byte) []uint32

Uint32SliceFromByteSlice casts b to []uint32.

func Uint64SliceFromByteSlice

func Uint64SliceFromByteSlice(b []byte) []uint64

Uint64SliceFromByteSlice casts b to []uint64.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer helps to read blobs efficiently.

func NewBuffer

func NewBuffer(count int, r Reader) *Buffer

NewBuffer inits a Buffer object.

func (*Buffer) ReadBlobs

func (b *Buffer) ReadBlobs(bo ByteOrder) ([][]byte, error)

ReadBlobs helps to read blobs.

type ByteOrder

type ByteOrder interface {
	binary.ByteOrder
}

ByteOrder interface declares functions about how to handle data.

func GetByteOrder

func GetByteOrder(b byte) ByteOrder

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.

func NewReader

func NewReader(rd io.Reader) Reader

NewReader returns a reader instance which implement the Reader.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer declares functions to writer data into io.Writer.

func NewWriter

func NewWriter(wr io.Writer) *Writer

NewWriter inits a writer with io.Writer.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes any buffered data to the underlying io.Writer.

func (*Writer) Write

func (w *Writer) Write(d []byte) error

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) WriteByte

func (w *Writer) WriteByte(d byte) error

WriteByte writes a single byte.

func (*Writer) WriteString

func (w *Writer) WriteString(d string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL