dynamic

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package dynamic contains the implementation of hyperpb's dynamic message types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetField

func GetField[T any](m *Message, offset tdp.Offset) *T

GetField returns the field pointer for a given message.

Returns nil if the field is cold and there is no cold region allocated.

func LoadField

func LoadField[T any](m *Message, offset tdp.Offset) T

LoadField returns the field data for a given message.

Returns nil if the field is cold and there is no cold region allocated.

Types

type Cold

type Cold struct {
	Unknown slice.Slice[zc.Range] // Unknown field chunks.
}

Cold is portions of a message that are located in context.Cold.

type Message

type Message struct {
	Shared     *Shared
	TypeOffset uint32

	// Index into context.cold; negative means no cold pointer.
	// Exported for open-coding in the parser.
	ColdIndex int32
	// contains filtered or unexported fields
}

Message is a dynamic message value.

A *Message lives on some arena, and all of its submessages do too. Because arenas are designed such that if a pointer to any of its allocated data is reachable, the whole arena is reachable, simply holding a *Message into the arena will keep everything else alive.

This means that *Message values not being directly operated on by the application do not need to be marked by the GC, because their memory already gets marked whenever the GC sweeps a *root. As such, all of the fields of a Message are laid out in memory that follows it.

func (*Message) Cold

func (m *Message) Cold() *Cold

cold returns a pointer to the cold region, or nil if it hasn't been allocated.

func (*Message) Dump

func (m *Message) Dump() string

Dump dumps the internal state of a message.

func (*Message) Get

Get retrieves the value for a field.

func (*Message) GetBit

func (m *Message) GetBit(n uint32) bool

GetBit gets the value of the nth bit from this message's bitset.

func (*Message) GetByIndexUnchecked

func (m *Message) GetByIndexUnchecked(n int) protoreflect.Value

GetByIndex is like Message.Get, but it takes a raw field index, performing no bounds checks.

func (*Message) Has

Has reports whether a field is populated.

func (*Message) MutableCold

func (m *Message) MutableCold() *Cold

MutableCold returns a pointer to the cold region, allocating one if needed.

func (*Message) ProtoReflect

func (m *Message) ProtoReflect() protoreflect.Message

ProtoReflect is a callback to construct the root package's message type.

It is connected to the root package via linkname.

func (*Message) Range

func (m *Message) Range(yield func(protoreflect.FieldDescriptor, protoreflect.Value) bool)

Range iterates over every populated field.

func (*Message) SetBit

func (m *Message) SetBit(n uint32, flag bool)

StBit sets the value of the nth bit from this message's bitset.

func (*Message) Type

func (m *Message) Type() *tdp.Type

Type returns this message's type.

type Shared

type Shared struct {
	Src *byte
	Len int

	// Synchronizes calls to startParse() with this context.
	Lock sync.Mutex

	// Off-arena memory which holds arena pointers to "Cold" parts of a message.
	Cold []*Cold
	// contains filtered or unexported fields
}

Shared is state that is shared by all messages in a particular tree of messages.

A zero Shared is ready to use.

func (*Shared) Arena

func (s *Shared) Arena() *arena.Arena

Arena returns the message tree's arena.

func (*Shared) Free

func (s *Shared) Free()

Free releases any resources held by this context, allowing them to be re-used.

Any messages previously parsed using this context must not be reused.

func (*Shared) Library

func (s *Shared) Library() *tdp.Library

Library returns the message tree's library.

func (*Shared) New

func (s *Shared) New(ty *tdp.Type) *Message

New allocates a new message in this context.

Jump to

Keyboard shortcuts

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