Documentation ¶
Index ¶
- Constants
- Variables
- type Benc
- func (benc *Benc) Decode(b []byte, msg Msg) error
- func (benc *Benc) DecodeBool(n int, id byte, b []byte, r []byte, i []byte) (int, bool)
- func (benc *Benc) DecodeFloat32(n int, id byte, b []byte, r []byte, i []byte) (int, float32)
- func (benc *Benc) DecodeFloat64(n int, id byte, b []byte, r []byte, i []byte) (int, float64)
- func (benc *Benc) DecodeInt(n int, id byte, b []byte, r []byte, i []byte) (int, int)
- func (benc *Benc) DecodeInt16(n int, id byte, b []byte, r []byte, i []byte) (int, int16)
- func (benc *Benc) DecodeInt32(n int, id byte, b []byte, r []byte, i []byte) (int, int32)
- func (benc *Benc) DecodeInt64(n int, id byte, b []byte, r []byte, i []byte) (int, int64)
- func (benc *Benc) DecodeInt8(n int, id byte, b []byte, r []byte, i []byte) (int, int8)
- func (benc *Benc) DecodeMsg(n int, b []byte, id byte, r []byte, ids []byte) (int, []byte, error)
- func (benc *Benc) DecodeSafeString(n int, id byte, b []byte, r []byte, i []byte) (int, string)
- func (benc *Benc) DecodeUint(n int, id byte, b []byte, r []byte, i []byte) (int, uint)
- func (benc *Benc) DecodeUint16(n int, id byte, b []byte, r []byte, i []byte) (int, uint16)
- func (benc *Benc) DecodeUint32(n int, id byte, b []byte, r []byte, i []byte) (int, uint32)
- func (benc *Benc) DecodeUint64(n int, id byte, b []byte, r []byte, i []byte) (int, uint64)
- func (benc *Benc) DecodeUint8(n int, id byte, b []byte, r []byte, i []byte) (int, uint8)
- func (benc *Benc) Encode(msg Msg) ([]byte, error)
- func (benc *Benc) EncodeBool(n int, b []byte, v bool, id byte) int
- func (benc *Benc) EncodeFloat32(n int, b []byte, v float32, id byte) int
- func (benc *Benc) EncodeFloat64(n int, b []byte, v float64, id byte) int
- func (benc *Benc) EncodeInt(n int, b []byte, v int, id byte) int
- func (benc *Benc) EncodeInt16(n int, b []byte, v int16, id byte) int
- func (benc *Benc) EncodeInt32(n int, b []byte, v int32, id byte) int
- func (benc *Benc) EncodeInt64(n int, b []byte, v int64, id byte) int
- func (benc *Benc) EncodeInt8(n int, b []byte, v int8, id byte) int
- func (benc *Benc) EncodeMsg(n int, s int, id byte, b []byte, r []byte, enc func(n int) (int, error)) (int, error)
- func (benc *Benc) EncodeSafeString(n int, b []byte, v string, id byte) int
- func (benc *Benc) EncodeString(n int, b []byte, v string, id byte) int
- func (benc *Benc) EncodeUint(n int, b []byte, v uint, id byte) int
- func (benc *Benc) EncodeUint16(n int, b []byte, v uint16, id byte) int
- func (benc *Benc) EncodeUint32(n int, b []byte, v uint32, id byte) int
- func (benc *Benc) EncodeUint64(n int, b []byte, v uint64, id byte) int
- func (benc *Benc) EncodeUint8(n int, b []byte, v uint8, id byte) int
- func (benc *Benc) GetResizedBuffer(s int) ([]byte, error)
- func (benc *Benc) HandleCompatibilityField(n int, id byte, b []byte, r []byte, ids []byte) (int, bool)
- func (benc *Benc) SizeBool() int
- func (benc *Benc) SizeFloat32() int
- func (benc *Benc) SizeFloat64() int
- func (benc *Benc) SizeInt(v int) int
- func (benc *Benc) SizeInt16() int
- func (benc *Benc) SizeInt32() int
- func (benc *Benc) SizeInt64() int
- func (benc *Benc) SizeInt8() int
- func (benc *Benc) SizeMsg(s int, r []byte) int
- func (benc *Benc) SizeString(v string) int
- func (benc *Benc) SizeUint(v uint) int
- func (benc *Benc) SizeUint16() int
- func (benc *Benc) SizeUint32() int
- func (benc *Benc) SizeUint64() int
- func (benc *Benc) SizeUint8() int
- func (benc *Benc) SkipBool(n int) int
- func (benc *Benc) SkipEncodedValueByType(n int, t byte, b []byte) int
- func (benc *Benc) SkipFloat32(n int) int
- func (benc *Benc) SkipFloat64(n int) int
- func (benc *Benc) SkipInt(n int, b []byte) int
- func (benc *Benc) SkipInt16(n int) int
- func (benc *Benc) SkipInt32(n int) int
- func (benc *Benc) SkipInt64(n int) int
- func (benc *Benc) SkipInt8(n int) int
- func (benc *Benc) SkipMsg(n int, b []byte) int
- func (benc *Benc) SkipString(n int, b []byte) int
- func (benc *Benc) SkipUint(n int, b []byte) int
- func (benc *Benc) SkipUint16(n int) int
- func (benc *Benc) SkipUint32(n int) int
- func (benc *Benc) SkipUint64(n int) int
- func (benc *Benc) SkipUint8(n int) int
- type Msg
- type Nfbc
- func (nfbc *Nfbc) DecodeInt(n int, b []byte) (int, int, error)
- func (nfbc *Nfbc) DecodeUint(n int, b []byte) (int, uint, error)
- func (nfbc *Nfbc) DecodeUint8(n int, b []byte) (int, uint8)
- func (nfbc *Nfbc) EncodeInt(n int, b []byte, v int) int
- func (nfbc *Nfbc) EncodeUint(n int, b []byte, v uint) int
- func (nfbc *Nfbc) EncodeUint8(n int, b []byte, v uint8) int
- func (nfbc *Nfbc) SizeInt(v int) int
- func (nfbc *Nfbc) SizeInt8() int
- func (nfbc *Nfbc) SizeUint(v uint) int
- func (nfbc *Nfbc) SkipInt(n int, b []byte) int
- func (nfbc *Nfbc) SkipUint(n int, b []byte) int
- func (nfbc *Nfbc) SkipUint8(n int) int
Constants ¶
const ( // MSG represents a message type. MSG byte = iota // Int represents an integer type. Int // Int8 represents an 8-bit integer type. Int8 // Int16 represents a 16-bit integer type. Int16 // Int32 represents a 32-bit integer type. Int32 // Int64 represents a 64-bit integer type. Int64 // Uint represents an unsigned integer type. Uint // Uint8 represents an 8-bit unsigned integer type. Uint8 // Uint16 represents a 16-bit unsigned integer type. Uint16 // Uint32 represents a 32-bit unsigned integer type. Uint32 // Uint64 represents a 64-bit unsigned integer type. Uint64 // Float32 represents a 32-bit floating-point type. Float32 // Float64 represents a 64-bit floating-point type. Float64 // Bool represents a boolean type. Bool // String represents a string type. String )
Variables ¶
var ErrBufTooSmall = errors.New("buffer too small")
ErrBufTooSmall indicates that the buffer is too small to be reused at the specified size.
var ErrBytesTooSmall = errors.New("bytes too small")
ErrBytesTooSmall indicates that the buffer given is too small to decode data.
var ErrIdIsZero = errors.New("specified id cannot be 0")
ErrIdIsZero indicates that the ID has to be over 0 and <= 255.
var ErrInvalidIntFormat = errors.New("invalid int format")
ErrInvalidIntFormat indicates that the buffer given is invalid to decode an int.
var ErrInvalidType = errors.New("invalid type")
ErrInvalidType indicates that the decoded type is invalid.
var ErrInvalidUintFormat = errors.New("invalid uint format")
ErrInvalidUintFormat indicates that the buffer given is invalid to decode a uint.
var ErrReservedExceedsLimit = errors.New("the reserved ids, specified with r, exceeds the limit of 255")
ErrReservedExceedsLimit indicates that `r` has a length over 255.
Functions ¶
This section is empty.
Types ¶
type Benc ¶
type Benc struct {
// contains filtered or unexported fields
}
Benc represents an encoder/decoder with a buffer for encoding and decoding data.
func NewEncoder ¶
NewEncoder: ¶
Creates a new encoder instance for encoding and decoding operations.
If a buffer size is provided, it allocates a buffer of the specified size. Otherwise, it allocates a buffer with a default size of 4096 bytes.
Example:
benc := bencv2.NewEncoder(1024)
func (*Benc) Decode ¶
Decode: ¶
Decodes the provided byte slice into the provided message (Msg object).
Returns an error if decoding fails due to invalid data or buffer size limitations.
func (*Benc) DecodeBool ¶
DecodeBool: ¶
Decodes a encoded bool at the given offset, returns the decoded bool and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Bool: ¶
id type bool // byte byte->Bool byte->1 | byte->0
func (*Benc) DecodeFloat32 ¶
DecodeFloat32: ¶
Decodes a encoded 32-bit float at the given offset, returns the decoded 32-bit float and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Float32: ¶
id type float32 // byte byte->Float32 4 bytes
func (*Benc) DecodeFloat64 ¶
DecodeFloat64: ¶
Decodes a encoded 64-bit float at the given offset, returns the decoded 64-bit float and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Float64: ¶
id type float64 // byte byte->Float64 8 bytes
func (*Benc) DecodeInt ¶
DecodeInt: ¶
Decodes a encoded integer at the given offset, returns the decoded integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int: ¶
id type binary size integer // byte byte->Int byte []byte
func (*Benc) DecodeInt16 ¶
DecodeInt16: ¶
Decodes a encoded 16-bit integer at the given offset, returns the decoded 16-bit integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int16: ¶
id type int16 // byte byte->Int16 2 bytes
func (*Benc) DecodeInt32 ¶
DecodeInt32: ¶
Decodes a encoded 32-bit integer at the given offset, returns the decoded 32-bit integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int32: ¶
id type int32 // byte byte->Int32 4 bytes
func (*Benc) DecodeInt64 ¶
DecodeInt64: ¶
Decodes a encoded 64-bit integer at the given offset, returns the decoded 64-bit integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int64: ¶
id type int64 // byte byte->Int64 8 bytes
func (*Benc) DecodeInt8 ¶
DecodeInt8: ¶
Decodes a encoded 8-bit integer at the given offset, returns the decoded 8-bit integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int8: ¶
id type int8 // byte byte->Int8 byte
func (*Benc) DecodeMsg ¶
DecodeMsg: ¶
Decodes a message in the Benc format.
Parameters: ¶
- n: The current offset in the byte slice.
- b: The byte slice containing the encoded message.
- id: The ID of the message.
- r: A slice of reserved IDs.
- ids: A slice of existing IDs.
Returns: ¶
- The new offset after decoding the message.
- A byte slice containing the reserved IDs for the decoded message.
- An error if decoding fails.
Msg: ¶
A Msg is a container for handling backward and forward compatibility for fields.
Msg Structure, in the Benc format:
id type reservedIds size of content content // byte | byte->0 byte->MSG []byte | byte->0 int []byte
func (*Benc) DecodeSafeString ¶
DecodeSafeString: ¶
Decodes a encoded string at the given offset, returns the decoded string and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
String: ¶
id type string size string // byte byte->String int []byte
func (*Benc) DecodeUint ¶
DecodeUint: ¶
Decodes a encoded unsigned integer at the given offset, returns the decoded unsigned integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint: ¶
id type binary size unsigned integer // byte byte->Uint byte []byte
func (*Benc) DecodeUint16 ¶
DecodeUint16: ¶
Decodes a encoded 16-bit unsigned integer at the given offset, returns the decoded 16-bit unsigned integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint16: ¶
id type uint16 // byte byte->Uint16 2 bytes
func (*Benc) DecodeUint32 ¶
DecodeUint32: ¶
Decodes a encoded 32-bit unsigned integer at the given offset, returns the decoded 32-bit unsigned integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint32: ¶
id type uint32 // byte byte->Uint32 4 bytes
func (*Benc) DecodeUint64 ¶
DecodeUint64: ¶
Decodes a encoded 64-bit unsigned integer at the given offset, returns the decoded 64-bit unsigned integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint64: ¶
id type uint64 // byte byte->Uint64 4 bytes
func (*Benc) DecodeUint8 ¶
DecodeUint8: ¶
Decodes a encoded 8-bit unsigned integer at the given offset, returns the decoded 8-bit unsigned integer and the new offset.
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint8: ¶
id type uint8 // byte byte->Uint8 byte
func (*Benc) Encode ¶
Encode: ¶
Encodes the provided message (Msg object) into a byte slice.
Returns the byte slice containing the encoded message.
Returns an error if encoding fails due to invalid data or buffer size limitations.
func (*Benc) EncodeBool ¶
EncodeBool: ¶
Encodes the given bool at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Bool: ¶
id type bool // byte byte->Bool byte->1 | byte->0
func (*Benc) EncodeFloat32 ¶
EncodeFloat32: ¶
Encodes the given 32-bit float at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Float32: ¶
id type float32 // byte byte->Float32 4 bytes
func (*Benc) EncodeFloat64 ¶
EncodeFloat64: ¶
Encodes the given 64-bit float at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Float64: ¶
id type float64 // byte byte->Float64 8 bytes
func (*Benc) EncodeInt ¶
EncodeInt: ¶
Encodes the given integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int: ¶
id type binary size integer // byte byte->Int byte []byte
func (*Benc) EncodeInt16 ¶
EncodeInt16: ¶
Encodes the given 16-bit integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int16: ¶
id type int16 // byte byte->Int16 2 bytes
func (*Benc) EncodeInt32 ¶
EncodeInt32: ¶
Encodes the given 32-bit integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int32: ¶
id type int32 // byte byte->Int32 4 bytes
func (*Benc) EncodeInt64 ¶
EncodeInt64: ¶
Encodes the given 64-bit integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int64: ¶
id type int64 // byte byte->Int64 8 bytes
func (*Benc) EncodeInt8 ¶
EncodeInt8: ¶
Encodes the given 8-bit integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Int8: ¶
id type int8 // byte byte->Int8 byte
func (*Benc) EncodeMsg ¶
func (benc *Benc) EncodeMsg(n int, s int, id byte, b []byte, r []byte, enc func(n int) (int, error)) (int, error)
EncodeMsg: ¶
Encodes a message in the Benc format. If the message is the entry point, the ID has to be 0. The maximum size of a message is math.MaxUint64.
Parameters: ¶
- n: The current offset in the byte slice.
- b: The byte slice where the encoded message will be stored.
- id: The ID of the message. If it is the entry point, id has to be 0.
- enc: A function that encodes the content of the message.
Returns: ¶
The new offset after encoding the message.
Msg: ¶
A Msg is a container for handling backward and forward compatibility for fields.
Msg Structure, in the Benc format:
id type reservedIds size of content content // byte | byte->0 byte->MSG []byte | byte->0 int []byte
func (*Benc) EncodeSafeString ¶
EncodeSafeString: ¶
Encodes the given string at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
String: ¶
id type string size string // byte byte->String int []byte
func (*Benc) EncodeString ¶
EncodeString: ¶
Encodes the given string at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Uses zero-allocation string conversion, using the `unsafe` package, to do safe string conversions use `EncodeSafeString`
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
String: ¶
id type string size string // byte byte->String int []byte
func (*Benc) EncodeUint ¶
EncodeUint: ¶
Encodes the given unsigned integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint: ¶
id type binary size unsigned integer // byte byte->Uint byte []byte
func (*Benc) EncodeUint16 ¶
EncodeUint16: ¶
Encodes the given 16-bit unsigned integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint16: ¶
id type uint16 // byte byte->Uint16 2 bytes
func (*Benc) EncodeUint32 ¶
EncodeUint32: ¶
Encodes the given 32-bit unsigned integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint32: ¶
id type uint32 // byte byte->Uint32 4 bytes
func (*Benc) EncodeUint64 ¶
EncodeUint64: ¶
Encodes the given 64-bit unsigned integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint64: ¶
id type uint64 // byte byte->Uint64 4 bytes
func (*Benc) EncodeUint8 ¶
EncodeUint8: ¶
Encodes the given 8-bit unsigned integer at the given offset, and returns the new offset.
Important: ¶
`id` may not be 0
Note: ¶
This function panics on any error, if you prefer error handling using the `error` variable, please generate BENC code using bencc: https://github.com/bencv2/bencc
Uint8: ¶
id type uint8 // byte byte->Uint8 byte
func (*Benc) GetResizedBuffer ¶
GetResizedBuffer: ¶
Retrieves a resized buffer from a one-time allocated buffer, resizing it to the specified size `s`.
func (*Benc) HandleCompatibilityField ¶
func (benc *Benc) HandleCompatibilityField( n int, id byte, b []byte, r []byte, ids []byte, ) (int, bool)
HandleCompatibilityField: ¶
Handles backward/forward compatibility by skipping or ignoring a field based on the provided ID, reserved IDs, and existing IDs.
func (*Benc) SizeBool ¶
SizeBool: ¶
Sizes the given bool and returns its size in the benc format.
Bool: ¶
id type bool // byte byte->Bool byte->1 | byte->0
func (*Benc) SizeFloat32 ¶
SizeFloat32: ¶
Sizes the given 32-bit float and returns its size in the benc format.
Float32: ¶
id type float32 // byte byte->Float32 4 bytes
func (*Benc) SizeFloat64 ¶
SizeFloat64: ¶
Sizes the given 64-bit float and returns its size in the benc format.
Float64: ¶
id type float64 // byte byte->Float64 4 bytes
func (*Benc) SizeInt ¶
SizeInt: ¶
Sizes the given integer and returns its size in the benc format.
Int: ¶
id type binary size integer // byte byte->Int byte []byte
func (*Benc) SizeInt16 ¶
SizeInt16: ¶
Sizes the given 16-bit integer and returns its size in the benc format.
Int16: ¶
id type int16 // byte byte->Int16 2 bytes
func (*Benc) SizeInt32 ¶
SizeInt32: ¶
Sizes the given 32-bit integer and returns its size in the benc format.
Int32: ¶
id type int32 // byte byte->Int32 4 bytes
func (*Benc) SizeInt64 ¶
SizeInt64: ¶
Sizes the given 64-bit integer and returns its size in the benc format.
Int64: ¶
id type int64 // byte byte->Int64 8 bytes
func (*Benc) SizeInt8 ¶
SizeInt8: ¶
Sizes the given 8-bit integer and returns its size in the benc format.
Int8: ¶
id type int8 // byte byte->Int8 byte
func (*Benc) SizeMsg ¶
SizeMsg: ¶
Calculates and returns the size required to encode a message in the Benc format.
Returns: ¶
The size, in bytes, needed to encode a message.
Msg: ¶
A Msg is a container for handling backward and forward compatibility for fields.
Msg Structure, in the Benc format:
id type reservedIds size of content content // byte | byte->0 byte->MSG []byte | byte->0 int []byte
func (*Benc) SizeString ¶
SizeString: ¶
Sizes the given string and returns its size in the benc format.
Note: ¶
Also for `EncodeSafeString` and `DecodeSafeString`
String: ¶
id type string size string // byte byte->String int []byte
func (*Benc) SizeUint ¶
SizeUint: ¶
Sizes the given unsigned integer and returns its size in the benc format.
Uint: ¶
id type binary size unsigned integer // byte byte->Uint byte []byte
func (*Benc) SizeUint16 ¶
SizeUint16: ¶
Sizes the given 16-bit unsigned integer and returns its size in the benc format.
Uint16: ¶
id type uint16 // byte byte->Uint16 2 bytes
func (*Benc) SizeUint32 ¶
SizeUint32: ¶
Sizes the given 32-bit unsigned integer and returns its size in the benc format.
Uint32: ¶
id type uint32 // byte byte->Uint32 4 bytes
func (*Benc) SizeUint64 ¶
SizeUint64: ¶
Sizes the given 64-bit unsigned integer and returns its size in the benc format.
Uint64: ¶
id type uint64 // byte byte->Uint64 4 bytes
func (*Benc) SizeUint8 ¶
SizeUint8: ¶
Sizes the given 8-bit unsigned integer and returns its size in the benc format.
Uint8: ¶
id type uint8 // byte byte->Uint8 byte
func (*Benc) SkipBool ¶
SkipBool: ¶
Skips an encoded bool at the given offset and returns the new offset.
Bool: ¶
id type bool // byte byte->Bool byte->1 | byte->0
func (*Benc) SkipEncodedValueByType ¶
SkipEncodedValueByType: ¶
Skips the encoding of a value based on its data type.
func (*Benc) SkipFloat32 ¶
SkipFloat32: ¶
Skips an encoded 32-bit float at the given offset and returns the new offset.
Float32: ¶
id type float32 // byte byte->Float32 4 bytes
func (*Benc) SkipFloat64 ¶
SkipFloat64: ¶
Skips an encoded 64-bit float at the given offset and returns the new offset.
Float64: ¶
id type float64 // byte byte->Float64 4 bytes
func (*Benc) SkipInt ¶
SkipInt: ¶
Skips an encoded integer at the given offset and returns the new offset.
Int: ¶
id type binary size integer // byte byte->Int byte []byte
func (*Benc) SkipInt16 ¶
SkipInt16: ¶
Skips an encoded 16-bit integer at the given offset and returns the new offset.
Int16: ¶
id type int16 // byte byte->Int16 2 bytes
func (*Benc) SkipInt32 ¶
SkipInt32: ¶
Skips an encoded 32-bit integer at the given offset and returns the new offset.
Int32: ¶
id type int32 // byte byte->Int32 4 bytes
func (*Benc) SkipInt64 ¶
SkipInt64: ¶
Skips an encoded 64-bit integer at the given offset and returns the new offset.
Int64: ¶
id type int64 // byte byte->Int64 8 bytes
func (*Benc) SkipInt8 ¶
SkipInt8: ¶
Skips an encoded 8-bit integer at the given offset and returns the new offset.
Int8: ¶
id type int8 // byte byte->Int8 byte
func (*Benc) SkipMsg ¶
SkipMsg: ¶
Skips the current message in the Benc format.
Parameters: ¶
- n: The current offset in the byte slice.
- b: The byte slice containing the encoded message.
Returns: ¶
The new offset after skipping the message.
func (*Benc) SkipString ¶
SkipString: ¶
Skips an encoded string at the given offset and returns the new offset.
Note: ¶
Also for `EncodeSafeString` and `DecodeSafeString`
String: ¶
id type string size string // byte byte->String int []byte
func (*Benc) SkipUint ¶
SkipUint: ¶
Skips an encoded unsigned integer at the given offset and returns the new offset.
Uint: ¶
id type binary size unsigned integer // byte byte->Uint byte []byte
func (*Benc) SkipUint16 ¶
SkipUint16: ¶
Skips an encoded 16-bit unsigned integer at the given offset and returns the new offset.
Uint16: ¶
id type uint16 // byte byte->Uint16 2 bytes
func (*Benc) SkipUint32 ¶
SkipUint32: ¶
Skips an encoded 32-bit unsigned integer at the given offset and returns the new offset.
Uint32: ¶
id type uint32 // byte byte->Uint32 4 bytes
func (*Benc) SkipUint64 ¶
SkipUint64: ¶
Skips an encoded 64-bit unsigned integer at the given offset and returns the new offset.
Uint64: ¶
id type uint64 // byte byte->Uint64 4 bytes
type Msg ¶
type Msg interface { // Size returns the size of the encoded message. Size(benc *Benc) (int, int) // Encode encodes the message into a byte slice. Encode(benc *Benc, n int, s int, id byte, b []byte) (int, error) // Decode decodes the message from a byte slice. Decode(benc *Benc, n int, id byte, b []byte) (int, error) }
Msg is an interface for encoding and decoding messages.
type Nfbc ¶
type Nfbc struct { }
func (*Nfbc) DecodeInt ¶
DecodeInt: ¶
Decodes a encoded integer at the given offset, returns the decoded integer and the new offset.
Note: ¶
The data at the offset, has to be encoded using `EncodeInt`.
Int: ¶
binary size integer // byte []byte
func (*Nfbc) DecodeUint ¶
DecodeUint: ¶
Decodes a encoded unsigned integer at the given offset, returns the decoded unsigned integer and the new offset.
Note: ¶
The data at the offset, has to be encoded using `EncodeUint`.
Uint: ¶
binary size unsigned integer // byte []byte
func (*Nfbc) DecodeUint8 ¶
DecodeUint8: ¶
Decodes a encoded 8-bit unsigned integer at the given offset, returns the decoded 8-bit unsigned integer and the new offset.
Note: ¶
The data at the offset, has to be encoded using `EncodeUint8`.
Uint8: ¶
uint8 // byte
func (*Nfbc) EncodeInt ¶
EncodeInt: ¶
Encodes the given integer at the given offset, and returns the new offset.
Note: ¶
No id and datatype is encoded, therefore the Nfbc (No Forward/Backward Compatibility)
Int: ¶
binary size integer // byte []byte
func (*Nfbc) EncodeUint ¶
EncodeUint: ¶
Encodes the given unsigned integer at the given offset, and returns the new offset.
Note: ¶
No id and datatype is encoded, therefore the Nfbc (No Forward/Backward Compatibility)
Uint: ¶
binary size unsigned integer // byte []byte
func (*Nfbc) EncodeUint8 ¶
EncodeUint8: ¶
Encodes the given 8-bit unsigned integer at the given offset, and returns the new offset.
Note: ¶
No id and datatype is encoded, therefore the Nfbc (No Forward/Backward Compatibility)
Uint8: ¶
uint8 // byte
func (*Nfbc) SizeInt ¶
SizeInt: ¶
Sizes the given integer and returns its size in the benc format.
Int: ¶
binary size integer // byte []byte
func (*Nfbc) SizeInt8 ¶
SizeUint8: ¶
Sizes the given 8-bit unsigned integer and returns its size in the benc format.
Uint8: ¶
uint8 // byte
func (*Nfbc) SizeUint ¶
SizeUint: ¶
Sizes the given unsigned integer and returns its size in the benc format.
Uint: ¶
binary size unsigned integer // byte []byte
func (*Nfbc) SkipInt ¶
SkipInt: ¶
Skips an encoded integer at the given offset and returns the new offset.
Int: ¶
binary size integer // byte []byte