tlv

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 3 Imported by: 0

README

tlv

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

Package tlv registers the TLV 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/tlv"

The codec is the SDK's self-describing Type-Length-Value binary: every value carries its kind and its length, so a document decodes without a schema, into a typed target or into an interface. Structs, maps, slices and the scalar kinds are written by reflection. Input is bounded in size and depth. 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.22.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.22.1  the value could not be encoded, or the writer failed
CodeUnmarshalFailed  0.3.22.2  a malformed record, a type mismatch, or the reader failed
CodeUnsupportedType  0.3.22.3  a channel, a function, a complex number, an unsafe pointer
CodeDepthExceeded    0.3.22.4  nesting past 32 levels
CodeSizeExceeded     0.3.22.5  an input past 10 MiB
CodeTruncated        0.3.22.6  the input ends inside a record

No error message quotes the input.

Index

Constants

const CodeDepthExceeded errs.Code = 202244

CodeDepthExceeded is 0.3.22.4: nesting past 32 levels.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/tlv.CodeTLVDepthExceeded.

Code 0.3.22.4

const CodeMarshalFailed errs.Code = 202241

CodeMarshalFailed is 0.3.22.1: the value could not be encoded, or the writer failed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/tlv.CodeTLVMarshalFailed.

Code 0.3.22.1

const CodeSizeExceeded errs.Code = 202245

CodeSizeExceeded is 0.3.22.5: an input past 10 MiB.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/tlv.CodeTLVSizeExceeded.

Code 0.3.22.5

const CodeTruncated errs.Code = 202246

CodeTruncated is 0.3.22.6: the input ends inside a record.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/tlv.CodeTLVTruncated.

Code 0.3.22.6

const CodeUnmarshalFailed errs.Code = 202242

CodeUnmarshalFailed is 0.3.22.2: a malformed record, a type mismatch, or the reader failed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/tlv.CodeTLVUnmarshalFailed.

Code 0.3.22.2

const CodeUnsupportedType errs.Code = 202243

CodeUnsupportedType is 0.3.22.3: a channel, a function, a complex number, an unsafe pointer.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/tlv.CodeTLVUnsupportedType.

Code 0.3.22.3

const Format = "tlv"

Format is the name TLV 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/tlv.DepthExceeded.

Code 0.3.22.4 · reason DEPTH_EXCEEDED · public "TLV nesting depth exceeds limit"

var MarshalFailed *errs.Error

MarshalFailed is the sentinel of CodeMarshalFailed.

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

Code 0.3.22.1 · reason MARSHAL_FAILED · public "TLV encoding failed"

var SizeExceeded *errs.Error

SizeExceeded is the sentinel of CodeSizeExceeded.

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

Code 0.3.22.5 · reason SIZE_EXCEEDED · public "TLV input exceeds size limit"

var Truncated *errs.Error

Truncated is the sentinel of CodeTruncated.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/tlv.Truncated.

Code 0.3.22.6 · reason TRUNCATED · public "TLV buffer truncated"

var UnmarshalFailed *errs.Error

UnmarshalFailed is the sentinel of CodeUnmarshalFailed.

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

Code 0.3.22.2 · reason UNMARSHAL_FAILED · public "TLV decoding failed"

var UnsupportedType *errs.Error

UnsupportedType is the sentinel of CodeUnsupportedType.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/tlv.UnsupportedType.

Code 0.3.22.3 · reason UNSUPPORTED_TYPE · public "TLV codec cannot encode this type"

Generated from docs/api by tools/genindex.

Documentation

Overview

Package tlv registers the TLV 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/tlv"

The codec is the SDK's self-describing Type-Length-Value binary: every value carries its kind and its length, so a document decodes without a schema, into a typed target or into an interface. Structs, maps, slices and the scalar kinds are written by reflection. Input is bounded in size and depth. 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.22.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeMarshalFailed    0.3.22.1  the value could not be encoded, or the writer failed
CodeUnmarshalFailed  0.3.22.2  a malformed record, a type mismatch, or the reader failed
CodeUnsupportedType  0.3.22.3  a channel, a function, a complex number, an unsafe pointer
CodeDepthExceeded    0.3.22.4  nesting past 32 levels
CodeSizeExceeded     0.3.22.5  an input past 10 MiB
CodeTruncated        0.3.22.6  the input ends inside a record

No error message quotes the input.

Index

Constants

View Source
const (
	// CodeMarshalFailed is 0.3.22.1: the value could not be encoded, or the
	// writer failed.
	CodeMarshalFailed errs.Code = coretlv.CodeTLVMarshalFailed
	// CodeUnmarshalFailed is 0.3.22.2: a malformed record, a type mismatch, or
	// the reader failed.
	CodeUnmarshalFailed errs.Code = coretlv.CodeTLVUnmarshalFailed
	// CodeUnsupportedType is 0.3.22.3: a channel, a function, a complex
	// number, an unsafe pointer.
	CodeUnsupportedType errs.Code = coretlv.CodeTLVUnsupportedType
	// CodeDepthExceeded is 0.3.22.4: nesting past 32 levels.
	CodeDepthExceeded errs.Code = coretlv.CodeTLVDepthExceeded
	// CodeSizeExceeded is 0.3.22.5: an input past 10 MiB.
	CodeSizeExceeded errs.Code = coretlv.CodeTLVSizeExceeded
	// CodeTruncated is 0.3.22.6: the input ends inside a record.
	CodeTruncated errs.Code = coretlv.CodeTLVTruncated
)

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

View Source
const Format = "tlv"

Format is the name TLV 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 = coretlv.MarshalFailed
	// UnmarshalFailed is the sentinel of [CodeUnmarshalFailed].
	UnmarshalFailed = coretlv.UnmarshalFailed
	// UnsupportedType is the sentinel of [CodeUnsupportedType].
	UnsupportedType = coretlv.UnsupportedType
	// DepthExceeded is the sentinel of [CodeDepthExceeded].
	DepthExceeded = coretlv.DepthExceeded
	// SizeExceeded is the sentinel of [CodeSizeExceeded].
	SizeExceeded = coretlv.SizeExceeded
	// Truncated is the sentinel of [CodeTruncated].
	Truncated = coretlv.Truncated
)

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

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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