Documentation
¶
Index ¶
- func Build[TParentMessage any, TMetadata model_core.ReferenceMetadata, ...](candidates CandidateList[TParentMessagePtr, TMetadata], options *Options) (model_core.PatchedMessage[TParentMessagePtr, TMetadata], error)
- type Candidate
- type CandidateList
- type CapturedParentAppender
- type Options
- type ParentAppender
- type ParentAppenderForTesting
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[encoding.BinaryMarshaler, TMetadata] // Encoder to use when storing ExternalMessage in a child object. Encoder model_encoding.DeterministicBinaryEncoder // 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.
func AlwaysInline ¶
func AlwaysInline[TParentMessage any, TMetadata model_core.ReferenceMetadata]( patcher *model_core.ReferenceMessagePatcher[TMetadata], parentAppender func(parent model_core.PatchedMessage[TParentMessage, TMetadata]), ) Candidate[TParentMessage, TMetadata]
AlwaysInline creates a simple Candidate that always inlines data into the parent message. This can be used to set message fields that have no way of getting stored in an external object.
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()
Discard any state associated with all candidates. This ensures that if a call to Build() fails, any files/resources owned by the metadata gets released.
type CapturedParentAppender ¶
type CapturedParentAppender[TParentMessage any, TMetadata model_core.ReferenceMetadata] func( parent model_core.PatchedMessage[TParentMessage, TMetadata], externalObject *model_core.Decodable[model_core.MetadataEntry[TMetadata]], )
CapturedParentAppender is a simplified version of ParentAppender that receives an already captured object, as opposed to receiving the literal contents of the created object. This is sufficient for most candidates.
type Options ¶
type Options struct {
ReferenceFormat object.ReferenceFormat
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], externalObject *model_core.Decodable[model_core.CreatedObject[TMetadata]], ) error
ParentAppender is invoked to append the data to be stored in the parent message. If externalObject is set, the data is about to be stored in an external message. If externalObject is not set, 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.
func Capturing ¶
func Capturing[TParentMessage any, TMetadata model_core.ReferenceMetadata]( ctx context.Context, capturer model_core.CreatedObjectCapturer[TMetadata], appender CapturedParentAppender[TParentMessage, TMetadata], ) ParentAppender[TParentMessage, TMetadata]
Capturing converts a CapturedParentAppender to a plain ParentAppender.
type ParentAppenderForTesting ¶
type ParentAppenderForTesting ParentAppender[*model_filesystem_pb.DirectoryContents, model_core.ReferenceMetadata]
ParentAppenderForTesting is an instantiation of ParentAppender for generating mocks to be used by tests.