wire

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package wire defines the fundamental Argo wire types, such as String, Varint, Record, Array, etc., and provides utilities for working with these types. It forms the basis for how Argo data is structured and represented before being encoded or after being decoded.

Index

Constants

This section is empty.

Variables

View Source
var (
	SelfDescribingTypeMarkerNull   = label.NullMarker
	SelfDescribingTypeMarkerFalse  = label.FalseMarker
	SelfDescribingTypeMarkerTrue   = label.TrueMarker
	SelfDescribingTypeMarkerObject = label.NewFromInt64(2)
	SelfDescribingTypeMarkerList   = label.NewFromInt64(3)
	SelfDescribingTypeMarkerString = label.NewFromInt64(4)
	SelfDescribingTypeMarkerBytes  = label.NewFromInt64(5)
	SelfDescribingTypeMarkerInt    = label.NewFromInt64(6)
	SelfDescribingTypeMarkerFloat  = label.NewFromInt64(7)
)

SelfDescribingTypeMarkers are label.Label instances used to mark self-describing types.

View Source
var (
	SelfDescribingNull   = label.Null  // From label package []byte
	SelfDescribingFalse  = label.False // From label package []byte
	SelfDescribingTrue   = label.True  // From label package []byte
	SelfDescribingObject = SelfDescribingTypeMarkerObject.Encode()
	SelfDescribingList   = SelfDescribingTypeMarkerList.Encode()
	SelfDescribingString = SelfDescribingTypeMarkerString.Encode()
	SelfDescribingBytes  = SelfDescribingTypeMarkerBytes.Encode()
	SelfDescribingInt    = SelfDescribingTypeMarkerInt.Encode()
	SelfDescribingFloat  = SelfDescribingTypeMarkerFloat.Encode()
)

SelfDescribing is a collection of pre-encoded byte slices for self-describing type markers.

View Source
var AbsentValue interface{} = &struct{}{}

AbsentValue is a sentinel value used to indicate that an omittable field in a RecordType was not present during decoding. Functions that decode record fields can return (AbsentValue, nil) to signal this absence without it being an error. It is a pointer to an empty struct to ensure it's a unique, comparable value.

View Source
var SelfDescribingBlocks map[BlockKey]Type

SelfDescribingBlocks is a map from BlockKey to the Type of the elements in that block. This is used when decoding self-describing values that are blocks, to know the type of the items within the block from its key. It's initialized in the second init function to ensure all base types are defined.

Functions

func DeduplicateByDefault

func DeduplicateByDefault(t Type) (bool, error)

DeduplicateByDefault determines whether a given wire type (t) should have its corresponding BlockType deduplicated by default. Primitive types like String and Bytes are typically deduplicated by default. Other types like numbers or booleans usually are not. This function returns an error for types like Array or Record, for which block-level deduplication is not directly applicable or meaningful in the same way.

func IsArray

func IsArray(t Type) bool

IsArray checks if the given Type is ArrayType. Returns true if it is, false otherwise.

func IsBlock

func IsBlock(t Type) bool

IsBlock checks if the given Type is BlockType. Returns true if it is, false otherwise.

func IsBoolean

func IsBoolean(t Type) bool

IsBoolean checks if the given Type is BooleanType. Returns true if it is, false otherwise.

func IsBytes

func IsBytes(t Type) bool

IsBytes checks if the given Type is BytesType. Returns true if it is, false otherwise.

func IsDesc

func IsDesc(t Type) bool

IsDesc checks if the given Type is DescType. Returns true if it is, false otherwise.

func IsFixed

func IsFixed(t Type) bool

IsFixed checks if the given Type is FixedType. Returns true if it is, false otherwise.

func IsFloat64

func IsFloat64(t Type) bool

IsFloat64 checks if the given Type is Float64Type. Returns true if it is, false otherwise.

func IsLabeled

func IsLabeled(wt Type) bool

IsLabeled checks if values of the given wire type (wt) are expected to start with a Label in the Argo binary encoding. This is true for types like Nullable, String, Boolean, Bytes, and Array. For a BlockType, it recursively checks if the underlying element type is labeled. It panics if it encounters a BlockType that doesn't conform to the expected structure (which indicates a programming error). Other types (e.g., Varint, Float64, Fixed, Path, Desc, Record) are not directly prefixed by a Label.

func IsNullable

func IsNullable(t Type) bool

IsNullable checks if the given Type is NullableType. Returns true if it is, false otherwise.

func IsPath

func IsPath(t Type) bool

IsPath checks if the given Type is PathType. Returns true if it is, false otherwise.

func IsRecord

func IsRecord(t Type) bool

IsRecord checks if the given Type is RecordType. Returns true if it is, false otherwise.

func IsString

func IsString(t Type) bool

IsString checks if the given Type is StringType. Returns true if it is, false otherwise.

func IsVarint

func IsVarint(t Type) bool

IsVarint checks if the given Type is VarintType. Returns true if it is, false otherwise.

func MustDeduplicateByDefault

func MustDeduplicateByDefault(t Type) bool

MustDeduplicateByDefault is a helper function that calls DeduplicateByDefault(t) and panics if an error occurs. This is intended for use during package initialization where an error from DeduplicateByDefault would indicate a programming error in defining default deduplication behavior for core types.

func PathToWirePath

func PathToWirePath(wt Type, path []interface{}) ([]int, error)

PathToWirePath converts a human-readable path (a slice of strings and integers representing record field names and array indices) into a wire path (a slice of integers representing field/element indices) for a given wire type (wt). This is used to translate a user-friendly path into the compact numerical representation used in the Argo binary format (e.g., for error reporting or targeted data access). Returns an error if the path is invalid for the given wire type (e.g., a string field name used for an array, or an index out of bounds).

func Print

func Print(wt Type) string

Print generates a human-readable string representation of a wire type (wt). It formats the type structure with indentation for readability, useful for debugging or displaying type information. Example: RECORD (

"field1": STRING
"field2": NULLABLE (
  VARINT
)

)

func WirePathToPath

func WirePathToPath(wt Type, wirePath []int) ([]interface{}, error)

WirePathToPath converts a wire path (a slice of integers representing field/element indices) back into a human-readable path (a slice of strings for record field names and integers for array indices) for a given wire type (wt). This is the reverse of PathToWirePath and is useful for presenting internal Argo paths in a more understandable format. Returns an error if the wire path is invalid for the given wire type (e.g., an index is out of bounds for a record or array).

Types

type ArrayType

type ArrayType struct {
	Of Type
}

ArrayType represents an Argo array, which is an ordered sequence of values, all of the same underlying type (Of). It implements the Type interface.

func (ArrayType) GetTypeKey

func (ArrayType) GetTypeKey() TypeKey

type BlockKey

type BlockKey string

BlockKey is a type alias for string, representing a key used to identify a block in an Argo stream. This key is often used for deduplication and referencing. For example, a block of strings might have the key "String".

type BlockType

type BlockType struct {
	Of     Type
	Key    BlockKey
	Dedupe bool
}

BlockType represents an Argo block, which is a sequence of values all of the same underlying type (Of). Blocks have a Key for identification and potential deduplication. The Dedupe flag indicates whether values within this block are subject to deduplication. It implements the Type interface.

func NewBlockType

func NewBlockType(of Type, key BlockKey, dedupe bool) BlockType

NewBlockType is a constructor function that creates and returns a new BlockType. It initializes the BlockType with the specified underlying type (of), block key (key), and deduplication flag (dedupe).

func (BlockType) GetTypeKey

func (BlockType) GetTypeKey() TypeKey

type BooleanType

type BooleanType struct{}

BooleanType represents the Argo wire type for boolean values (true or false). It implements the Type interface. Use the global Boolean instance for this type.

func (BooleanType) GetTypeKey

func (BooleanType) GetTypeKey() TypeKey

type BytesType

type BytesType struct{}

BytesType represents the Argo wire type for opaque byte arrays. It implements the Type interface. Use the global Bytes instance for this type.

func (BytesType) GetTypeKey

func (BytesType) GetTypeKey() TypeKey

type DescType

type DescType struct{}

DescType represents the Argo wire type for self-describing values. A self-describing value carries its type information along with the data. It implements the Type interface. Use the global Desc instance for this type.

func (DescType) GetTypeKey

func (DescType) GetTypeKey() TypeKey

type ExtensionsType added in v1.1.0

type ExtensionsType struct{}

ExtensionsType represents the Argo wire type for extensions. It implements the Type interface. Use the global Extensions instance for this type.

func (ExtensionsType) GetTypeKey added in v1.1.0

func (ExtensionsType) GetTypeKey() TypeKey

type Field

type Field struct {
	Name      string
	Of        Type
	Omittable bool
}

Field defines a single field within a RecordType. It has a Name, an underlying wire Type (Of), and an Omittable flag. If Omittable is true, the field may be absent from an encoded record.

type FixedType

type FixedType struct {
	Length int
}

FixedType represents the Argo wire type for fixed-length byte arrays. The Length field specifies the exact number of bytes this type represents. It implements the Type interface.

func (FixedType) GetTypeKey

func (FixedType) GetTypeKey() TypeKey

type Float64Type

type Float64Type struct{}

Float64Type represents the Argo wire type for 64-bit floating-point numbers (IEEE 754). It implements the Type interface. Use the global Float64 instance for this type.

func (Float64Type) GetTypeKey

func (Float64Type) GetTypeKey() TypeKey

type NullableType

type NullableType struct {
	Of Type
}

NullableType represents an Argo wire type that can either hold a value of another type (Of) or be explicitly null. It implements the Type interface.

func NewNullableType

func NewNullableType(of Type) NullableType

NewNullableType is a constructor function that creates and returns a new NullableType. It initializes the NullableType with the specified underlying type (of) that can be made nullable.

func (NullableType) GetTypeKey

func (NullableType) GetTypeKey() TypeKey

type PathType

type PathType struct{}

PathType represents the Argo wire type for Argo paths. Paths are used for referring to specific locations within a data structure. It implements the Type interface. Use the global Path instance for this type.

func (PathType) GetTypeKey

func (PathType) GetTypeKey() TypeKey

type RecordType

type RecordType struct {
	Fields []Field
}

RecordType represents an Argo record, a structured collection of named Fields. Each field has its own wire type. The order of fields in the Fields slice is significant. It implements the Type interface.

func (RecordType) GetTypeKey

func (RecordType) GetTypeKey() TypeKey

type StringType

type StringType struct{}

StringType represents the Argo wire type for UTF-8 encoded strings. It implements the Type interface. Use the global String instance for this type.

func (StringType) GetTypeKey

func (StringType) GetTypeKey() TypeKey

type Type

type Type interface {
	GetTypeKey() TypeKey
	// contains filtered or unexported methods
}

Type is the core interface implemented by all Argo wire types. It provides a way to get the TypeKey of the wire type and includes an unexported marker method (isWireType) to ensure that only types defined within this package can satisfy the interface. This helps maintain a closed set of known wire types.

var (
	String     Type = StringType{}  // String is the global instance of StringType.
	Boolean    Type = BooleanType{} // Boolean is the global instance of BooleanType.
	Varint     Type = VarintType{}  // Varint is the global instance of VarintType.
	Float64    Type = Float64Type{} // Float64 is the global instance of Float64Type.
	Bytes      Type = BytesType{}   // Bytes is the global instance of BytesType.
	Path       Type = PathType{}    // Path is the global instance of PathType.
	Desc       Type = DescType{}    // Desc is the global instance of DescType.
	Extensions Type = ExtensionsType{}
)

Global pre-allocated instances of primitive wire types. These should be used instead of creating new zero-value structs of these types.

var (
	// VarintBlock is a block of Varint values, keyed as "Int", with default deduplication.
	VarintBlock Type
	// Location is a RecordType representing a line and column, often used for error reporting.
	// Both fields use VarintBlock.
	Location Type
	// Error is a RecordType representing a structured error, potentially including a message,
	// locations, a path, and extensions.
	Error Type
)

Global pre-allocated instances of frequently used complex wire types. These are initialized in the init function.

type TypeKey

type TypeKey string

TypeKey is a string constant representing the kind of an Argo wire type. Each distinct wire type (e.g., StringType, ArrayType) has a unique TypeKey. This is used for type assertions and type-based dispatch.

const (

	// TypeKeyString represents the wire type for UTF-8 encoded strings.
	TypeKeyString TypeKey = "STRING"
	// TypeKeyBoolean represents the wire type for boolean values (true or false).
	TypeKeyBoolean TypeKey = "BOOLEAN"
	// TypeKeyVarint represents the wire type for variable-length integers.
	TypeKeyVarint TypeKey = "VARINT"
	// TypeKeyFloat64 represents the wire type for 64-bit floating-point numbers (IEEE 754).
	TypeKeyFloat64 TypeKey = "FLOAT64"
	// TypeKeyBytes represents the wire type for opaque byte arrays.
	TypeKeyBytes TypeKey = "BYTES"
	// TypeKeyPath represents the wire type for GraphQL paths, used for referring to specific locations within a data structure.
	TypeKeyPath TypeKey = "PATH"

	// TypeKeyFixed represents the wire type for fixed-length byte arrays.
	TypeKeyFixed TypeKey = "FIXED"
	// TypeKeyBlock represents a block, which is a sequence of values of the same underlying type.
	// Blocks can optionally be deduplicated.
	TypeKeyBlock TypeKey = "BLOCK"
	// TypeKeyNullable represents a wire type that can hold a value of another type or be explicitly null.
	TypeKeyNullable TypeKey = "NULLABLE"
	// TypeKeyArray represents an ordered sequence of values, all of the same underlying type.
	TypeKeyArray TypeKey = "ARRAY"
	// TypeKeyRecord represents a structured collection of named fields, where each field has its own wire type.
	TypeKeyRecord TypeKey = "RECORD"
	// TypeKeyDesc represents a self-describing value, where the value itself carries its type information.
	TypeKeyDesc TypeKey = "DESC"
	// TypeKeyExtensions represents an extension
	TypeKeyExtensions TypeKey = "EXTENSIONS"
)

type VarintType

type VarintType struct{}

VarintType represents the Argo wire type for variable-length integers. It implements the Type interface. Use the global Varint instance for this type.

func (VarintType) GetTypeKey

func (VarintType) GetTypeKey() TypeKey

Jump to

Keyboard shortcuts

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