inlinedtree

package
v0.0.0-...-d93761d Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build[
	TParentMessage any,
	TMetadata model_core.ReferenceMetadata,
	TParentMessagePtr interface {
		*TParentMessage
		proto.Message
	},
](
	candidates CandidateList[TParentMessagePtr, TMetadata],
	options *Options,
) (model_core.PatchedMessage[TParentMessagePtr, TMetadata], error)

Build a Protobuf message that contains data, either inlined into the message directly or stored in the form of a reference to a separate object.

Data to be inlined needs to be provided in the form of candidates. For each candidate, a function needs to be provided that can either inline the data into the message or emit a reference to it. These functions are eventually applied in the same order in which they are provided, meaning that the order in which items are appended to lists is preserved.

This function selects candidates to inline based on their height or size. It initially attempts to keep the height of the resulting message minimal, followed by inlining as many candidates as possible to fill up the remaining space.

Types

type Candidate

type Candidate[TParentMessage any, TMetadata model_core.ReferenceMetadata] struct {
	// Message to store in a child object if no space is present to
	// inline it into the parent object.
	ExternalMessage model_core.PatchedMessage[proto.Message, TMetadata]
	// Function to invoke to either inline the message into the
	// output, or create a reference to the child object.
	ParentAppender ParentAppender[TParentMessage, TMetadata]
}

Candidate of data that needs to be stored in a message, but can optionally be stored in a child object if no space is present.

type CandidateList

type CandidateList[TParentMessage any, TMetadata model_core.ReferenceMetadata] []Candidate[TParentMessage, TMetadata]

CandidateList is a list of candidates that may be inlined into message generated by Build, or stored separately.

func (*CandidateList[TParentMessage, TMetadata]) Discard

func (cl *CandidateList[TParentMessage, TMetadata]) Discard()

type Options

type Options struct {
	ReferenceFormat  object.ReferenceFormat
	Encoder          encoding.BinaryEncoder
	MaximumSizeBytes int
}

Options used by the Build function.

type ParentAppender

type ParentAppender[TParentMessage any, TMetadata model_core.ReferenceMetadata] func(
	parent model_core.PatchedMessage[TParentMessage, TMetadata],
	externalContents *object.Contents,
	externalMetadata []TMetadata,
)

ParentAppender is invoked to append the data to be stored in the parent message. If externalContents is not nil, the data is about to be stored in an external message. If externalMessage is nil, the data may be inlined.

This function may be invoked multiple times to determine how the size of the parent object is affected by either inlining the data or storing it externally.

Jump to

Keyboard shortcuts

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