bencv2

package module
v0.0.0-...-3dc7457 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 5 Imported by: 0

README

BencV2

Visit the blog.

Note: This is only a pre-release for testing purpose:
  • Not tested
  • Broken features
  • Proper error handling
  • Nested struct encoding
As pre-release, is this README not complete!

Creators

Kinetra

License

MIT

Documentation

Index

Constants

View Source
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

View Source
var ErrBufTooSmall = errors.New("buffer too small")

ErrBufTooSmall indicates that the buffer is too small to be reused at the specified size.

View Source
var ErrBytesTooSmall = errors.New("bytes too small")

ErrBytesTooSmall indicates that the buffer given is too small to decode data.

View Source
var ErrIdIsZero = errors.New("specified id cannot be 0")

ErrIdIsZero indicates that the ID has to be over 0 and <= 255.

View Source
var ErrInvalidIntFormat = errors.New("invalid int format")

ErrInvalidIntFormat indicates that the buffer given is invalid to decode an int.

View Source
var ErrInvalidType = errors.New("invalid type")

ErrInvalidType indicates that the decoded type is invalid.

View Source
var ErrInvalidUintFormat = errors.New("invalid uint format")

ErrInvalidUintFormat indicates that the buffer given is invalid to decode a uint.

View Source
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

func NewEncoder(bufSize ...int) *Benc

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

func (benc *Benc) Decode(b []byte, msg Msg) error

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

func (benc *Benc) DecodeBool(n int, id byte, b []byte, r []byte, i []byte) (int, bool)

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

func (benc *Benc) DecodeFloat32(n int, id byte, b []byte, r []byte, i []byte) (int, float32)

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

func (benc *Benc) DecodeFloat64(n int, id byte, b []byte, r []byte, i []byte) (int, float64)

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

func (benc *Benc) DecodeInt(n int, id byte, b []byte, r []byte, i []byte) (int, int)

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

func (benc *Benc) DecodeInt16(n int, id byte, b []byte, r []byte, i []byte) (int, int16)

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

func (benc *Benc) DecodeInt32(n int, id byte, b []byte, r []byte, i []byte) (int, int32)

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

func (benc *Benc) DecodeInt64(n int, id byte, b []byte, r []byte, i []byte) (int, int64)

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

func (benc *Benc) DecodeInt8(n int, id byte, b []byte, r []byte, i []byte) (int, int8)

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

func (benc *Benc) DecodeMsg(n int, b []byte, id byte, r []byte, ids []byte) (int, []byte, error)

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

func (benc *Benc) DecodeSafeString(n int, id byte, b []byte, r []byte, i []byte) (int, string)

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

func (benc *Benc) DecodeUint(n int, id byte, b []byte, r []byte, i []byte) (int, uint)

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

func (benc *Benc) DecodeUint16(n int, id byte, b []byte, r []byte, i []byte) (int, uint16)

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

func (benc *Benc) DecodeUint32(n int, id byte, b []byte, r []byte, i []byte) (int, uint32)

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

func (benc *Benc) DecodeUint64(n int, id byte, b []byte, r []byte, i []byte) (int, uint64)

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

func (benc *Benc) DecodeUint8(n int, id byte, b []byte, r []byte, i []byte) (int, uint8)

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

func (benc *Benc) Encode(msg Msg) ([]byte, error)

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

func (benc *Benc) EncodeBool(n int, b []byte, v bool, id byte) int

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

func (benc *Benc) EncodeFloat32(n int, b []byte, v float32, id byte) int

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

func (benc *Benc) EncodeFloat64(n int, b []byte, v float64, id byte) int

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

func (benc *Benc) EncodeInt(n int, b []byte, v int, id byte) int

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

func (benc *Benc) EncodeInt16(n int, b []byte, v int16, id byte) int

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

func (benc *Benc) EncodeInt32(n int, b []byte, v int32, id byte) int

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

func (benc *Benc) EncodeInt64(n int, b []byte, v int64, id byte) int

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

func (benc *Benc) EncodeInt8(n int, b []byte, v int8, id byte) int

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

func (benc *Benc) EncodeSafeString(n int, b []byte, v string, id byte) int

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

func (benc *Benc) EncodeString(n int, b []byte, v string, id byte) int

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

func (benc *Benc) EncodeUint(n int, b []byte, v uint, id byte) int

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

func (benc *Benc) EncodeUint16(n int, b []byte, v uint16, id byte) int

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

func (benc *Benc) EncodeUint32(n int, b []byte, v uint32, id byte) int

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

func (benc *Benc) EncodeUint64(n int, b []byte, v uint64, id byte) int

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

func (benc *Benc) EncodeUint8(n int, b []byte, v uint8, id byte) int

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

func (benc *Benc) GetResizedBuffer(
	s int,
) ([]byte, error)

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

func (benc *Benc) SizeBool() int

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

func (benc *Benc) SizeFloat32() int

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

func (benc *Benc) SizeFloat64() int

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

func (benc *Benc) SizeInt(v int) int

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

func (benc *Benc) SizeInt16() int

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

func (benc *Benc) SizeInt32() int

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

func (benc *Benc) SizeInt64() int

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

func (benc *Benc) SizeInt8() int

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

func (benc *Benc) SizeMsg(s int, r []byte) int

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

func (benc *Benc) SizeString(v string) int

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

func (benc *Benc) SizeUint(v uint) int

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

func (benc *Benc) SizeUint16() int

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

func (benc *Benc) SizeUint32() int

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

func (benc *Benc) SizeUint64() int

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

func (benc *Benc) SizeUint8() int

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

func (benc *Benc) SkipBool(n int) int

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

func (benc *Benc) SkipEncodedValueByType(
	n int,
	t byte,
	b []byte,
) int

SkipEncodedValueByType:

Skips the encoding of a value based on its data type.

func (*Benc) SkipFloat32

func (benc *Benc) SkipFloat32(n int) int

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

func (benc *Benc) SkipFloat64(n int) int

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

func (benc *Benc) SkipInt(n int, b []byte) int

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

func (benc *Benc) SkipInt16(n int) int

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

func (benc *Benc) SkipInt32(n int) int

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

func (benc *Benc) SkipInt64(n int) int

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

func (benc *Benc) SkipInt8(n int) int

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

func (benc *Benc) SkipMsg(n int, b []byte) int

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

func (benc *Benc) SkipString(n int, b []byte) int

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

func (benc *Benc) SkipUint(n int, b []byte) int

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

func (benc *Benc) SkipUint16(n int) int

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

func (benc *Benc) SkipUint32(n int) int

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

func (benc *Benc) SkipUint64(n int) int

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

func (*Benc) SkipUint8

func (benc *Benc) SkipUint8(n int) int

SkipUint8:

Skips an encoded 8-bit unsigned integer at the given offset and returns the new offset.

Uint8:

     id        type       uint8
//  byte   byte->Uint8     byte

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

func (nfbc *Nfbc) DecodeInt(n int, b []byte) (int, int, error)

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

func (nfbc *Nfbc) DecodeUint(n int, b []byte) (int, uint, error)

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

func (nfbc *Nfbc) DecodeUint8(n int, b []byte) (int, uint8)

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

func (nfbc *Nfbc) EncodeInt(n int, b []byte, v int) int

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

func (nfbc *Nfbc) EncodeUint(n int, b []byte, v uint) int

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

func (nfbc *Nfbc) EncodeUint8(n int, b []byte, v uint8) int

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

func (nfbc *Nfbc) SizeInt(v int) int

SizeInt:

Sizes the given integer and returns its size in the benc format.

Int:

    binary size    integer
//     byte         []byte

func (*Nfbc) SizeInt8

func (nfbc *Nfbc) SizeInt8() int

SizeUint8:

Sizes the given 8-bit unsigned integer and returns its size in the benc format.

Uint8:

    uint8
//  byte

func (*Nfbc) SizeUint

func (nfbc *Nfbc) SizeUint(v uint) int

SizeUint:

Sizes the given unsigned integer and returns its size in the benc format.

Uint:

    binary size    unsigned integer
//     byte             []byte

func (*Nfbc) SkipInt

func (nfbc *Nfbc) SkipInt(n int, b []byte) int

SkipInt:

Skips an encoded integer at the given offset and returns the new offset.

Int:

    binary size    integer
//     byte         []byte

func (*Nfbc) SkipUint

func (nfbc *Nfbc) SkipUint(n int, b []byte) int

SkipUint:

Skips an encoded unsigned integer at the given offset and returns the new offset.

Uint:

    binary size    unsigned integer
//     byte             []byte

func (*Nfbc) SkipUint8

func (nfbc *Nfbc) SkipUint8(n int) int

SkipUint8:

Skips an encoded 8-bit unsigned integer at the given offset and returns the new offset.

Uint8:

    uint8
//  byte

Jump to

Keyboard shortcuts

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