nativewire

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CommandFlagOmitResultIDs asks mutation responses to omit result ID vectors
	// when the command can otherwise report success through response_meta.
	CommandFlagOmitResultIDs uint64 = 1 << iota
	// CommandFlagOmitResponseMeta asks success responses to omit response_meta
	// when the client only needs success/error signaling.
	CommandFlagOmitResponseMeta
)
View Source
const (
	DeterministicEntryMagic   = "TDC1"
	DeterministicEntryVersion = uint64(1)
)
View Source
const (
	Magic             = "TDB1"
	ProtocolMajorV1   = uint16(1)
	ProtocolMinorV0   = uint16(0)
	FrameHeaderLenV1  = uint16(40)
	MaxFrameHeaderLen = FrameHeaderLenV1
)
View Source
const (
	CommandSpecificSectionStart SectionID = 100
	SectionFlagCritical         uint64    = 1
)
View Source
const MaxErrorCode = errCodeSentinel - 1

MaxErrorCode is the highest native-wire error code currently assigned by this protocol version.

Variables

This section is empty.

Functions

func AppendByteVector

func AppendByteVector(dst []byte, items ...[]byte) []byte

func AppendByteVectorPayload

func AppendByteVectorPayload(dst []byte, lengths []int, payload []byte) ([]byte, error)

func AppendByteVectorWithEncodedLen

func AppendByteVectorWithEncodedLen(dst []byte, encodedLen int, items ...[]byte) []byte

func AppendCommandHeader

func AppendCommandHeader(dst []byte, h CommandHeader) []byte

func AppendDeterministicEntry

func AppendDeterministicEntry(dst []byte, cmd ValidatedCommand) ([]byte, error)

AppendDeterministicEntry appends a canonical replicated command entry using default limits. On error it returns dst truncated to its original length.

func AppendDeterministicEntryWithLimits

func AppendDeterministicEntryWithLimits(dst []byte, cmd ValidatedCommand, limits Limits) ([]byte, error)

AppendDeterministicEntryWithLimits appends a canonical replicated command entry while validating deterministic payloads against caller-provided limits. On error it returns dst truncated to its original length.

func AppendHeader

func AppendHeader(dst []byte, h Header) ([]byte, error)

func AppendSection

func AppendSection(dst []byte, s Section) ([]byte, error)

func AppendSectionHeader

func AppendSectionHeader(dst []byte, id SectionID, flags uint64, sectionLen int) ([]byte, error)

func ByteVectorEncodedLen

func ByteVectorEncodedLen(items [][]byte) int

func ByteVectorPayloadEncodedLen

func ByteVectorPayloadEncodedLen(lengths []int, payloadLen int) (int, error)

func DecodeByteVectorItems

func DecodeByteVectorItems(src []byte, limits Limits) ([][]byte, error)

DecodeByteVectorItems decodes a byte-vector into item slices that borrow from src. It avoids offset/length table allocation for callers that only need a transient [][]byte view.

func DecodeByteVectorItemsInto

func DecodeByteVectorItemsInto(dst [][]byte, src []byte, limits Limits) ([][]byte, error)

DecodeByteVectorItemsInto decodes a byte-vector into dst[:count] item slices that borrow from src. It avoids offset/length table allocation for callers that only need a transient [][]byte view.

func DeterministicCommandFlags

func DeterministicCommandFlags(flags uint64) uint64

func DeterministicEntryDigest

func DeterministicEntryDigest(entry []byte) [32]byte

DeterministicEntryDigest returns the SHA-256 digest of canonical deterministic entry bytes.

func SectionEncodedLen

func SectionEncodedLen(s Section) int

func SectionHeaderEncodedLen

func SectionHeaderEncodedLen(id SectionID, flags uint64, sectionLen int) int

func UnsupportedDeterministicCommandFlags

func UnsupportedDeterministicCommandFlags(flags uint64) uint64

func ValidateHeaderVersion

func ValidateHeaderVersion(h Header, selected Version) error

Types

type AckPolicy

type AckPolicy uint64
const (
	AckVisible       AckPolicy = 1
	AckFlushed       AckPolicy = 2
	AckSynced        AckPolicy = 3
	AckRaftCommitted AckPolicy = 4
)

type ByteVector

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

func DecodeByteVector

func DecodeByteVector(src []byte, limits Limits) (ByteVector, error)

func DecodeByteVectorInto

func DecodeByteVectorInto(src []byte, limits Limits, scratch *ByteVectorScratch) (ByteVector, error)

DecodeByteVectorInto decodes a byte-vector using reusable buffers when scratch is non-nil. The returned vector borrows from src and scratch.

func (ByteVector) Item

func (v ByteVector) Item(i int) ([]byte, bool)

func (ByteVector) Len

func (v ByteVector) Len() int

type ByteVectorScratch

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

ByteVectorScratch carries reusable decode buffers for DecodeByteVectorInto.

type CommandHeader

type CommandHeader struct {
	ID      CommandID
	Version uint64
	Flags   uint64
}

func DecodeCommandHeader

func DecodeCommandHeader(src []byte) (CommandHeader, error)

type CommandID

type CommandID uint64
const (
	CommandCreateCollection CommandID = 10
	CommandListCollections  CommandID = 11
	CommandCreateIndex      CommandID = 12
	CommandListIndexes      CommandID = 13
	CommandDropIndex        CommandID = 14
	CommandOpenCollection   CommandID = 15
	CommandCloseCollection  CommandID = 16
	CommandDropCollection   CommandID = 17

	CommandInsertBatch     CommandID = 30
	CommandReplaceBatch    CommandID = 31
	CommandDeleteBatch     CommandID = 32
	CommandFlushCollection CommandID = 33
	CommandFlushAll        CommandID = 34
	CommandCheckpoint      CommandID = 35
	CommandUpdateBSONSet   CommandID = 36

	CommandGetMany     CommandID = 50
	CommandIndexLookup CommandID = 51
	CommandIndexRange  CommandID = 52
	CommandOpenScan    CommandID = 53
	CommandCursorNext  CommandID = 54
	CommandCursorClose CommandID = 55
	CommandExplain     CommandID = 56
	CommandStats       CommandID = 57
)

type CommandKind

type CommandKind uint8
const (
	CommandKindControl CommandKind = iota + 1
	CommandKindMutation
	CommandKindRead
)

type CommandSchema

type CommandSchema struct {
	ID                   CommandID
	Version              uint64
	Name                 string
	Kind                 CommandKind
	AllowedCommandFlags  uint64
	Replicated           bool
	LocalOnly            bool
	RequiresIdempotency  bool
	RequiresCatalogGuard bool
	BenchmarkRequired    bool
	Sections             []SectionRule
	// contains filtered or unexported fields
}

type CommandScratch

type CommandScratch struct {
	Known   []Section
	Ignored []Section
	// contains filtered or unexported fields
}

CommandScratch carries reusable buffers for command-schema validation.

type ConsistencyPolicy

type ConsistencyPolicy uint64
const (
	ConsistencyLocalStale   ConsistencyPolicy = 1
	ConsistencyLeaderRead   ConsistencyPolicy = 2
	ConsistencyLinearizable ConsistencyPolicy = 3
	ConsistencyLeaseRead    ConsistencyPolicy = 4
)

type DeterministicEntry

type DeterministicEntry struct {
	Version        uint64
	CommandID      CommandID
	CommandVersion uint64
	CommandFlags   uint64
	Sections       []Section
}

func DecodeDeterministicEntry

func DecodeDeterministicEntry(src []byte, limits Limits) (DeterministicEntry, error)

func DecodeDeterministicEntryInto

func DecodeDeterministicEntryInto(src []byte, limits Limits, scratch *DeterministicEntryScratch) (DeterministicEntry, error)

DecodeDeterministicEntryInto decodes a deterministic command-entry envelope.

The returned section payloads borrow from src and the section slice may borrow from scratch. Callers that need to retain the entry after reusing src or scratch must copy it.

func DecodeDeterministicEntryIntoWithRegistry

func DecodeDeterministicEntryIntoWithRegistry(src []byte, limits Limits, scratch *DeterministicEntryScratch, registry *Registry) (DeterministicEntry, error)

DecodeDeterministicEntryIntoWithRegistry is DecodeDeterministicEntryInto with caller-supplied command registry validation. A nil registry uses the v1 native-wire registry.

func DecodeDeterministicEntryWithRegistry

func DecodeDeterministicEntryWithRegistry(src []byte, limits Limits, registry *Registry) (DeterministicEntry, error)

DecodeDeterministicEntryWithRegistry decodes a deterministic command-entry envelope using registry for command validation. A nil registry uses the v1 native-wire registry.

type DeterministicEntryScratch

type DeterministicEntryScratch struct {
	Sections []Section
}

DeterministicEntryScratch carries reusable buffers for DecodeDeterministicEntryInto.

type DocumentFormat

type DocumentFormat uint64
const (
	DocumentFormatDefault    DocumentFormat = 0
	DocumentFormatJSON       DocumentFormat = 1
	DocumentFormatBSON       DocumentFormat = 2
	DocumentFormatTemplateV1 DocumentFormat = 3
)

type ErrorCode

type ErrorCode uint64
const (
	ErrMalformedFrame ErrorCode = iota + 1
	ErrUnsupportedVersion
	ErrUnsupportedFeature
	ErrAuthRequired
	ErrPermissionDenied
	ErrInvalidCommand
	ErrCollectionNotFound
	ErrIndexNotFound
	ErrDuplicateDocumentID
	ErrDocumentExists
	ErrUniqueIndexConflict
	ErrCatalogVersionMismatch
	ErrReadOnly
	ErrTimeout
	ErrCanceled
	ErrResourceExhausted
	ErrInternal
	ErrDurabilityUnavailable
	ErrConsistencyUnavailable
	ErrCursorNotFound
	ErrCatalogChanged
	ErrIdempotencyConflict
	ErrCommitAmbiguous
)

func ErrorCodeOf

func ErrorCodeOf(err error) (ErrorCode, bool)

type FrameType

type FrameType uint16
const (
	FrameHello FrameType = iota + 1
	FrameHelloOK
	FrameRequest
	FrameResponse
	FrameData
	FrameError
	FrameCancel
	FramePing
	FramePong
	FrameGoaway
)
type Header struct {
	Version   Version
	Type      FrameType
	Flags     uint32
	StreamID  uint64
	RequestID uint64
	BodyLen   uint64
}

func DecodeHeader

func DecodeHeader(src []byte, limits Limits) (Header, error)

type Limits

type Limits struct {
	MaxFrameSize                       uint64
	MaxHeaderLen                       uint16
	MaxSections                        int
	MaxSectionLen                      uint64
	MaxByteVectorItems                 int
	MaxByteVectorBytes                 uint64
	MaxDeterministicOpaquePayloadBytes uint64
	MaxDeterministicNameBytes          uint64
}

func DefaultLimits

func DefaultLimits() Limits

type ProtocolError

type ProtocolError struct {
	Code   ErrorCode
	Reason string
}

func (*ProtocolError) Error

func (e *ProtocolError) Error() string

type Registry

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

func MustV1Registry

func MustV1Registry() *Registry

func NewRegistry

func NewRegistry(commands ...CommandSchema) (*Registry, error)

func (*Registry) LookupCommand

func (r *Registry) LookupCommand(id CommandID, version uint64) (*CommandSchema, bool)

func (*Registry) Schemas

func (r *Registry) Schemas() []CommandSchema

func (*Registry) ValidateRequestSections

func (r *Registry) ValidateRequestSections(sections []Section) (ValidatedCommand, error)

func (*Registry) ValidateRequestSectionsInto

func (r *Registry) ValidateRequestSectionsInto(sections []Section, scratch *CommandScratch) (ValidatedCommand, error)

ValidateRequestSectionsInto validates sections using scratch when provided.

The returned command borrows section slices from sections and scratch. Callers may reuse scratch after they are done with the validated command view.

type Section

type Section struct {
	ID    SectionID
	Flags uint64
	Bytes []byte
}

func DecodeSections

func DecodeSections(src []byte, limits Limits) ([]Section, error)

func DecodeSectionsInto

func DecodeSectionsInto(dst []Section, src []byte, limits Limits) ([]Section, error)

DecodeSectionsInto decodes section envelopes, reusing dst[:0] when capacity allows and allocating a larger backing array when needed.

The returned sections borrow from src. Callers may reuse dst after they are done with the decoded section view. Callers that want reuse across calls must retain the returned slice; a grow will not update the caller's dst variable.

func (Section) Critical

func (s Section) Critical() bool

type SectionID

type SectionID uint64
const (
	SectionCommandHeader     SectionID = 1
	SectionError             SectionID = 2
	SectionCapabilitySet     SectionID = 3
	SectionDeadline          SectionID = 4
	SectionTraceContext      SectionID = 5
	SectionAckPolicy         SectionID = 6
	SectionConsistencyPolicy SectionID = 7
	SectionIdempotencyKey    SectionID = 8
	SectionChecksum          SectionID = 9
	SectionCompression       SectionID = 10
	SectionResponseMeta      SectionID = 11
	SectionCursorMeta        SectionID = 12
)
const (
	SectionCollectionRef          SectionID = 100
	SectionDocumentFormat         SectionID = 101
	SectionDocumentIDs            SectionID = 102
	SectionDocuments              SectionID = 103
	SectionTemplateRecords        SectionID = 104
	SectionExpectedCatalogVersion SectionID = 105
	SectionReplacementMode        SectionID = 106
	SectionCollectionMeta         SectionID = 107
	SectionIndexDefinition        SectionID = 108
	SectionIndexName              SectionID = 109
	SectionCollectionHandle       SectionID = 110
	SectionIndexValue             SectionID = 111
	SectionIndexLowerBound        SectionID = 112
	SectionIndexUpperBound        SectionID = 113
	SectionCursorRef              SectionID = 114
	SectionCursorLimits           SectionID = 115
	SectionPresenceBitmap         SectionID = 116
	SectionTruncated              SectionID = 117
	SectionUpdateFieldNames       SectionID = 121
	SectionUpdateFieldValues      SectionID = 122
)

type SectionRule

type SectionRule struct {
	ID            SectionID
	Name          string
	Required      bool
	Repeatable    bool
	Ordered       bool
	Deterministic bool
}

type ValidatedCommand

type ValidatedCommand struct {
	Header  CommandHeader
	Schema  *CommandSchema
	Known   []Section
	Ignored []Section
}

type Version

type Version struct {
	Major uint16
	Minor uint16
}

Jump to

Keyboard shortcuts

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