Documentation
¶
Index ¶
- type Decoder
- type DecoderCommon
- func (cd *DecoderCommon) ReadSize1(index int, d *[]byte) (byte, int)
- func (cd *DecoderCommon) ReadSize2(index int, d *[]byte) ([]byte, int)
- func (cd *DecoderCommon) ReadSize4(index int, d *[]byte) ([]byte, int)
- func (cd *DecoderCommon) ReadSize8(index int, d *[]byte) ([]byte, int)
- func (cd *DecoderCommon) ReadSizeN(index, n int, d *[]byte) ([]byte, int)
- type Encoder
- type EncoderCommon
- func (c *EncoderCommon) SetByte1Int(code, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte1Int64(value int64, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte1Uint64(value uint64, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte2Int(value int, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte2Int64(value int64, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte2Uint64(value uint64, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte4Int(value int, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte4Int64(value int64, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte4Uint32(value uint32, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte4Uint64(value uint64, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte8Int64(value int64, offset int, d *[]byte) int
- func (c *EncoderCommon) SetByte8Uint64(value uint64, offset int, d *[]byte) int
- func (c *EncoderCommon) SetBytes(bs []byte, offset int, d *[]byte) int
- type StreamDecoder
- type StreamEncoder
- type StreamWriter
- func (w *StreamWriter) WriteByte1Int(value int) error
- func (w *StreamWriter) WriteByte1Int64(value int64) error
- func (w *StreamWriter) WriteByte1Uint64(value uint64) error
- func (w *StreamWriter) WriteByte2Int(value int) error
- func (w *StreamWriter) WriteByte2Int64(value int64) error
- func (w *StreamWriter) WriteByte2Uint64(value uint64) error
- func (w *StreamWriter) WriteByte4Int(value int) error
- func (w *StreamWriter) WriteByte4Int64(value int64) error
- func (w *StreamWriter) WriteByte4Uint32(value uint32) error
- func (w *StreamWriter) WriteByte4Uint64(value uint64) error
- func (w *StreamWriter) WriteByte8Int64(value int64) error
- func (w *StreamWriter) WriteByte8Uint64(value uint64) error
- func (w *StreamWriter) WriteBytes(bs []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder interface {
// Code returns the unique code representing the decoder type.
Code() int8
// IsType checks if the data at the given offset matches the expected type.
// Returns true if the type matches, false otherwise.
IsType(offset int, d *[]byte) bool
// AsValue decodes the data at the given offset into a Go value of the specified kind.
// Returns the decoded value, the new offset, and an error if decoding fails.
AsValue(offset int, k reflect.Kind, d *[]byte) (interface{}, int, error)
}
Decoder defines an interface for decoding values from bytes. It provides methods to get the decoder type, check if the data matches the type, and convert the data into a Go value.
type DecoderCommon ¶
type DecoderCommon struct {
}
DecoderCommon provides common utility methods for decoding data from bytes.
func (*DecoderCommon) ReadSize1 ¶
func (cd *DecoderCommon) ReadSize1(index int, d *[]byte) (byte, int)
ReadSize1 reads a single byte from the given index in the byte slice. Returns the byte and the new index after reading.
func (*DecoderCommon) ReadSize2 ¶
func (cd *DecoderCommon) ReadSize2(index int, d *[]byte) ([]byte, int)
ReadSize2 reads two bytes from the given index in the byte slice. Returns the bytes as a slice and the new index after reading.
func (*DecoderCommon) ReadSize4 ¶
func (cd *DecoderCommon) ReadSize4(index int, d *[]byte) ([]byte, int)
ReadSize4 reads four bytes from the given index in the byte slice. Returns the bytes as a slice and the new index after reading.
type Encoder ¶
type Encoder interface {
// Code returns the unique code representing the encoder type.
Code() int8
// Type returns the reflect.Type of the value that the encoder handles.
Type() reflect.Type
// CalcByteSize calculates the number of bytes required to encode the given value.
// Returns the size and an error if the calculation fails.
CalcByteSize(value reflect.Value) (int, error)
// WriteToBytes encodes the given value into a byte slice starting at the specified offset.
// Returns the new offset after writing the bytes.
WriteToBytes(value reflect.Value, offset int, bytes *[]byte) int
}
Encoder defines an interface for encoding values into bytes. It provides methods to get the encoding type, calculate the byte size of a value, and write the encoded value into a byte slice.
type EncoderCommon ¶
type EncoderCommon struct {
}
EncoderCommon provides utility methods for encoding various types of values into bytes. It includes methods to encode integers and unsigned integers of different sizes, as well as methods to write raw byte slices into a target byte slice.
func (*EncoderCommon) SetByte1Int ¶
func (c *EncoderCommon) SetByte1Int(code, offset int, d *[]byte) int
SetByte1Int encodes a single byte from the given int value into the byte slice at the specified offset. Returns the new offset after writing the byte.
func (*EncoderCommon) SetByte1Int64 ¶
func (c *EncoderCommon) SetByte1Int64(value int64, offset int, d *[]byte) int
SetByte1Int64 encodes a single byte from the given int64 value into the byte slice at the specified offset. Returns the new offset after writing the byte.
func (*EncoderCommon) SetByte1Uint64 ¶
func (c *EncoderCommon) SetByte1Uint64(value uint64, offset int, d *[]byte) int
SetByte1Uint64 encodes a single byte from the given uint64 value into the byte slice at the specified offset. Returns the new offset after writing the byte.
func (*EncoderCommon) SetByte2Int ¶
func (c *EncoderCommon) SetByte2Int(value int, offset int, d *[]byte) int
SetByte2Int encodes the lower two bytes of the given int value into the byte slice at the specified offset. Returns the new offset after writing the bytes.
func (*EncoderCommon) SetByte2Int64 ¶
func (c *EncoderCommon) SetByte2Int64(value int64, offset int, d *[]byte) int
SetByte2Int64 encodes the lower two bytes of the given int64 value into the byte slice at the specified offset. Returns the new offset after writing the bytes.
func (*EncoderCommon) SetByte2Uint64 ¶
func (c *EncoderCommon) SetByte2Uint64(value uint64, offset int, d *[]byte) int
SetByte2Uint64 encodes the lower two bytes of the given uint64 value into the byte slice at the specified offset. Returns the new offset after writing the bytes.
func (*EncoderCommon) SetByte4Int ¶
func (c *EncoderCommon) SetByte4Int(value int, offset int, d *[]byte) int
SetByte4Int encodes the lower four bytes of the given int value into the byte slice at the specified offset. Returns the new offset after writing the bytes.
func (*EncoderCommon) SetByte4Int64 ¶
func (c *EncoderCommon) SetByte4Int64(value int64, offset int, d *[]byte) int
SetByte4Int64 encodes the lower four bytes of the given int64 value into the byte slice at the specified offset. Returns the new offset after writing the bytes.
func (*EncoderCommon) SetByte4Uint32 ¶
func (c *EncoderCommon) SetByte4Uint32(value uint32, offset int, d *[]byte) int
SetByte4Uint32 encodes the lower four bytes of the given uint32 value into the byte slice at the specified offset. Returns the new offset after writing the bytes.
func (*EncoderCommon) SetByte4Uint64 ¶
func (c *EncoderCommon) SetByte4Uint64(value uint64, offset int, d *[]byte) int
SetByte4Uint64 encodes the lower four bytes of the given uint64 value into the byte slice at the specified offset. Returns the new offset after writing the bytes.
func (*EncoderCommon) SetByte8Int64 ¶
func (c *EncoderCommon) SetByte8Int64(value int64, offset int, d *[]byte) int
SetByte8Int64 encodes all eight bytes of the given int64 value into the byte slice at the specified offset. Returns the new offset after writing the bytes.
func (*EncoderCommon) SetByte8Uint64 ¶
func (c *EncoderCommon) SetByte8Uint64(value uint64, offset int, d *[]byte) int
SetByte8Uint64 encodes all eight bytes of the given uint64 value into the byte slice at the specified offset. Returns the new offset after writing the bytes.
type StreamDecoder ¶ added in v2.2.0
type StreamDecoder interface {
// Code returns the unique identifier for the decoder.
Code() int8
// IsType checks if the provided code, inner type, and data length match the expected type.
// Returns true if the type matches, otherwise false.
IsType(code byte, innerType int8, dataLength int) bool
// ToValue converts the raw data into a Go value of the specified kind.
// Takes the code, raw data, and the target kind as input.
// Returns the decoded value or an error if the conversion fails.
ToValue(code byte, data []byte, k reflect.Kind) (any, error)
}
StreamDecoder defines an interface for decoding streams of data. It provides methods to retrieve the decoder's code, check type compatibility, and convert raw data into a Go value of a specified kind.
type StreamEncoder ¶ added in v2.2.0
type StreamEncoder interface {
// Code returns the unique code for the encoder.
Code() int8
// Type returns the reflect.Type of the value being encoded.
Type() reflect.Type
// Write encodes the given value and writes it to the provided StreamWriter.
Write(w StreamWriter, value reflect.Value) error
}
StreamEncoder is an interface that extended encoders should implement. It defines methods for encoding data into a stream.
type StreamWriter ¶ added in v2.2.2
type StreamWriter struct {
// contains filtered or unexported fields
}
StreamWriter provides methods for writing data in extended formats. It wraps an io.Writer and a buffer for efficient writing.
func CreateStreamWriter ¶ added in v2.2.2
func CreateStreamWriter(w io.Writer, buf *common.Buffer) StreamWriter
CreateStreamWriter creates and returns a new StreamWriter instance.
func (*StreamWriter) WriteByte1Int ¶ added in v2.2.2
func (w *StreamWriter) WriteByte1Int(value int) error
WriteByte1Int writes a single byte representation of an int value.
func (*StreamWriter) WriteByte1Int64 ¶ added in v2.2.2
func (w *StreamWriter) WriteByte1Int64(value int64) error
WriteByte1Int64 writes a single byte representation of an int64 value.
func (*StreamWriter) WriteByte1Uint64 ¶ added in v2.2.2
func (w *StreamWriter) WriteByte1Uint64(value uint64) error
WriteByte1Uint64 writes a single byte representation of a uint64 value.
func (*StreamWriter) WriteByte2Int ¶ added in v2.2.2
func (w *StreamWriter) WriteByte2Int(value int) error
WriteByte2Int writes a two-byte representation of an int value.
func (*StreamWriter) WriteByte2Int64 ¶ added in v2.2.2
func (w *StreamWriter) WriteByte2Int64(value int64) error
WriteByte2Int64 writes a two-byte representation of an int64 value.
func (*StreamWriter) WriteByte2Uint64 ¶ added in v2.2.2
func (w *StreamWriter) WriteByte2Uint64(value uint64) error
WriteByte2Uint64 writes a two-byte representation of a uint64 value.
func (*StreamWriter) WriteByte4Int ¶ added in v2.2.2
func (w *StreamWriter) WriteByte4Int(value int) error
WriteByte4Int writes a four-byte representation of an int value.
func (*StreamWriter) WriteByte4Int64 ¶ added in v2.2.2
func (w *StreamWriter) WriteByte4Int64(value int64) error
WriteByte4Int64 writes a four-byte representation of an int64 value.
func (*StreamWriter) WriteByte4Uint32 ¶ added in v2.2.2
func (w *StreamWriter) WriteByte4Uint32(value uint32) error
WriteByte4Uint32 writes a four-byte representation of a uint32 value.
func (*StreamWriter) WriteByte4Uint64 ¶ added in v2.2.2
func (w *StreamWriter) WriteByte4Uint64(value uint64) error
WriteByte4Uint64 writes a four-byte representation of a uint64 value.
func (*StreamWriter) WriteByte8Int64 ¶ added in v2.2.2
func (w *StreamWriter) WriteByte8Int64(value int64) error
WriteByte8Int64 writes an eight-byte representation of an int64 value.
func (*StreamWriter) WriteByte8Uint64 ¶ added in v2.2.2
func (w *StreamWriter) WriteByte8Uint64(value uint64) error
WriteByte8Uint64 writes an eight-byte representation of a uint64 value.
func (*StreamWriter) WriteBytes ¶ added in v2.2.2
func (w *StreamWriter) WriteBytes(bs []byte) error
WriteBytes writes a slice of bytes to the underlying writer.