baseproto

package module
v0.0.0-...-ecb2b82 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 5 Imported by: 0

README

baseProto: Flat Binary Protocol

baseProto is a flat binary protocol optimized for almost zero allocations.

  • baseProto is a flat binary format.
  • baseRPC is an RPC protocol with bidirectional-streaming and nested subservices.
  • baseMTP is a message transfer protocol with channel multiplexing.

The protocol includes an IDL and a baseprotoc code generator.


© 2021-2026 Ivan Korobkov

Documentation

Index

Constants

View Source
const (
	KindUndefined = format.KindUndefined

	KindBool  = format.KindBool
	KindTrue  = format.KindTrue
	KindFalse = format.KindFalse
	KindByte  = format.KindByte

	KindInt16 = format.KindInt16
	KindInt32 = format.KindInt32
	KindInt64 = format.KindInt64

	KindUint16 = format.KindUint16
	KindUint32 = format.KindUint32
	KindUint64 = format.KindUint64

	KindFloat32 = format.KindFloat32
	KindFloat64 = format.KindFloat64

	KindBin64  = format.KindBin64
	KindBin128 = format.KindBin128
	KindBin192 = format.KindBin192
	KindBin256 = format.KindBin256

	KindBytes  = format.KindBytes
	KindString = format.KindString

	KindList    = format.KindList
	KindListBig = format.KindListBig

	KindMessage    = format.KindMessage
	KindMessageBig = format.KindMessageBig

	KindStruct = format.KindStruct
)

Variables

View Source
var (
	EncodeBool = encode.EncodeBool
	EncodeByte = encode.EncodeByte

	EncodeBin64       = encode.EncodeBin64
	EncodeBin128      = encode.EncodeBin128
	EncodeBin128Bytes = encode.EncodeBin128Bytes
	EncodeBin192      = encode.EncodeBin192
	EncodeBin256      = encode.EncodeBin256

	EncodeBytes = encode.EncodeBytes

	EncodeFloat32 = encode.EncodeFloat32
	EncodeFloat64 = encode.EncodeFloat64

	EncodeInt16 = encode.EncodeInt16
	EncodeInt32 = encode.EncodeInt32
	EncodeInt64 = encode.EncodeInt64

	EncodeString = encode.EncodeString
	EncodeStruct = encode.EncodeStruct

	EncodeUint16 = encode.EncodeUint16
	EncodeUint32 = encode.EncodeUint32
	EncodeUint64 = encode.EncodeUint64
)
View Source
var (
	DecodeKind     = encode.DecodeKind
	DecodeKindSize = encode.DecodeKindSize

	DecodeBool = encode.DecodeBool
	DecodeByte = encode.DecodeByte

	DecodeBin64  = encode.DecodeBin64
	DecodeBin128 = encode.DecodeBin128
	DecodeBin192 = encode.DecodeBin192
	DecodeBin256 = encode.DecodeBin256

	DecodeBytes = encode.DecodeBytes

	DecodeFloat32 = encode.DecodeFloat32
	DecodeFloat64 = encode.DecodeFloat64

	DecodeInt16 = encode.DecodeInt16
	DecodeInt32 = encode.DecodeInt32
	DecodeInt64 = encode.DecodeInt64

	DecodeString      = encode.DecodeString
	DecodeStringClone = encode.DecodeStringClone

	DecodeStruct = encode.DecodeStruct

	DecodeUint16 = encode.DecodeUint16
	DecodeUint32 = encode.DecodeUint32
	DecodeUint64 = encode.DecodeUint64
)

Functions

func WriteField

func WriteField[T any](w writer.FieldWriter, value T, write writer.WriteFunc[T]) error

WriteField writes a generic field using the given encode function.

Types

type Bytes

type Bytes = format.Bytes

Bytes is a baseproto byte slice backed by a buffer. Clone it if you need to keep it around.

type FieldWriter

type FieldWriter = writer.FieldWriter

type GetFuncErr

type GetFuncErr[T any] = values.GetFuncErr[T]

GetFuncErr is a function type for decoding list elements.

type Kind

type Kind = format.Kind

Kind specifies a value kind.

type List

type List = values.List

List is a raw list of elements.

func GetList

func GetList(b []byte) List

GetList gets and returns a list from bytes, or an empty list on error. The method decodes the list table, but not the elements, see ParseList.

func GetListErr

func GetListErr(b []byte) (_ List, size int, err error)

GetListErr gets and returns a list from bytes, or an error. The method decodes the list table, but not the elements, see ParseList.

func ParseList

func ParseList(b []byte) (l List, size int, err error)

ParseList recursively parses and returns a list.

type ListWriter

type ListWriter = writer.ListWriter

ListWriter is a raw list writer.

func NewListWriter

func NewListWriter() ListWriter

NewListWriter returns a new list writer with a new empty buffer.

The writer is released on end.

func NewListWriterBuffer

func NewListWriterBuffer(buf buffer.Buffer) ListWriter

NewListWriterBuffer returns a new list writer with the given buffer.

The writer is freed on end.

type Message

type Message = values.Message

Message is a raw message.

func GetMessage

func GetMessage(b []byte) Message

GetMessage gets and returns a message from bytes, or an empty message on error. The method decodes the message table, but not the fields, see ParseMessage.

func GetMessageErr

func GetMessageErr(b []byte) (_ Message, size int, err error)

GetMessageErr gets and returns a message from bytes, or an error. The method decodes the message table, but not the fields, see ParseMessage.

func ParseMessage

func ParseMessage(b []byte) (_ Message, size int, err error)

ParseMessage recursively parses and returns a message.

type MessageListWriter

type MessageListWriter[T any] = writer.MessageListWriter[T]

MessageListWriter writes a list of messages.

func NewMessageListWriter

func NewMessageListWriter[T any](w ListWriter, next func(w MessageWriter) T) MessageListWriter[T]

NewMessageListWriter returns a new message list writer.

type MessageType

type MessageType = values.MessageType

MessageType is a type implemented by generated messages.

type MessageWriter

type MessageWriter = writer.MessageWriter

func NewMessageWriter

func NewMessageWriter() MessageWriter

NewMessageWriter returns a new message writer with a new empty buffer.

The writer is released on end.

func NewMessageWriterBuffer

func NewMessageWriterBuffer(buf buffer.Buffer) MessageWriter

NewMessageWriterBuffer returns a new message writer with the given buffer.

The writer is freed on end.

type ParseFuncErr

type ParseFuncErr[T any] = values.ParseFuncErr[T]

ParseFuncErr is a function type for parsing values.

type String

type String = format.String

String is a baseproto string backed by a buffer. Clone it if you need to keep it around.

type TypedList

type TypedList[T any] = values.TypedList[T]

TypedList is a typed list of elements.

func GetTypedList

func GetTypedList[T any](b []byte, get GetFuncErr[T]) TypedList[T]

GetTypedList gets and returns a value list, or an empty list on error.

func GetTypedListErr

func GetTypedListErr[T any](b []byte, get GetFuncErr[T]) (
	_ TypedList[T], size int, err error)

GetTypedListErr gets and returns a value list, or an error.

func NewTypedList

func NewTypedList[T any](list List, get GetFuncErr[T]) TypedList[T]

NewTypedList returns a new value list.

func ParseTypedList

func ParseTypedList[T any](b []byte, get GetFuncErr[T]) (
	_ TypedList[T], size int, err error)

ParseTypedList decodes, recursively validates and returns a list.

type Value

type Value = values.Value

Value is a raw binary value.

func GetValue

func GetValue(b []byte) Value

GetValue gets and returns a value from bytes, or nil on error.

The method only checks the type, but does not recursively parse the value. See ParseValue for recursive parsing.

func GetValueErr

func GetValueErr(b []byte) (Value, error)

GetValueErr gets and returns a value from bytes, or an error.

The method only checks the type, but does not recursively parse the value. See ParseValue for recursive parsing.

func ParseValue

func ParseValue(b []byte) (_ Value, n int, err error)

ParseValue recursively parses and returns a value.

type ValueListWriter

type ValueListWriter[T any] = writer.ValueListWriter[T]

ValueListWriter writes a list of primitive values.

func NewValueListWriter

func NewValueListWriter[T any](w ListWriter, write writer.WriteFunc[T]) (_ ValueListWriter[T])

NewValueListWriter returns a new value list writer.

type ValueWriter

type ValueWriter = writer.ValueWriter

func NewValueWriter

func NewValueWriter() ValueWriter

NewValueWriter returns a new value writer with a new empty buffer.

The writer is released on end.

func NewValueWriterBuffer

func NewValueWriterBuffer(buf buffer.Buffer) ValueWriter

NewValueWriterBuffer returns a new value writer with the given buffer.

The writer is freed on end.

type WriteFunc

type WriteFunc[T any] = writer.WriteFunc[T]

WriteFunc specifies a generic function to write a value directly into a buffer.

type Writer

type Writer = writer.Writer

Writer writes baseproto values.

func NewWriter

func NewWriter() Writer

NewWriter returns a new writer with a new empty buffer.

The writer must be freed manually.

func NewWriterBuffer

func NewWriterBuffer(buf buffer.Buffer) Writer

NewWriterBuffer returns a new writer with the given buffer.

The writer must be freed manually.

Directories

Path Synopsis
cmd
baseprotoc command
internal/parser
Code generated by goyacc -l -v grammar.out -o grammar.go grammar.y.
Code generated by goyacc -l -v grammar.out -o grammar.go grammar.y.
internal
proto

Jump to

Keyboard shortcuts

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