leb128

package module
v0.0.0-...-d8daac6 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Maximum length of integer
	// encoded forms in bytes.
	MaxLen32 = 5
	MaxLen64 = 10
)

Variables

View Source
var ErrOverflow = errors.New("value overflow")

ErrOverflow is returned when an attempted read of a constrained size int / uint overflows container type.

Functions

func AppendInt

func AppendInt(b []byte, v int) []byte

AppendInt: see AppendInt32 / AppendInt64 depending on platform integer size.

func AppendInt32

func AppendInt32(b []byte, v int32) []byte

AppendInt32 appends LEB128 encoded form of int32 into given buffer, returning result.

func AppendInt64

func AppendInt64(b []byte, v int64) []byte

AppendInt64 appends LEB128 encoded form of int64 into given buffer, returning result.

func AppendUint

func AppendUint(b []byte, v uint) []byte

AppendUint: see AppendUint32 / AppendUint64 depending on platform integer size.

func AppendUint32

func AppendUint32(b []byte, v uint32) []byte

AppendInt32 appends LEB128 encoded form of uint32 into given buffer, returning result.

func AppendUint64

func AppendUint64(b []byte, v uint64) []byte

AppendInt64 appends LEB128 encoded form of int64 into given buffer, returning result.

func Int

func Int(b []byte) (v int, n int)

Int: see Int32 / Int64 depending on platform integer size.

func Int32

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

Int32 reads LEB128 encoded signed value from slice, up to a maximum size of 32 bits. Returns value and number of bytes read. Will return n=-1 on invalid varint or int32 overflow.

func Int64

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

Int64 reads LEB128 encoded signed value from slice, up to a maximum size of 64 bits. Returns value and number of bytes read. Will return n=-1 on invalid varint or int64 overflow.

func ReadInt

func ReadInt(r io.ByteReader) (v int, n int, err error)

ReadInt: see ReadInt32 / ReadInt64 depending on platform integer size.

func ReadInt32

func ReadInt32(r io.ByteReader) (v int32, n int, err error)

ReadInt32 reads LEB128 encoded signed value from byte reader, up to a maximum size of 32 bits. Returns value, number of bytes read and error. Will return ErrOverflow on int32 overflow.

func ReadInt64

func ReadInt64(r io.ByteReader) (v int64, n int, err error)

ReadInt64 reads LEB128 encoded signed value from byte reader, up to a maximum size of 64 bits. Returns value, number of bytes read and error. Will return ErrOverflow on int64 overflow.

func ReadUint

func ReadUint(r io.ByteReader) (v uint, n int, err error)

ReadUint: see ReadUint32 / ReadUint64 depending on platform integer size.

func ReadUint32

func ReadUint32(r io.ByteReader) (v uint32, n int, err error)

ReadUint32 reads LEB128 encoded unsigned value from byte reader, up to a maximum size of 32 bits. Returns value, number of bytes read and error. Will return ErrOverflow on uint32 overflow.

func ReadUint64

func ReadUint64(r io.ByteReader) (v uint64, n int, err error)

ReadUint64 reads LEB128 encoded unsigned value from byte reader, up to a maximum size of 64 bits. Returns value, number of bytes read and error. Will return ErrOverflow on int64 overflow.

func Uint

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

Uint: see Uint32 / Uint64 depending on platform integer size.

func Uint32

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

Uint32 reads LEB128 encoded unsigned value from slice, up to a maximum size of 32 bits. Returns value and number of bytes read. Will return n=-1 on invalid varint or uint32 overflow.

func Uint64

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

Uint32 reads LEB128 encoded unsigned value from slice, up to a maximum size of 64 bits. Returns value and number of bytes read. Will return n=-1 on invalid varint or uint64 overflow.

func WriteInt

func WriteInt(w io.ByteWriter, v int) (n int, err error)

WriteInt: see WriteInt32 / WriteInt64 depending on platform integer size.

func WriteInt32

func WriteInt32(w io.ByteWriter, v int32) (n int, err error)

WriteInt32 writes LEB128 encoded form of int32 to byte writer, returning bytes written and any write error.

func WriteInt64

func WriteInt64(w io.ByteWriter, v int64) (n int, err error)

WriteInt64 writes LEB128 encoded form of int64 to byte writer, returning bytes written and any write error.

func WriteUint

func WriteUint(w io.ByteWriter, v uint) (n int, err error)

WriteUint: see WriteUint32 / WriteUint64 depending on platform integer size.

func WriteUint32

func WriteUint32(w io.ByteWriter, v uint32) (n int, err error)

WriteUint32 writes LEB128 encoded form of uint32 to byte writer, returning bytes written and any write error.

func WriteUint64

func WriteUint64(w io.ByteWriter, v uint64) (n int, err error)

WriteUint64 writes LEB128 encoded form of uint64 to byte writer, returning bytes written and any write error.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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