Documentation
¶
Overview ¶
Package omnibuf implements the OmniBuf high-throughput binary wire format.
It supports three usage modes in Go:
- Plain Go structs annotated with `omnibuf:"<fieldNum>[,name=<name>][,wire=<wireType>][,omitempty]"`
- Existing protoc-gen-go generated structs (*pb.Message) and dynamicpb.Message via Marshal and Unmarshal
- Generated single-pass codecs and Opaque zero-decode lazy readers via protoc-gen-omnibuf (using github.com/sudorandom/omnibuf/wire)
Index ¶
- Constants
- func DecodeBlind(packet []byte) (map[string]any, error)
- func Marshal(v any) ([]byte, error)
- func MarshalAppend(dst []byte, v any) ([]byte, error)
- func MarshalDeterministic(v any) ([]byte, error)
- func Unmarshal(packet []byte, v any) error
- func UnmarshalZeroCopy(packet []byte, v any) error
- type MarshalOptions
- type SchemaMeta
Constants ¶
const MaxNestingDepth = 32
MaxNestingDepth is the maximum allowed sub-message / array nesting depth (prevents stack-overflow bombs).
Variables ¶
This section is empty.
Functions ¶
func DecodeBlind ¶
DecodeBlind decodes any OmniBuf packet without a compile-time schema. If Field #0 (Tag = 0x0B, wireSubMsg = 5, omnibuf.v1.SchemaMeta) is present, its field names (and any nested children schemas) are used to decode human-readable keys. Otherwise, synthetic field names ("field_1", "field_2", ...) are used.
func Marshal ¶
Marshal encodes any struct pointer (including plain Go structs with `omnibuf:"..."` tags and existing *pb.PeerUpdate protoc-gen-go structs) into a newly allocated OmniBuf packet.
func MarshalAppend ¶
MarshalAppend appends the OmniBuf encoding of struct pointer v to dst[:0] using the cached unsafe-offset table codec (0 reflection allocations on the hot path).
func MarshalDeterministic ¶
MarshalDeterministic encodes any struct pointer or protoreflect.Message with deterministic wireMap key ordering.
func Unmarshal ¶
Unmarshal decodes an OmniBuf packet into any struct pointer v (including *pb.PeerUpdate) using safe heap-allocated strings.
func UnmarshalZeroCopy ¶
UnmarshalZeroCopy decodes an OmniBuf packet into any struct pointer v using zero-copy unsafe.String references into packet.
Types ¶
type MarshalOptions ¶
type MarshalOptions struct {
// Deterministic sorts wireMap keys in ascending order so identical messages
// always produce byte-for-byte identical wire output (useful for golden files,
// reproducible builds, and content-addressable hashing).
Deterministic bool
// SelfDescribing emits Field #0 (Tag = 0x0B, wireSubMsg = 5, omnibuf.v1.SchemaMeta)
// at byte 0 of the root message with field names and nested children schemas.
SelfDescribing bool
}
MarshalOptions configures OmniBuf wire encoding.
func (MarshalOptions) Marshal ¶
func (o MarshalOptions) Marshal(v any) ([]byte, error)
Marshal encodes v (any struct pointer or protoreflect.Message) using the configured options.
func (MarshalOptions) MarshalAppend ¶
func (o MarshalOptions) MarshalAppend(dst []byte, v any) ([]byte, error)
MarshalAppend appends the OmniBuf encoding of v to dst[:0] using the configured options.
type SchemaMeta ¶
type SchemaMeta struct {
TypeName string `protobuf:"bytes,1,opt,name=type_name,proto3" json:"type_name,omitempty"`
Fields map[uint32]string `protobuf:"bytes,2,rep,name=fields,proto3" json:"fields,omitempty"`
Children map[uint32]*SchemaMeta `protobuf:"bytes,3,rep,name=children,proto3" json:"children,omitempty"`
}
SchemaMeta is the optional inline schema header encoded as Field #0 (Tag = 0x0B, wireSubMsg = 5) at byte 0 of an OmniBuf message (omnibuf.v1.SchemaMeta).
func ReadField0SchemaMeta ¶
func ReadField0SchemaMeta(packet []byte) (*SchemaMeta, bool)
ReadField0SchemaMeta decodes and merges all Field #0 (Tag = 0x0B, wireSubMsg = 5) SchemaMeta blocks in packet.
func (*SchemaMeta) AppendField0 ¶ added in v0.0.2
func (meta *SchemaMeta) AppendField0(dst []byte, deterministic bool) []byte
AppendField0 appends Field #0 (Tag = 0x0B, wireSubMsg = 5) encoding meta to dst. When deterministic is true, map keys in Fields and Children are sorted in ascending order.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
conformance-go
command
Command conformance-go is the Go implementation's adapter binary for the OmniBuf conformance test runner.
|
Command conformance-go is the Go implementation's adapter binary for the OmniBuf conformance test runner. |
|
conformance-runner
command
Command conformance-runner executes the language-independent OmniBuf conformance test suite against a target language adapter binary over length-prefixed stdin/stdout frames (modeled after Protobuf's conformance-test-runner).
|
Command conformance-runner executes the language-independent OmniBuf conformance test suite against a target language adapter binary over length-prefixed stdin/stdout frames (modeled after Protobuf's conformance-test-runner). |
|
omnibuf
command
|
|
|
protoc-gen-omnibuf
command
|
|
|
internal
|
|
|
conformance
Package conformance implements the language-independent OmniBuf conformance test protocol (modeled after Protocol Buffers' conformance_test_runner) where a runner binary communicates with a language-specific adapter binary over length-prefixed stdin/stdout frames.
|
Package conformance implements the language-independent OmniBuf conformance test protocol (modeled after Protocol Buffers' conformance_test_runner) where a runner binary communicates with a language-specific adapter binary over length-prefixed stdin/stdout frames. |
|
pb
Code generated for omnibuf/bench/peer.proto.
|
Code generated for omnibuf/bench/peer.proto. |
|
Package wire provides low-level OmniBuf wire format primitives, O(1) zero-decode field hoppers, the streaming Encoder, and runtime helpers for protoc-gen-omnibuf.
|
Package wire provides low-level OmniBuf wire format primitives, O(1) zero-decode field hoppers, the streaming Encoder, and runtime helpers for protoc-gen-omnibuf. |