Documentation
¶
Overview ¶
Package codec provides the tools for encoding and decoding Argo data. This file focuses on the ArgoDecoder, which is responsible for parsing Argo binary messages and reconstructing them into Go data structures, typically an ordered map representing a GraphQL ExecutionResult.
Index ¶
- type ArgoDecoder
- type ArgoEncoder
- func (ae *ArgoEncoder) GetResult() (*buf.Buf, error)
- func (ae *ArgoEncoder) Header() *header.Header
- func (ae *ArgoEncoder) Log(msg interface{})
- func (ae *ArgoEncoder) Track(path ast.Path, msg string, b buf.Write, value interface{})
- func (ae *ArgoEncoder) ValueToArgoWithType(v interface{}, wt wire.Type) error
- func (ae *ArgoEncoder) Write(blockDef wire.BlockType, valueWireType wire.Type, v interface{}) (*label.Label, error)
- type ArgoErrorLocation
- type ArgoErrorValue
- type MessageSlicer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgoDecoder ¶
type ArgoDecoder struct {
// contains filtered or unexported fields
}
ArgoDecoder decodes an Argo binary message into a Go data structure. It uses a MessageSlicer to access different parts of the Argo message (header, blocks, core) and maintains a map of block readers to efficiently decode block data.
func NewArgoDecoder ¶
func NewArgoDecoder(messageBuf buf.Read) (*ArgoDecoder, error)
NewArgoDecoder creates and initializes a new ArgoDecoder. messageBuf should contain the entire Argo message to be decoded. It returns an error if the message slicer cannot be initialized (e.g., due to header read issues).
func (*ArgoDecoder) ArgoToMap ¶
func (ad *ArgoDecoder) ArgoToMap(wt wire.Type) (*orderedmap.OrderedMap[string, interface{}], error)
ArgoToMap decodes the entire Argo message into an ordered map, which typically represents a GraphQL ExecutionResult. The wire.Type `wt` specifies the expected structure of the data. If the Argo message header indicates it is self-describing, the provided `wt` is overridden by `wire.Desc`.
type ArgoEncoder ¶
type ArgoEncoder struct {
// Debug fields, used when ArgoEncoder.Debug is true.
Debug bool // If true, enables tracking of encoding steps.
// contains filtered or unexported fields
}
ArgoEncoder handles the conversion of Go data structures, typically representing GraphQL query results, into the Argo binary message format. It manages a core buffer for labels and inline data, a collection of block writers for scalar values that are not inlined, and an Argo header. The encoder supports various Argo features like deduplication, different block types, and self-describing values, controlled by header flags and wire type definitions.
func NewArgoEncoder ¶
func NewArgoEncoder() *ArgoEncoder
NewArgoEncoder initializes and returns a new ArgoEncoder. It sets up the core buffer, the map for block writers, and a new Argo header.
func (*ArgoEncoder) GetResult ¶
func (ae *ArgoEncoder) GetResult() (*buf.Buf, error)
GetResult finalizes the encoding process. It assembles the Argo header, data from all block writers (if not inlining everything), and the core buffer data into a single, final *buf.Buf containing the complete Argo message.
func (*ArgoEncoder) Header ¶
func (ae *ArgoEncoder) Header() *header.Header
Header returns the encoder's *header.Header instance, allowing the caller to set Argo header flags or other header properties before finalizing the message.
func (*ArgoEncoder) Log ¶
func (ae *ArgoEncoder) Log(msg interface{})
Log provides a more generic logging mechanism for debugging, used when ae.Debug is true. It records the current position in the core buffer and a message or detailed object.
func (*ArgoEncoder) Track ¶
Track records an encoding step for debugging purposes if ae.Debug is true. It captures the GraphQL path, a descriptive message, the current buffer (if any), and the value being processed.
func (*ArgoEncoder) ValueToArgoWithType ¶
func (ae *ArgoEncoder) ValueToArgoWithType(v interface{}, wt wire.Type) error
ValueToArgoWithType is the primary entry point for encoding a Go data structure (typically from JSON-like input) into the Argo format based on a provided wire.Type schema. The `v` interface{} is expected to conform to the structure defined by `wt`. For example, if `wt` is a RecordType, `v` should be an *orderedmap.OrderedMap[string, interface{}]. If `wt` is an ArrayType, `v` should be a slice or array. Debugging information, if enabled, is written to "tmp-gowritelog.json".
func (*ArgoEncoder) Write ¶
func (ae *ArgoEncoder) Write(blockDef wire.BlockType, valueWireType wire.Type, v interface{}) (*label.Label, error)
Write is a core method for handling scalar values that are part of a block. It retrieves or creates the appropriate block writer for `blockDef`, writes the value `v` to this writer (which generates a label and stores bytes), and then writes the label (if any) to the encoder's coreBuf. If the `HeaderInlineEverythingFlag` is set, it also writes the value's bytes directly to the coreBuf for certain types of labels (e.g., length labels, non-null markers for unlabeled types).
type ArgoErrorLocation ¶
type ArgoErrorLocation struct {
Line int `json:"line"` // 1-indexed line number.
Column int `json:"column"` // 1-indexed column number.
}
ArgoErrorLocation represents a single source location (line and column) for an error.
type ArgoErrorValue ¶
type ArgoErrorValue struct {
Message string // The error message.
Locations []ArgoErrorLocation // Source locations of the error in the query.
Path []interface{} // Path to the field where the error occurred, as a list of string field names and integer indices.
Extensions *orderedmap.OrderedMap[string, interface{}] // Custom error data.
}
ArgoErrorValue defines the structure for representing GraphQL errors in Argo format when not using self-describing errors. It includes standard GraphQL error fields. The `Path` is transformed into a list of integers/strings for Argo.
type MessageSlicer ¶
type MessageSlicer struct {
// contains filtered or unexported fields
}
MessageSlicer is responsible for parsing an Argo message into its constituent parts: the header, data blocks (if any), and the core data. It provides buffered views (buf.Read) into these parts without copying the underlying message data.
func NewMessageSlicer ¶
func NewMessageSlicer(fullMessageBuf buf.Read) (*MessageSlicer, error)
NewMessageSlicer creates a MessageSlicer from a buffer containing the entire Argo message. It reads the header and then parses out the block segments and the final core data segment based on length prefixes, unless the HeaderInlineEverythingFlag is set.
func (*MessageSlicer) Core ¶
func (s *MessageSlicer) Core() buf.Read
Core returns a read buffer for the core data part of the message. This buffer contains the main payload after all block definitions.
func (*MessageSlicer) Header ¶
func (s *MessageSlicer) Header() *header.Header
Header returns the parsed message header.
func (*MessageSlicer) NextBlock ¶
func (s *MessageSlicer) NextBlock() buf.Read
NextBlock returns a read buffer for the next data block in the message. If the HeaderInlineEverythingFlag is set in the header, this method will repeatedly return the coreBuffer, as all data is considered inline. Otherwise, it iterates through the pre-parsed data block segments. It returns nil if all data blocks have been vended or if in inline mode and no more distinct blocks were expected by the schema logic.