flatbuffers

package
v0.19.7 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package flatbuffers implements a thin passthrough codec for already-encoded FlatBuffer payloads. The universal Codec contract speaks `any`, but FlatBuffers is a schema-driven format whose typed access lives in caller code (generated by `flatc`). This package therefore registers a codec that round-trips raw FlatBuffer bytes — Marshal hands back the buffer the caller already has; Unmarshal publishes the buffer to the caller's target without parsing it. Real schema-typed reads stay in the caller's generated accessors.

The codec uses no third-party dependency. The only validation is the 4-byte root-offset header required by the FlatBuffers wire format.

Package flatbuffers — small adapter interfaces that let strongly-typed FlatBuffers wrappers participate in the universal codec contract without reaching into schema-generated structs from this package.

Index

Constants

View Source
const PromotionMagic uint32 = 0x80000001

PromotionMagic is the synthetic little-endian uint32 header stamped by the facade promotion path in pkg/v1/data/codec/promote.go when it wraps a non-FlatBuffer value in flatbuffers-shaped bytes. 0x80000001 is a deliberately invalid root offset (a real root offset points INTO the buffer, never past it AND never the high bit set), so a flatc- generated reader fails predictably on these bytes — only the SDK itself recognises and unwraps them.

Exported so promote.go can stamp the same value without a duplicated magic-number constant.

Variables

View Source
var (
	//: register the singleton and expose it as a typed package var.
	Codec codec.Codec = codec.Register(&flatbuffersCodec{})
)

Package-level state: the codec singleton plus the hoisted MIME / extension tables.

Functions

func New

func New() codec.Codec

New returns the FlatBuffers passthrough codec singleton.

Types

type BytesAcceptor

type BytesAcceptor interface {
	SetBytes(data []byte)
}

BytesAcceptor is the optional sink interface an Unmarshal target may satisfy to receive the decoded FlatBuffer payload. The codec passes the caller's data slice by reference; implementations that need ownership MUST copy the slice themselves.

type BytesProvider

type BytesProvider interface {
	Bytes() []byte
}

BytesProvider is the optional source interface a Marshal argument may satisfy to hand the codec its already-encoded FlatBuffer payload. The returned slice MUST remain valid for the lifetime of the codec call; the codec performs no copy and treats the buffer as read-only.

`Provider`/`Acceptor` suffixes are registered as legitimate adapter-role vocabulary in `/workspace/.ktn-linter.yaml` (per kodflow/ktn-linter#337), so `KTN-INTERFACE-ERNAME` does not fire here.

Jump to

Keyboard shortcuts

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