msgpack

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 4 Imported by: 0

README

msgpack

import "github.com/kitsunium/sdk/pkg/v1/data/codec/msgpack"

Package msgpack registers the MessagePack codec with the SDK's codec registry — and no other codec — when it is imported (ADR 0134):

import _ "github.com/kitsunium/sdk/pkg/v1/data/codec/msgpack"

The codec is the msgpack.org specification written on the standard library: maps, arrays, the integer and float families, strings, binary, the timestamp extension, application extensions as an Ext, struct fields by their msgpack tag, and types that marshal themselves. A time.Duration is an integer of int64 nanoseconds, the rule of every binary format (#1126). Input is bounded in size and depth, and read without allocating what a declared length claims before the bytes are there. It streams.

Everything that dispatches through the registry by format name then reads and writes it: the codec package's Marshal and Unmarshal, config.FSSource and i18n.LoadFS. Importing github.com/kitsunium/sdk/pkg/v1/data/codec instead registers every format the SDK ships; this package links this one codec, the core package declaring its codes and the standard library, and nothing else. Importing both is harmless: a format is registered by the package that implements it, which Go initialises once however many packages import it.

Errors

Failures carry the range 0.3.7.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.7.1  a value MessagePack cannot represent, nesting past the bound, a writer's failure
CodeUnmarshalFailed  0.3.7.2  malformed or truncated input, past a bound, or a value the target cannot hold

No error message quotes the input.

Index

Constants

const CodeDepthExceeded errs.Code = 198406

CodeDepthExceeded is 0.3.7.6: containers nested past maxDepth.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.CodeMsgPackDepthExceeded.

Code 0.3.7.6

const CodeDuplicateKey errs.Code = 198403

CodeDuplicateKey is 0.3.7.3: NewStrict's instance found a map that repeats a key.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.CodeMsgPackDuplicateKey.

Code 0.3.7.3

const CodeMarshalFailed errs.Code = 198401

CodeMarshalFailed is 0.3.7.1: a value MessagePack cannot represent, nesting past the bound, a writer's failure.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.CodeMsgPackMarshalFailed.

Code 0.3.7.1

const CodeSizeExceeded errs.Code = 198405

CodeSizeExceeded is 0.3.7.5: input past maxMsgPackBytes.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.CodeMsgPackSizeExceeded.

Code 0.3.7.5

const CodeUnknownMember errs.Code = 198404

CodeUnknownMember is 0.3.7.4: NewStrict's instance found a member no struct field claims.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.CodeMsgPackUnknownMember.

Code 0.3.7.4

const CodeUnmarshalFailed errs.Code = 198402

CodeUnmarshalFailed is 0.3.7.2: malformed or truncated input, past a bound, or a value the target cannot hold.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.CodeMsgPackUnmarshalFailed.

Code 0.3.7.2

const Format = "msgpack"

Format is the name MessagePack is registered under. It is an untyped constant, so it goes wherever a format name is taken — the codec package's Marshal, config.FSSource's string, i18n.LoadFS's codec.Format — without a conversion.

Variables

var DepthExceeded *errs.Error

DepthExceeded is the sentinel of CodeDepthExceeded.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.DepthExceeded.

Code 0.3.7.6 · reason DEPTH_EXCEEDED · public "MsgPack input nests too deeply"

var DuplicateKey *errs.Error

DuplicateKey is the sentinel of CodeDuplicateKey.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.DuplicateKey.

Code 0.3.7.3 · reason DUPLICATE_KEY · public "MessagePack document repeats a map key"

var MarshalFailed *errs.Error

MarshalFailed is the sentinel of CodeMarshalFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.MarshalFailed.

Code 0.3.7.1 · reason MARSHAL_FAILED · public "MessagePack encoding failed"

var SizeExceeded *errs.Error

SizeExceeded is the sentinel of CodeSizeExceeded.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.SizeExceeded.

Code 0.3.7.5 · reason SIZE_EXCEEDED · public "MsgPack input exceeds a size limit"

var UnknownMember *errs.Error

UnknownMember is the sentinel of CodeUnknownMember.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.UnknownMember.

Code 0.3.7.4 · reason UNKNOWN_MEMBER · public "MessagePack document carries an unknown member"

var UnmarshalFailed *errs.Error

UnmarshalFailed is the sentinel of CodeUnmarshalFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/msgpack.UnmarshalFailed.

Code 0.3.7.2 · reason UNMARSHAL_FAILED · public "MessagePack decoding failed"

func NewStrict

func NewStrict() codec.Codec

NewStrict returns a fresh MessagePack codec, not registered, that reads a document one way or not at all: a map repeating a key is refused with CodeDuplicateKey, a member no struct field claims with CodeUnknownMember. The registered format keeps last-wins and skips unknown members.

type Ext

Ext is an extension value the codec has no Go type for — an application type, 0 to 127, and its payload. A document carrying one decodes into an interface with the extension as an Ext; an Ext encodes in the shortest form its payload allows. The timestamp (−1) stays a time.Time.

type Ext = svcmsgpack.Ext

Ext is an alias of github.com/kitsunium/sdk/internal/service/data/codec/msgpack.Ext, declared as:

type Ext struct {
	// Data is the payload, opaque to the codec.
	Data []byte
	// Type is the extension type.
	Type int8
}

Generated from docs/api by tools/genindex.

Documentation

Overview

Package msgpack registers the MessagePack codec with the SDK's codec registry — and no other codec — when it is imported (ADR 0134):

import _ "github.com/kitsunium/sdk/pkg/v1/data/codec/msgpack"

The codec is the msgpack.org specification written on the standard library: maps, arrays, the integer and float families, strings, binary, the timestamp extension, application extensions as an Ext, struct fields by their msgpack tag, and types that marshal themselves. A time.Duration is an integer of int64 nanoseconds, the rule of every binary format (#1126). Input is bounded in size and depth, and read without allocating what a declared length claims before the bytes are there. It streams.

Everything that dispatches through the registry by format name then reads and writes it: the codec package's Marshal and Unmarshal, config.FSSource and i18n.LoadFS. Importing github.com/kitsunium/sdk/pkg/v1/data/codec instead registers every format the SDK ships; this package links this one codec, the core package declaring its codes and the standard library, and nothing else. Importing both is harmless: a format is registered by the package that implements it, which Go initialises once however many packages import it.

Errors

Failures carry the range 0.3.7.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.7.1  a value MessagePack cannot represent, nesting past the bound, a writer's failure
CodeUnmarshalFailed  0.3.7.2  malformed or truncated input, past a bound, or a value the target cannot hold

No error message quotes the input.

Index

Constants

View Source
const (
	// CodeMarshalFailed is 0.3.7.1: a value MessagePack cannot represent,
	// nesting past the bound, a writer's failure.
	CodeMarshalFailed errs.Code = coremsgpack.CodeMsgPackMarshalFailed
	// CodeUnmarshalFailed is 0.3.7.2: malformed or truncated input, past a
	// bound, or a value the target cannot hold.
	CodeUnmarshalFailed errs.Code = coremsgpack.CodeMsgPackUnmarshalFailed
	// CodeDuplicateKey is 0.3.7.3: NewStrict's instance found a map that
	// repeats a key.
	CodeDuplicateKey errs.Code = coremsgpack.CodeMsgPackDuplicateKey
	// CodeUnknownMember is 0.3.7.4: NewStrict's instance found a member
	// no struct field claims.
	CodeUnknownMember errs.Code = coremsgpack.CodeMsgPackUnknownMember
	// CodeSizeExceeded is 0.3.7.5: input past maxMsgPackBytes.
	CodeSizeExceeded errs.Code = coremsgpack.CodeMsgPackSizeExceeded
	// CodeDepthExceeded is 0.3.7.6: containers nested past maxDepth.
	CodeDepthExceeded errs.Code = coremsgpack.CodeMsgPackDepthExceeded
)

The error codes, range 0.3.7.*, declared in the core (ADR 0160).

View Source
const Format = "msgpack"

Format is the name MessagePack is registered under. It is an untyped constant, so it goes wherever a format name is taken — the codec package's Marshal, config.FSSource's string, i18n.LoadFS's codec.Format — without a conversion.

Variables

View Source
var (
	// MarshalFailed is the sentinel of [CodeMarshalFailed].
	MarshalFailed = coremsgpack.MarshalFailed
	// UnmarshalFailed is the sentinel of [CodeUnmarshalFailed].
	UnmarshalFailed = coremsgpack.UnmarshalFailed
	// DuplicateKey is the sentinel of [CodeDuplicateKey].
	DuplicateKey = coremsgpack.DuplicateKey
	// UnknownMember is the sentinel of [CodeUnknownMember].
	UnknownMember = coremsgpack.UnknownMember
	// SizeExceeded is the sentinel of [CodeSizeExceeded].
	SizeExceeded = coremsgpack.SizeExceeded
	// DepthExceeded is the sentinel of [CodeDepthExceeded].
	DepthExceeded = coremsgpack.DepthExceeded
)

The sentinels, for errors.Is: each carries the code of the same name.

Functions

func NewStrict added in v0.12.0

func NewStrict() codec.Codec

NewStrict returns a fresh MessagePack codec, not registered, that reads a document one way or not at all: a map repeating a key is refused with CodeDuplicateKey, a member no struct field claims with CodeUnknownMember. The registered format keeps last-wins and skips unknown members.

Types

type Ext added in v0.12.0

type Ext = svcmsgpack.Ext

Ext is an extension value the codec has no Go type for — an application type, 0 to 127, and its payload. A document carrying one decodes into an interface with the extension as an Ext; an Ext encodes in the shortest form its payload allows. The timestamp (−1) stays a time.Time.

Jump to

Keyboard shortcuts

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