Documentation
¶
Overview ¶
Package tdp contains the "object file format" used by hyperpb's parser. "TDP" stands for "table-driven parser".
Subpackages of this package contain other components, like the parser and compiler.
All fields in this package are exported because they are assembled and accessed by other internal packages. None of the types in this file should ever be exposed to users, either directly or as the type of an interface.
Index ¶
Constants ¶
const SignBits = 0x80_80_80_80_80_80_80_80
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aux ¶
type Aux struct {
Layout debug.Value[TypeLayout]
Library *Library
Descriptor protoreflect.MessageDescriptor
Methods protoiface.Methods
FieldDescriptors []protoreflect.FieldDescriptor
// Field indices that are required or contain required fields.
// Negative numbers are the complement of a message field which
// might contain required fields.
Required []int32
}
Aux is data on a typeHeader that is stored behind a pointer and kept alive in the traces struct in [compiler.compile]. These rarely-accessed fields ensure that parser-relevant data is closer together in cache.
type Field ¶
type Field struct {
// The Message type for this field, if there is one.
Message *Type
Accessor
// contains filtered or unexported fields
}
Field is an optimized descriptor for a message field.
func (*Field) Format ¶
Format implements fmt.Formatter.
type FieldLayout ¶
type FieldLayout struct {
Size, Align, Bits, Padding uint32
Index int // Which field is this in the MessageDescriptor?
Offset Offset
}
FieldLayout is layout information for a [field]. Only for debugging.
type FieldParser ¶
type FieldParser struct {
// The expected, partially decoded Tag value for the field.
Tag Tag
// Byte offset to the typeParser this fieldParser uses, if any.
Message *TypeParser
// Field Offset information for the field this parser parses. Duplicated
// from [getter].
Offset Offset
// For non-singular fields, the default size to preallocate for this field.
Preload uint32
// The parser to jump to after this one, depending on whether the parse
// succeeds or fails.
NextOk, NextErr xunsafe.Addr[FieldParser]
// The thunk to call for this field. The type of this thunk is stored in
// the parser package.
Parse uintptr
// contains filtered or unexported fields
}
FieldParser is a parser for a single field.
func (*FieldParser) Format ¶
func (p *FieldParser) Format(s fmt.State, verb rune)
Format implements fmt.Formatter.
type Library ¶
type Library struct {
Base *Type
Types map[protoreflect.MessageDescriptor]*Type
Bytes int
// Used to store compilation metadata. Actually a []hyperpb.CompileOptions.
Metadata any
}
Library represents the full output of [Compile]. Given any Type, it can be used to obtain the Type for any other message type that was compiled as part of the same call to [Compile].
func (*Library) Type ¶
func (l *Library) Type(md protoreflect.MessageDescriptor) (*Type, bool)
Type returns the Type for the given descriptor in this library.
If not present, returns false.
type Offset ¶
type Offset struct {
// First Bit index for bits allocated to this field.
//
// If this is a oneof field, this is instead an offset into the
// oneof word table.
Bit uint32
// Byte offset within the containing message to the Data for this field.
//
// If negative, this is a cold field, and this is the negation of an offset
// into the cold field area.
Data int32
// This field's Number. Only used by oneof fields; all other fields have
// a zero here.
Number uint32
}
Offset is field offset information for a generated message type's field.
type Scalar ¶
type Scalar interface {
int32 | int64 |
uint32 | uint64 |
float32 | float64 |
protoreflect.EnumNumber | bool
}
Scalar is a Protobuf scalar type.
type Tag ¶
type Tag uint64
Tag is a specially-formatted tag for the parser.
The tag is formatted in the way it would be when encoded in a Protobuf message, but with the high bit of each byte cleared.
type Type ¶
type Type struct {
*Aux
// The number of bytes of memory that must be allocated for a *message of
// this type. This includes the Size of the header. Alignment is implicitly
// that of uint64.
Size, ColdSize uint32
// The "unspecialized" Parser for this type.
Parser *TypeParser
// Maps field Numbers to offsets in fields.
Numbers *swiss.Table[int32, uint32]
// The number of fields that follow this type, not including the special
// padding field with number equal to zero.
Count uint32
// contains filtered or unexported fields
}
func (*Type) ByDescriptor ¶
func (t *Type) ByDescriptor(fd protoreflect.FieldDescriptor) *Field
ByDescriptor returns the field with the given descriptor.
func (*Type) ByIndex ¶
byIndex returns the nth byIndex (in byIndex number order) for this type.
If n == 0 and this type has no fields, returns a byIndex with an invalid byIndex number.
This function does not perform bounds checks.
func (*Type) Format ¶
Format implements fmt.Formatter.
func (*Type) ProtoReflect ¶
func (t *Type) ProtoReflect() protoreflect.MessageType
ProtoReflect wraps this type for reflection.
type TypeLayout ¶
type TypeLayout struct {
BitWords int // Number of 32-bit words in the type.
Fields []FieldLayout // Sorted in offset order.
}
TypeLayout is layout information for a Type. Only for debugging.
type TypeParser ¶
type TypeParser struct {
// Maps offsets to field tags for the first 128 field tags. A value of
// -1 means that if there is a parser at that position, it is farther away
// than the first 256 fields.
TagLUT [128]uint8
TypeOffset uint32 // The type that this parser parses.
DiscardUnknown bool // Should unknown fields be kept?
// Maps field tags to offsets in fields.
Tags *swiss.Table[int32, uint32]
// If this is an ordinary parser, this is the parser for parsing this
// message as a "map entry"; that is, it will have a single field with
// number 2 that forwards to this parser.
MapEntry *TypeParser
Entrypoint FieldParser
// contains filtered or unexported fields
}
TypeParser is a parser for some Type. A Type may have multiple parsers.
func (*TypeParser) Fields ¶
func (p *TypeParser) Fields() *xunsafe.VLA[FieldParser]
Fields returns a raw pointer to this parser's field array.
func (*TypeParser) Format ¶
func (p *TypeParser) Format(s fmt.State, verb rune)
Format implements fmt.Formatter.
Directories
¶
| Path | Synopsis |
|---|---|
|
linker
Package linker provides a general-purpose in-memory linker, that is used to assemble the output buffer within the compiler.
|
Package linker provides a general-purpose in-memory linker, that is used to assemble the output buffer within the compiler. |
|
Package dynamic contains the implementation of hyperpb's dynamic message types.
|
Package dynamic contains the implementation of hyperpb's dynamic message types. |
|
Package maps contains shared layouts for maps field implementations, for sharing between the tdp packages and the gencode packages.
|
Package maps contains shared layouts for maps field implementations, for sharing between the tdp packages and the gencode packages. |
|
Package repeated contains shared layouts for repeated field implementations, for sharing between the tdp packages and the gencode packages.
|
Package repeated contains shared layouts for repeated field implementations, for sharing between the tdp packages and the gencode packages. |
|
Package thunks provides all thunks for the parser VM.
|
Package thunks provides all thunks for the parser VM. |
|
Package vm contains the core interpreter VM for the hyperpb parser.
|
Package vm contains the core interpreter VM for the hyperpb parser. |