encoding

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: MIT, MIT Imports: 4 Imported by: 0

Documentation

Overview

Package encoding provides functions to marshal and unmarshal data types.

Index

Constants

This section is empty.

Variables

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

ErrBufTooSmall is returned when the buffer is too small to read/write.

View Source
var ErrOverflow = errors.New("varint overflows a 64-bit integer")

ErrOverflow is returned when a varint overflows a 64-bit integer.

Functions

func MarshalBool

func MarshalBool(n int, b []byte, v bool) int

MarshalBool marshals a bool into the buffer.

func MarshalByte

func MarshalByte(n int, b []byte, byt byte) int

MarshalByte marshals a byte into the buffer.

func MarshalBytes

func MarshalBytes(n int, b []byte, bs []byte) int

MarshalBytes marshals a byte slice into the buffer.

func MarshalFloat32

func MarshalFloat32(n int, b []byte, v float32) int

MarshalFloat32 marshals a float32 into the buffer.

func MarshalFloat64

func MarshalFloat64(n int, b []byte, v float64) int

MarshalFloat64 marshals a float64 into the buffer.

func MarshalInt

func MarshalInt(n int, b []byte, sv int) int

MarshalInt marshals a signed integer into the buffer.

func MarshalInt16

func MarshalInt16(n int, b []byte, v int16) int

MarshalInt16 marshals an int16 into the buffer.

func MarshalInt32

func MarshalInt32(n int, b []byte, v int32) int

MarshalInt32 marshals an int32 into the buffer.

func MarshalInt64

func MarshalInt64(n int, b []byte, v int64) int

MarshalInt64 marshals an int64 into the buffer.

func MarshalMap

func MarshalMap[K comparable, V any](n int, b []byte, m map[K]V, kMarshaler MarshalFunc[K], vMarshaler MarshalFunc[V]) int

MarshalMap marshals a map into the buffer.

func MarshalSlice

func MarshalSlice[T any](n int, b []byte, slice []T, marshaler MarshalFunc[T]) int

MarshalSlice marshals a slice into the buffer.

func MarshalString

func MarshalString(n int, b []byte, str string) int

MarshalString marshals a string into the buffer.

func MarshalUint

func MarshalUint(n int, b []byte, v uint) int

MarshalUint marshals an unsigned integer into the buffer.

func MarshalUint16

func MarshalUint16(n int, b []byte, v uint16) int

MarshalUint16 marshals a uint16 into the buffer.

func MarshalUint32

func MarshalUint32(n int, b []byte, v uint32) int

MarshalUint32 marshals a uint32 into the buffer.

func MarshalUint64

func MarshalUint64(n int, b []byte, v uint64) int

MarshalUint64 marshals a uint64 into the buffer.

func SizeBool

func SizeBool() int

SizeBool returns the bytes needed to marshal a bool.

func SizeByte

func SizeByte() int

SizeByte returns the bytes needed to marshal a byte.

func SizeBytes

func SizeBytes(bs []byte) int

SizeBytes returns the bytes needed to marshal a byte slice.

func SizeFloat32

func SizeFloat32() int

SizeFloat32 returns the bytes needed to marshal a float32.

func SizeFloat64

func SizeFloat64() int

SizeFloat64 returns the bytes needed to marshal a float64.

func SizeInt

func SizeInt(sv int) int

SizeInt returns the bytes needed to marshal a signed integer.

func SizeInt16

func SizeInt16() int

SizeInt16 returns the bytes needed to marshal an int16.

func SizeInt32

func SizeInt32() int

SizeInt32 returns the bytes needed to marshal an int32.

func SizeInt64

func SizeInt64() int

SizeInt64 returns the bytes needed to marshal an int64.

func SizeMap

func SizeMap[K comparable, V any](m map[K]V, kSizer interface{}, vSizer interface{}) (s int)

SizeMap returns the bytes needed to marshal a map.

func SizeSlice

func SizeSlice[T any](slice []T, sizer interface{}) (s int)

SizeSlice returns the bytes needed to marshal a slice.

func SizeString

func SizeString(str string) int

SizeString returns the bytes needed to marshal a string.

func SizeUint

func SizeUint(v uint) int

SizeUint returns the bytes needed to marshal an unsigned integer.

func SizeUint16

func SizeUint16() int

SizeUint16 returns the bytes needed to marshal a uint16.

func SizeUint32

func SizeUint32() int

SizeUint32 returns the bytes needed to marshal a uint32.

func SizeUint64

func SizeUint64() int

SizeUint64 returns the bytes needed to marshal a uint64.

func SkipBool

func SkipBool(n int, b []byte) (int, error)

SkipBool skips a bool in the buffer.

func SkipByte

func SkipByte(n int, b []byte) (int, error)

SkipByte skips a byte in the buffer.

func SkipBytes

func SkipBytes(n int, b []byte) (int, error)

SkipBytes skips a byte slice in the buffer.

func SkipFloat32

func SkipFloat32(n int, b []byte) (int, error)

SkipFloat32 skips a float32 in the buffer.

func SkipFloat64

func SkipFloat64(n int, b []byte) (int, error)

SkipFloat64 skips a float64 in the buffer.

func SkipInt16

func SkipInt16(n int, b []byte) (int, error)

SkipInt16 skips an int16 in the buffer.

func SkipInt32

func SkipInt32(n int, b []byte) (int, error)

SkipInt32 skips an int32 in the buffer.

func SkipInt64

func SkipInt64(n int, b []byte) (int, error)

SkipInt64 skips an int64 in the buffer.

func SkipMap

func SkipMap(n int, b []byte) (int, error)

SkipMap skips a map in the buffer.

func SkipSlice

func SkipSlice(n int, b []byte) (int, error)

SkipSlice skips a slice in the buffer.

func SkipString

func SkipString(n int, b []byte) (int, error)

SkipString skips a string in the buffer.

func SkipUint16

func SkipUint16(n int, b []byte) (int, error)

SkipUint16 skips a uint16 in the buffer.

func SkipUint32

func SkipUint32(n int, b []byte) (int, error)

SkipUint32 skips a uint32 in the buffer.

func SkipUint64

func SkipUint64(n int, b []byte) (int, error)

SkipUint64 skips a uint64 in the buffer.

func SkipVarint

func SkipVarint(n int, buf []byte) (int, error)

SkipVarint skips a varint in the buffer.

func UnmarshalBool

func UnmarshalBool(n int, b []byte) (int, bool, error)

UnmarshalBool unmarshals a bool from the buffer.

func UnmarshalByte

func UnmarshalByte(n int, b []byte) (int, byte, error)

UnmarshalByte unmarshals a byte from the buffer.

func UnmarshalBytes

func UnmarshalBytes(n int, b []byte) (int, []byte, error)

UnmarshalBytes unmarshals a byte slice from the buffer.

func UnmarshalFloat32

func UnmarshalFloat32(n int, b []byte) (int, float32, error)

UnmarshalFloat32 unmarshals a float32 from the buffer.

func UnmarshalFloat64

func UnmarshalFloat64(n int, b []byte) (int, float64, error)

UnmarshalFloat64 unmarshals a float64 from the buffer.

func UnmarshalInt

func UnmarshalInt(n int, buf []byte) (int, int, error)

UnmarshalInt unmarshals a signed integer from the buffer.

func UnmarshalInt16

func UnmarshalInt16(n int, b []byte) (int, int16, error)

UnmarshalInt16 unmarshals an int16 from the buffer.

func UnmarshalInt32

func UnmarshalInt32(n int, b []byte) (int, int32, error)

UnmarshalInt32 unmarshals an int32 from the buffer.

func UnmarshalInt64

func UnmarshalInt64(n int, b []byte) (int, int64, error)

UnmarshalInt64 unmarshals an int64 from the buffer.

func UnmarshalMap

func UnmarshalMap[K comparable, V any](n int, b []byte, kUnmarshaler interface{}, vUnmarshaler interface{}) (int, map[K]V, error)

UnmarshalMap unmarshals a map from the buffer.

func UnmarshalSlice

func UnmarshalSlice[T any](n int, b []byte, unmarshaler interface{}) (int, []T, error)

UnmarshalSlice unmarshals a slice from the buffer.

func UnmarshalString

func UnmarshalString(n int, b []byte) (int, string, error)

UnmarshalString unmarshals a string from the buffer.

func UnmarshalUint

func UnmarshalUint(n int, buf []byte) (int, uint, error)

UnmarshalUint unmarshals an unsigned integer from the buffer.

func UnmarshalUint16

func UnmarshalUint16(n int, b []byte) (int, uint16, error)

UnmarshalUint16 unmarshals a uint16 from the buffer.

func UnmarshalUint32

func UnmarshalUint32(n int, b []byte) (int, uint32, error)

UnmarshalUint32 unmarshals a uint32 from the buffer.

func UnmarshalUint64

func UnmarshalUint64(n int, b []byte) (int, uint64, error)

UnmarshalUint64 unmarshals a uint64 from the buffer.

Types

type MarshalFunc

type MarshalFunc[T any] func(n int, b []byte, t T) int

MarshalFunc is a function that marshals a value of type T into a byte slice.

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

Signed is a constraint that permits any signed integer type. If future releases of Go add new predeclared signed integer types, this constraint will be modified to include them.

type StringHeader

type StringHeader struct {
	Data *byte
	Len  int
}

StringHeader is a string header.

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Unsigned is a constraint that permits any unsigned integer type. If future releases of Go add new predeclared unsigned integer types, this constraint will be modified to include them.

Jump to

Keyboard shortcuts

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