msgpunsafe

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 6 Imported by: 0

README

msgpunsafe

Unsafe routines for msgpack decoding.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleError added in v0.0.2

func HandleError(r any, err *error)

func IsNil added in v0.0.2

func IsNil(src unsafe.Pointer, lim unsafe.Pointer) (bool, unsafe.Pointer)

IsNil checks if the current Msgpack value is nil (marker 0xc0). If it is nil, it returns true and shifts the pointer by 1 byte. If it is not nil, it returns false and the original untouched pointer.

func TakeBinHeader

func TakeBinHeader(src unsafe.Pointer, lim unsafe.Pointer) (int, unsafe.Pointer)

TakeBinHeader reads Binary header of Msgpack ([]byte data). Returns the size of the slice in bytes and updated pointer.

func TakeBool

func TakeBool(src unsafe.Pointer, lim unsafe.Pointer) (bool, unsafe.Pointer)

TakeBool reads a boolean value from Msgpack. Returns the boolean value and an updated pointer.

func TakeBytes

func TakeBytes(src unsafe.Pointer, lim unsafe.Pointer, sBuf *SafeBuffer) ([]byte, unsafe.Pointer)

TakeBytes reads a byte slice from Msgpack, copies its content into the SafeBuffer, and returns a long-lived []byte that safely survives the temporary Tarantool buffer.

func TakeFloat32

func TakeFloat32(src unsafe.Pointer, lim unsafe.Pointer) (float32, unsafe.Pointer)

TakeFloat32 reads numeric value into float32.

func TakeFloat64

func TakeFloat64(src unsafe.Pointer, lim unsafe.Pointer) (float64, unsafe.Pointer)

TakeFloat64 reads numeric value into float64.

func TakeInt

func TakeInt(src unsafe.Pointer, lim unsafe.Pointer) (int, unsafe.Pointer)

TakeInt reads numeric value into int.

func TakeInt8

func TakeInt8(src unsafe.Pointer, lim unsafe.Pointer) (int8, unsafe.Pointer)

TakeInt8 reads numeric value into int8.

func TakeInt16

func TakeInt16(src unsafe.Pointer, lim unsafe.Pointer) (int16, unsafe.Pointer)

TakeInt16 reads numeric value into int16.

func TakeInt32

func TakeInt32(src unsafe.Pointer, lim unsafe.Pointer) (int32, unsafe.Pointer)

TakeInt32 reads numeric value into int32.

func TakeInt64

func TakeInt64(src unsafe.Pointer, lim unsafe.Pointer) (int64, unsafe.Pointer)

TakeInt64 reads numeric value into int64.

func TakeMapHeader

func TakeMapHeader(src unsafe.Pointer, lim unsafe.Pointer) (int, unsafe.Pointer)

TakeMapHeader read Map header of Msgpack. Returns a number of elements (key-value pairs) in there and updated pointer.

func TakeSliceHeader

func TakeSliceHeader(src unsafe.Pointer, lim unsafe.Pointer) (int, unsafe.Pointer)

TakeSliceHeader read Array header of Msgpack. Returns a number of elements in there and updated pointer.

func TakeStrHeader

func TakeStrHeader(src unsafe.Pointer, lim unsafe.Pointer) (int, unsafe.Pointer)

TakeStrHeader reads String header of Msgpack. Returns the size of the string in bytes and updated pointer.

func TakeString

func TakeString(src unsafe.Pointer, lim unsafe.Pointer, sBuf *SafeBuffer) (string, unsafe.Pointer)

TakeString reads a string from Msgpack, copies its content into the SafeBuffer, and returns a long-lived string that safely survives the temporary Tarantool buffer.

func TakeStringZC added in v0.0.2

func TakeStringZC(src unsafe.Pointer, lim unsafe.Pointer) (string, unsafe.Pointer)

TakeStringZC reads a string from Msgpack using Zero-Copy. The returned string points directly into the incoming 'src' memory buffer. WARNING: The string is only valid as long as the underlying source buffer is not cleared or reused.

func TakeUint

func TakeUint(src unsafe.Pointer, lim unsafe.Pointer) (uint, unsafe.Pointer)

TakeUint reads numeric value uinto uint.

func TakeUint8

func TakeUint8(src unsafe.Pointer, lim unsafe.Pointer) (uint8, unsafe.Pointer)

TakeUint8 reads numeric value uinto uint8.

func TakeUint16

func TakeUint16(src unsafe.Pointer, lim unsafe.Pointer) (uint16, unsafe.Pointer)

TakeUint16 reads numeric value uinto uint16.

func TakeUint32

func TakeUint32(src unsafe.Pointer, lim unsafe.Pointer) (uint32, unsafe.Pointer)

TakeUint32 reads numeric value uinto uint32.

func TakeUint64

func TakeUint64(src unsafe.Pointer, lim unsafe.Pointer) (uint64, unsafe.Pointer)

TakeUint64 reads numeric value uinto uint64.

Types

type ErrorCode

type ErrorCode int
const (
	ErrorSliceExhausted ErrorCode = iota
	ErrorSliceHeaderTruncated
	ErrorSliceHeaderCorrupted

	ErrorMapExhausted
	ErrorMapHeaderTruncated
	ErrorMapHeaderCorrupted

	ErrorStrExhausted
	ErrorStrHeaderTruncated
	ErrorStrHeaderCorrupted
	ErrorStrLenConflict

	ErrorBinExhausted
	ErrorBinHeaderTruncated
	ErrorBinHeaderCorrupted
	ErrorBinLenConflict

	ErrorNumberExhausted
	ErrorNumberTruncated
	ErrorIntCorrupted
	ErrorUintCorrupted
	ErrorFloatCorrupted
	ErrorIntOverflow
	ErrorUintOverflow

	ErrorBoolExhausted
	ErrorBoolCorrupted

	ErrorStructExhausted
	ErrorStructCorrupted
	ErrorUnknownField
	ErrorRequiredFieldMissing
)

func (ErrorCode) Error

func (e ErrorCode) Error() string

func (ErrorCode) IsValid

func (e ErrorCode) IsValid() bool

type SafeBuffer

type SafeBuffer struct {
	// contains filtered or unexported fields
}

SafeBuffer buffer for safe storage of strings and bytes for msgpack data from temporary buffer.

func NewSafeBuffer

func NewSafeBuffer(bufCap int) *SafeBuffer

NewSafeBuffer creates safe buffer with preallocated bytes. Beware, you better not to use anything larger than 512 unless you are going to reuse it. And you better to make it smaller than 512 at that: the smaller the size the easier is to alloc.

func (*SafeBuffer) AllocBytes

func (b *SafeBuffer) AllocBytes(data unsafe.Pointer, size int) []byte

AllocBytes safely stores data referenced with pointer and the size as a []byte.

func (*SafeBuffer) AllocString

func (b *SafeBuffer) AllocString(data unsafe.Pointer, size int) string

AllocString safely stores data referenced with pointer and the size as a string.

Jump to

Keyboard shortcuts

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