vdl

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: BSD-3-Clause Imports: 11 Imported by: 364

Documentation

Overview

Package vdl implements the Vanadium Definition Language type and value system.

Concept: https://vanadium.github.io/concepts/rpc.html#vdl
Specification: https://vanadium.github.io/designdocs/vdl-spec.html

VDL is an interface definition language designed to enable interoperation between clients and servers executing in heterogeneous environments. E.g. it enables a frontend written in Javascript running on a phone to communicate with a backend written in Go running on a server. VDL is compiled into an intermediate representation that is used to generate code in each target environment.

The concepts in VDL are similar to the concepts used in general-purpose languages to specify interfaces and communication protocols.

Index

Constants

This section is empty.

Variables

View Source
var (
	AnyType        = primitiveType(Any)
	BoolType       = primitiveType(Bool)
	ByteType       = primitiveType(Byte)
	Uint16Type     = primitiveType(Uint16)
	Uint32Type     = primitiveType(Uint32)
	Uint64Type     = primitiveType(Uint64)
	Int8Type       = primitiveType(Int8)
	Int16Type      = primitiveType(Int16)
	Int32Type      = primitiveType(Int32)
	Int64Type      = primitiveType(Int64)
	Float32Type    = primitiveType(Float32)
	Float64Type    = primitiveType(Float64)
	StringType     = primitiveType(String)
	TypeObjectType = primitiveType(TypeObject)
)

Primitive types, the basis for all other types. All have empty names.

View Source
var ErrorType = OptionalType(NamedType("v.io/v23/vdl.WireError", StructType(
	Field{"Id", StringType},
	Field{"RetryCode", NamedType("v.io/v23/vdl.WireRetryCode", EnumType("NoRetry", "RetryConnection", "RetryRefetch", "RetryBackoff"))},
	Field{"Msg", StringType},
	Field{"ParamList", ListType(AnyType)},
)))

ErrorType describes the built-in error type. TODO(bprosnitz) We should define these as built-ins (with name wireError and wireRetryCode).

WireRetryCodeAll holds all labels for WireRetryCode.

Functions

func Compatible

func Compatible(a, b *Type) bool

Compatible returns true if types a and b are compatible with each other.

Compatibility is checked before every value conversion; it is the first-pass filter that disallows certain conversions. Values of incompatible types are never convertible, while values of compatible types might not be convertible. E.g. float32 and byte are compatible types, and float32(1.0) is convertible to/from byte(1), but float32(1.5) is not convertible to/from any byte value.

The reason we have a type compatibility check is to disallow invalid conversions that are hard to catch while converting values. E.g. conversions between values of []bool and []float32 are invalid, but this is hard to catch if both lists are empty.

Compatibility is reversible and transitive, except for the special Any type. Here are the rules:

o Any is compatible with all types.
o Optional is ignored for all rules (e.g. ?int is treated as int).
o Bool is only compatible with Bool.
o TypeObject is only compatible with TypeObject.
o Numbers are mutually compatible.
o String and enum are mutually compatible.
o Array and list are compatible if their elem types are compatible.
o Sets are compatible if their key types are compatible.
o Maps are compatible if their key and elem types are compatible.
o Structs are compatible if all fields with the same name are compatible,
  and at least one field has the same name, or one of the types has no
  fields.
o Unions are compatible if all fields with the same name are compatible,
  and at least one field has the same name.

Recursive types are checked for compatibility up to the first occurrence of a cycle in either type. This leaves open the possibility of "obvious" false positives where types are compatible but values are not; this is a tradeoff favoring a simpler implementation and better performance over exhaustive checking. This seems fine in practice since type compatibility is weaker than value convertibility, and since recursive types are not common.

func Convert

func Convert(dst, src interface{}) error

Convert converts from src to dst.

func ConvertReflect

func ConvertReflect(dst, src reflect.Value) error

ConvertReflect converts reflect values from src to dst.

func DecodeConvertedBytes

func DecodeConvertedBytes(dec Decoder, fixedLen int, buf *[]byte) error

DecodeConvertedBytes is a helper function for implementations of Decoder.DecodeBytes, to deal with cases where the decoder value is convertible to []byte. E.g. if the decoder value is []float64, we need to decode each element as a uint8, performing conversion checks.

Since this is meant to be used in the implementation of DecodeBytes, there is no outer call to StartValue/FinishValue.

func DeepEqual

func DeepEqual(a, b interface{}) bool

DeepEqual is like reflect.DeepEqual, with the following differences:

  1. If a value is encountered that implements Equaler, we will use that for the comparison.
  2. If cyclic values are encountered, we require that the cyclic structure of the two values is the same.

func DeepEqualReflect

func DeepEqualReflect(a, b reflect.Value) bool

DeepEqualReflect is the same as DeepEqual, but takes reflect.Value arguments.

func EqualValue

func EqualValue(a, b *Value) bool

EqualValue returns true iff a and b have the same type, and equal values.

TODO(toddw): The Value representation currently allows non-nil any, e.g. Value{Type:AnyType, Rep: ...}. We will soon remove this support. EqualValue does not distinguish non-nil any from the inner value.

func Read

func Read(dec Decoder, v interface{}) error

Read uses dec to decode a value into v, calling VDLRead methods and fast compiled readers when available, and using reflection otherwise. This is basically an all-purpose VDLRead implementation.

func ReadReflect

func ReadReflect(dec Decoder, rv reflect.Value) error

ReadReflect is like Read, but takes a reflect.Value argument.

func Register

func Register(wire interface{})

Register registers a type, identified by a value for that type. The type should be a type that will be sent over the wire. Subtypes are recursively registered. This creates a type name <-> reflect.Type bijective mapping.

Type registration is only required for VDL conversion into interface{} values, so that values of the correct type may be generated. Conversion into interface{} values for types that are not registered will fill in *vdl.Value into the interface{} value.

Panics if wire is not a valid wire type, or if the name<->type mapping is not bijective.

Register is not intended to be called by end users; calls are auto-generated for all types defined in *.vdl files.

func RegisterNative

func RegisterNative(toFn, fromFn interface{})

RegisterNative registers conversion functions between a VDL wire type and a Go native type. This is typically used when there is a more idiomatic native representation for a given wire type; e.g. the VDL standard Time type is converted into the Go standard time.Time.

The signatures of the conversion functions is expected to be:

func ToNative(wire W, native *N) error
func FromNative(wire *W, native N) error

The VDL conversion routines automatically apply these conversion functions, to avoid manual marshaling by the user. The "dst" values (i.e. native in ToNative, and wire in FromNative) are guaranteed to be an allocated zero value of the respective type.

As a special-case, RegisterNative is also called by the verror package to register conversions between vdl.WireError and the standard Go error type. This is required for error conversions to work correctly.

RegisterNative is not intended to be called by end users; calls are auto-generated for types with native conversions in *.vdl files.

func RegisterNativeError

func RegisterNativeError(toFn, fromFn interface{})

TODO(bprosnitz) Remove this.

func SplitIdent

func SplitIdent(ident string) (pkgpath, name string)

SplitIdent splits the given identifier into its package path and local name.

a/b.Foo   -> (a/b, Foo)
a.b/c.Foo -> (a.b/c, Foo)
Foo       -> ("",  Foo)
a/b       -> ("",  a/b)

func Transcode

func Transcode(e Encoder, d Decoder) error

Transcode transcodes from the decoder to the encoder.

func TypeToReflect

func TypeToReflect(t *Type) reflect.Type

TypeToReflect returns the reflect.Type corresponding to t. We look up named types in our registry, and build the unnamed types that we can via the Go reflect package. Returns nil for types that can't be manufactured.

func WrapInUnionInterface

func WrapInUnionInterface(rv reflect.Value) reflect.Value

WrapInUnionInterface returns a value of the union interface type that holds the union value rv. Returns an invalid reflect.Value if rv isn't a union value. Returns rv unchanged if its type is already the interface type.

func Write

func Write(enc Encoder, v interface{}) error

Write uses enc to encode value v, calling VDLWrite methods and fast compiled writers when available, and using reflection otherwise. This is basically an all-purpose VDLWrite implementation.

func WriteReflect

func WriteReflect(enc Encoder, rv reflect.Value) error

WriteReflect is like Write, but takes a reflect.Value argument.

Types

type Decoder

type Decoder interface {
	// StartValue must be called before decoding each value, for both scalar and
	// composite values.  The want type is the type of value being decoded into,
	// used to check compatibility with the value in the decoder; use AnyType if
	// you don't know, or want to decode any type of value.  Each call pushes the
	// type of the next value on to the stack.
	StartValue(want *Type) error
	// FinishValue must be called after decoding each value, for both scalar and
	// composite values.  Each call pops the type of the top value off of the
	// stack.
	FinishValue() error
	// SkipValue skips the next value; logically it behaves as if a full sequence
	// of StartValue / ...Decode*... / FinishValue were called.  It enables
	// optimizations when the caller doesn't care about the next value.
	SkipValue() error
	// IgnoreNextStartValue instructs the Decoder to ignore the next call to
	// StartValue.  It is used to simplify implementations of VDLRead; e.g. a
	// caller might call StartValue to check for nil values, and subsequently call
	// StartValue again to read non-nil values.  IgnoreNextStartValue is used to
	// ignore the second StartValue call.
	IgnoreNextStartValue()

	// NextEntry instructs the Decoder to move to the next element of an Array or
	// List, the next key of a Set, or the next (key,elem) pair of a Map.  Returns
	// done=true when there are no remaining entries.
	NextEntry() (done bool, _ error)
	// NextField instructs the Decoder to move to the next field of a Struct or
	// Union.  Returns the index of the next field, or -1 when there are no
	// remaining fields.  You may call Decoder.Type().Field(index).Name to
	// retrieve the name of the struct or union field.
	NextField() (index int, _ error)

	// Type returns the type of the top value on the stack.  Returns nil when the
	// stack is empty.  The returned type is only Any or Optional iff the value is
	// nil; non-nil values are "auto-dereferenced" to their underlying elem value.
	Type() *Type
	// IsAny returns true iff the type of the top value on the stack was Any,
	// despite the "auto-dereference" behavior of non-nil values.
	IsAny() bool
	// IsOptional returns true iff the type of the top value on the stack was
	// Optional, despite the "auto-dereference" behavior of non-nil values.
	IsOptional() bool
	// IsNil returns true iff the top value on the stack is nil.  It is equivalent
	// to Type() == AnyType || Type().Kind() == Optional.
	IsNil() bool
	// Index returns the index of the current entry or field of the top value on
	// the stack.  Returns -1 if the top value is a scalar, or if NextEntry /
	// NextField has not been called.
	Index() int
	// LenHint returns the length of the top value on the stack, if it is
	// available.  Returns -1 if the top value is a scalar, or if the length is
	// not available.
	LenHint() int

	// DecodeBool returns the top value on the stack as a bool.
	DecodeBool() (bool, error)
	// DecodeString returns the top value on the stack as a string.
	DecodeString() (string, error)
	// DecodeUint returns the top value on the stack as a uint, where the result
	// has bitlen bits.  Errors are returned on loss of precision.
	DecodeUint(bitlen int) (uint64, error)
	// DecodeInt returns the top value on the stack as an int, where the result
	// has bitlen bits.  Errors are returned on loss of precision.
	DecodeInt(bitlen int) (int64, error)
	// DecodeFloat returns the top value on the stack as a float, where the result
	// has bitlen bits.  Errors are returned on loss of precision.
	DecodeFloat(bitlen int) (float64, error)
	// DecodeTypeObject returns the top value on the stack as a type.
	DecodeTypeObject() (*Type, error)
	// DecodeBytes decodes the top value on the stack as bytes, into x.  If
	// fixedLen >= 0 the decoded bytes must be exactly that length, otherwise
	// there is no restriction on the number of decoded bytes.  If cap(*x) is not
	// large enough to fit the decoded bytes, a new byte slice is assigned to *x.
	DecodeBytes(fixedLen int, x *[]byte) error

	// ReadValueBool behaves as if StartValue, DecodeBool, FinishValue were
	// called in sequence.  Some decoders optimize this codepath.
	ReadValueBool() (bool, error)
	// ReadValueString behaves as if StartValue, DecodeString, FinishValue were
	// called in sequence.  Some decoders optimize this codepath.
	ReadValueString() (string, error)
	// ReadValueUint behaves as if StartValue, DecodeUint, FinishValue were called
	// in sequence.  Some decoders optimize this codepath.
	ReadValueUint(bitlen int) (uint64, error)
	// ReadValueInt behaves as if StartValue, DecodeInt, FinishValue were called
	// in sequence.  Some decoders optimize this codepath.
	ReadValueInt(bitlen int) (int64, error)
	// ReadValueFloat behaves as if StartValue, DecodeFloat, FinishValue were
	// called in sequence.  Some decoders optimize this codepath.
	ReadValueFloat(bitlen int) (float64, error)
	// ReadValueTypeObject behaves as if StartValue, DecodeTypeObject, FinishValue
	// were called in sequence.  Some decoders optimize this codepath.
	ReadValueTypeObject() (*Type, error)
	// ReadValueBytes behaves as if StartValue, DecodeBytes, FinishValue were
	// called in sequence.  Some decoders optimize this codepath.
	ReadValueBytes(fixedLen int, x *[]byte) error

	// NextEntryValueBool behaves as if NextEntry, StartValue, DecodeBool,
	// FinishValue were called in sequence.  Some decoders optimize this codepath.
	NextEntryValueBool() (done bool, _ bool, _ error)
	// NextEntryValueString behaves as if NextEntry, StartValue, DecodeString,
	// FinishValue were called in sequence.  Some decoders optimize this codepath.
	NextEntryValueString() (done bool, _ string, _ error)
	// NextEntryValueUint behaves as if NextEntry, StartValue, DecodeUint,
	// FinishValue were called in sequence.  Some decoders optimize this codepath.
	NextEntryValueUint(bitlen int) (done bool, _ uint64, _ error)
	// NextEntryValueInt behaves as if NextEntry, StartValue, DecodeInt,
	// FinishValue were called in sequence.  Some decoders optimize this codepath.
	NextEntryValueInt(bitlen int) (done bool, _ int64, _ error)
	// NextEntryValueFloat behaves as if NextEntry, StartValue, DecodeFloat,
	// FinishValue were called in sequence.  Some decoders optimize this codepath.
	NextEntryValueFloat(bitlen int) (done bool, _ float64, _ error)
	// NextEntryValueTypeObject behaves as if NextEntry, StartValue,
	// DecodeTypeObject, FinishValue were called in sequence.  Some decoders
	// optimize this codepath.
	NextEntryValueTypeObject() (done bool, _ *Type, _ error)
}

Decoder defines the interface for a decoder of vdl values. The Decoder is passed as the argument to VDLRead. An example of an implementation of this interface is vom.Decoder.

The Decoder provides an API to read vdl values of all types in depth-first order. The ordering is based on the type of the value being read. E.g. given the following value:

type MyStruct struct {
  A []string
  B map[int64]bool
  C any
}
value := MyStruct{
  A: {"abc", "def"},
  B: {123: true, 456: false},
  C: float32(1.5),
}

The values will be read in the following order:

"abc"
"def"
(123, true)
(456, false)
1.5

type Encoder

type Encoder interface {
	// StartValue must be called before encoding each non-nil value, for both
	// scalar and composite values.  The tt type cannot be Any or Optional; use
	// NilValue to encode nil values.
	StartValue(tt *Type) error
	// FinishValue must be called after encoding each non-nil value, for both
	// scalar and composite values.
	FinishValue() error
	// NilValue encodes a nil value.  The tt type must be Any or Optional.
	NilValue(tt *Type) error
	// SetNextStartValueIsOptional instructs the encoder that the next call to
	// StartValue represents a value with an Optional type.
	SetNextStartValueIsOptional()

	// NextEntry instructs the Encoder to move to the next element of an Array or
	// List, the next key of a Set, or the next (key,elem) pair of a Map.  Set
	// done=true when there are no remaining entries.
	NextEntry(done bool) error
	// NextField instructs the Encoder to move to the next field of a Struct or
	// Union.  Set index to the index of the next field, or -1 when there are no
	// remaining fields.
	NextField(index int) error

	// SetLenHint sets the length of the List, Set or Map value.  It may only be
	// called immediately after StartValue, before NextEntry has been called.  Do
	// not call this method if the length is not known.
	SetLenHint(lenHint int) error

	// EncodeBool encodes a bool value.
	EncodeBool(value bool) error
	// EncodeString encodes a string value.
	EncodeString(value string) error
	// EncodeUint encodes a uint value.
	EncodeUint(value uint64) error
	// EncodeInt encodes an int value.
	EncodeInt(value int64) error
	// EncodeFloat encodes a float value.
	EncodeFloat(value float64) error
	// EncodeTypeObject encodes a type.
	EncodeTypeObject(value *Type) error
	// EncodeBytes encodes a bytes value; either an array or list of bytes.
	EncodeBytes(value []byte) error

	// WriteValueBool behaves as if StartValue, EncodeBool, FinishValue were
	// called in sequence.  Some encoders optimize this codepath.
	WriteValueBool(tt *Type, value bool) error
	// WriteValueString behaves as if StartValue, EncodeString, FinishValue were
	// called in sequence.  Some encoders optimize this codepath.
	WriteValueString(tt *Type, value string) error
	// WriteValueUint behaves as if StartValue, EncodeUint, FinishValue were
	// called in sequence.  Some encoders optimize this codepath.
	WriteValueUint(tt *Type, value uint64) error
	// WriteValueInt behaves as if StartValue, EncodeInt, FinishValue were called
	// in sequence.  Some encoders optimize this codepath.
	WriteValueInt(tt *Type, value int64) error
	// WriteValueFloat behaves as if StartValue, EncodeFloat, FinishValue were
	// called in sequence.  Some encoders optimize this codepath.
	WriteValueFloat(tt *Type, value float64) error
	// WriteValueTypeObject behaves as if StartValue, EncodeTypeObject,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	WriteValueTypeObject(value *Type) error
	// WriteValueBytes behaves as if StartValue, EncodeBytes, FinishValue were
	// called in sequence.  Some encoders optimize this codepath.
	WriteValueBytes(tt *Type, value []byte) error

	// NextEntryValueBool behaves as if NextEntry, StartValue, EncodeBool,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextEntryValueBool(tt *Type, value bool) error
	// NextEntryValueString behaves as if NextEntry, StartValue, EncodeString,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextEntryValueString(tt *Type, value string) error
	// NextEntryValueUint behaves as if NextEntry, StartValue, EncodeUint,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextEntryValueUint(tt *Type, value uint64) error
	// NextEntryValueInt behaves as if NextEntry, StartValue, EncodeInt,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextEntryValueInt(tt *Type, value int64) error
	// NextEntryValueFloat behaves as if NextEntry, StartValue, EncodeFloat,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextEntryValueFloat(tt *Type, value float64) error
	// NextEntryValueTypeObject behaves as if NextEntry, StartValue,
	// EncodeTypeObject, FinishValue were called in sequence.  Some encoders
	// optimize this codepath.
	NextEntryValueTypeObject(value *Type) error
	// NextEntryValueBytes behaves as if NextEntry, StartValue, EncodeBytes,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextEntryValueBytes(tt *Type, value []byte) error

	// NextFieldValueBool behaves as if NextEntry, StartValue, EncodeBool,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextFieldValueBool(index int, tt *Type, value bool) error
	// NextFieldValueString behaves as if NextEntry, StartValue, EncodeString,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextFieldValueString(index int, tt *Type, value string) error
	// NextFieldValueUint behaves as if NextEntry, StartValue, EncodeUint,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextFieldValueUint(index int, tt *Type, value uint64) error
	// NextFieldValueInt behaves as if NextEntry, StartValue, EncodeInt,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextFieldValueInt(index int, tt *Type, value int64) error
	// NextFieldValueFloat behaves as if NextEntry, StartValue, EncodeFloat,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextFieldValueFloat(index int, tt *Type, value float64) error
	// NextFieldValueTypeObject behaves as if NextEntry, StartValue,
	// EncodeTypeObject, FinishValue were called in sequence.  Some encoders
	// optimize this codepath.
	NextFieldValueTypeObject(index int, value *Type) error
	// NextFieldValueBytes behaves as if NextEntry, StartValue, EncodeBytes,
	// FinishValue were called in sequence.  Some encoders optimize this codepath.
	NextFieldValueBytes(index int, tt *Type, value []byte) error
}

Encoder defines the interface for an encoder of vdl values. The Encoder is passed as the argument to VDLWrite. An example of an implementation of this interface is vom.Encoder.

The Encoder provides an API to write vdl values of all types in depth-first order. The ordering is based on the type of the value being written; see Decoder for examples.

type Equaler

type Equaler interface {
	VDLEqual(v interface{}) bool
}

Equaler is the interface that wraps the VDLEqual method.

VDLEqual returns true iff the receiver that implements this method is equal to v. The semantics of the equality must abide by VDL equality rules. The caller of this method must ensure that the type of the receiver is the same as the type of v, and v is never nil.

type Field

type Field struct {
	Name string
	Type *Type
}

Field describes a single field in a Struct or Union.

type IsZeroer

type IsZeroer interface {
	VDLIsZero() bool
}

IsZeroer is the interface that wraps the VDLIsZero method.

VDLIsZero returns true iff the receiver that implements this method is the VDL zero value.

type Kind

type Kind int

Kind represents the kind of type that a Type represents.

const (
	// Variant kinds
	Any      Kind = iota // any type
	Optional             // value might not exist
	// Scalar kinds
	Bool       // boolean
	Byte       // 8 bit unsigned integer
	Uint16     // 16 bit unsigned integer
	Uint32     // 32 bit unsigned integer
	Uint64     // 64 bit unsigned integer
	Int8       // 8 bit signed integer
	Int16      // 16 bit signed integer
	Int32      // 32 bit signed integer
	Int64      // 64 bit signed integer
	Float32    // 32 bit IEEE 754 floating point
	Float64    // 64 bit IEEE 754 floating point
	String     // unicode string (encoded as UTF-8 in memory)
	Enum       // one of a set of labels
	TypeObject // type represented as a value
	// Composite kinds
	Array  // fixed-length ordered sequence of elements
	List   // variable-length ordered sequence of elements
	Set    // unordered collection of distinct keys
	Map    // unordered association between distinct keys and values
	Struct // conjunction of an ordered sequence of (name,type) fields
	Union  // disjunction of an ordered sequence of (name,type) fields

)

func (Kind) BitLen

func (k Kind) BitLen() int

BitLen returns the number of bits in the representation of the kind; e.g. Int32 returns 32. Returns -1 for non-number kinds.

func (Kind) CamelCase added in v0.1.8

func (k Kind) CamelCase() string

func (Kind) IsNumber

func (k Kind) IsNumber() bool

IsNumber returns true iff the kind is a number.

func (Kind) String

func (k Kind) String() string

type PendingArray

type PendingArray interface {
	PendingType
	// AssignLen assigns the Array length.
	AssignLen(len int) PendingArray
	// AssignElem assigns the Array element type.
	AssignElem(elem TypeOrPending) PendingArray
}

PendingArray represents an Array type that is being built.

type PendingEnum

type PendingEnum interface {
	PendingType
	// AppendLabel appends an Enum label.  Every Enum must have at least one
	// label, and each label must not be empty.
	AppendLabel(label string) PendingEnum
}

PendingEnum represents an Enum type that is being built.

type PendingList

type PendingList interface {
	PendingType
	// AssignElem assigns the List element type.
	AssignElem(elem TypeOrPending) PendingList
}

PendingList represents a List type that is being built.

type PendingMap

type PendingMap interface {
	PendingType
	// AssignKey assigns the Map key type.
	AssignKey(key TypeOrPending) PendingMap
	// AssignElem assigns the Map element type.
	AssignElem(elem TypeOrPending) PendingMap
}

PendingMap represents a Map type that is being built.

type PendingNamed

type PendingNamed interface {
	PendingType
	// AssignBase assigns the base type of the named type.  The resulting built
	// type will have the same underlying structure as base, but with the given
	// name.
	AssignBase(base TypeOrPending) PendingNamed
}

PendingNamed represents a named type that is being built. Given a base type you can build a new type with an identical underlying structure, but a different name.

type PendingOptional

type PendingOptional interface {
	PendingType
	// AssignElem assigns the Optional elem type.
	AssignElem(elem TypeOrPending) PendingOptional
}

PendingOptional represents an Optional type that is being built. Given a base type that is non-optional, you can build a new type that is optional.

type PendingSet

type PendingSet interface {
	PendingType
	// AssignKey assigns the Set key type.
	AssignKey(key TypeOrPending) PendingSet
}

PendingSet represents a Set type that is being built.

type PendingStruct

type PendingStruct interface {
	PendingType
	// AppendField appends the Struct field with the given name and t.  The name
	// must not be empty.  The ordering of fields is preserved; different
	// orderings create different types.
	AppendField(name string, t TypeOrPending) PendingStruct
	// NumField returns the number of fields appended so far.
	NumField() int
}

PendingStruct represents a Struct type that is being built.

type PendingType

type PendingType interface {
	TypeOrPending
	// Built returns the final built and hash-consed type.  Build must be called
	// on the TypeBuilder before Built is called on any pending type.  If any
	// pending type has a build error, Built returns a nil type for all pending
	// types, and returns non-nil errors for at least one pending type.
	Built() (*Type, error)
}

PendingType represents a type that's being built by the TypeBuilder.

type PendingUnion

type PendingUnion interface {
	PendingType
	// AppendField appends the Union field with the given name and t.  The name
	// must not be empty.  The ordering of fields is preserved; different
	// orderings create different types.
	AppendField(name string, t TypeOrPending) PendingUnion
	// NumField returns the number of fields appended so far.
	NumField() int
}

PendingUnion represents a Union type that is being built.

type ReadWriter

type ReadWriter interface {
	Reader
	Writer
}

ReadWriter is the interface that groups the VDLRead and VDLWrite methods.

type Reader

type Reader interface {
	VDLRead(dec Decoder) error
}

Reader is the interface that wraps the VDLRead method.

VDLRead fills in the the receiver that implements this method from the Decoder. This method is auto-generated for all types defined in vdl. It may be implemented for regular Go types not defined in vdl, to customize the decoding.

type Type

type Type struct {
	// contains filtered or unexported fields
}

Type is the representation of a vanadium type. Types are hash-consed; each unique type is represented by exactly one *Type instance, so to test for type equality you just compare the *Type instances.

Not all methods apply to all kinds of types. Restrictions are noted in the documentation for each method. Calling a method inappropriate to the kind of type causes a run-time panic.

Cyclic types are supported; e.g. you can represent a tree via:

type Node struct {
  Val      string
  Children []Node
}

func ArrayType

func ArrayType(len int, elem *Type) *Type

ArrayType is a helper using TypeBuilder to create a single Array type. Panics on all errors.

func EnumType

func EnumType(labels ...string) *Type

EnumType is a helper using TypeBuilder to create a single Enum type. Panics on all errors.

func ListType

func ListType(elem *Type) *Type

ListType is a helper using TypeBuilder to create a single List type. Panics on all errors.

func MapType

func MapType(key, elem *Type) *Type

MapType is a helper using TypeBuilder to create a single Map type. Panics on all errors.

func NamedType

func NamedType(name string, base *Type) *Type

NamedType is a helper using TypeBuilder to create a single named type based on another type. Panics on all errors.

func OptionalType

func OptionalType(elem *Type) *Type

OptionalType is a helper using TypeBuilder to create a single Optional type. Panics on all errors.

func SetType

func SetType(key *Type) *Type

SetType is a helper using TypeBuilder to create a single Set type. Panics on all errors.

func StructType

func StructType(fields ...Field) *Type

StructType is a helper using TypeBuilder to create a single Struct type. Panics on all errors.

func TypeFromReflect

func TypeFromReflect(rt reflect.Type) (*Type, error)

TypeFromReflect returns the type corresponding to rt. Not all reflect types have a valid type; reflect.Chan, reflect.Func and reflect.UnsafePointer are unsupported, as are maps with pointer keys, as well as structs with only unexported fields.

func TypeOf

func TypeOf(v interface{}) *Type

TypeOf returns the type corresponding to v. It's a helper for calling TypeFromReflect, and panics on any errors.

func UnionType

func UnionType(fields ...Field) *Type

UnionType is a helper using TypeBuilder to create a single Union type. Panics on all errors.

func (*Type) AssignableFrom

func (t *Type) AssignableFrom(f *Value) bool

AssignableFrom returns true iff values of t may be assigned from f:

o Allowed if t and the type of f are identical.
o Allowed if t is Any.
o Allowed if t is Optional, and f is Any(nil).

The first rule establishes strict static typing. The second rule relaxes things for Any, which is dynamically typed. The third rule relaxes things further, to allow implicit conversions from Any(nil) to all Optional types.

func (*Type) CanBeKey

func (t *Type) CanBeKey() bool

CanBeKey returns true iff t can be used as a set or map key.

Any, List, Map, Optional, Set and TypeObject cannot be keys, nor can composite types that contain these types.

func (*Type) CanBeNamed

func (t *Type) CanBeNamed() bool

CanBeNamed returns true iff t can be made into a named type.

Any and TypeObject cannot be named.

func (*Type) CanBeNil

func (t *Type) CanBeNil() bool

CanBeNil returns true iff values of t can be nil.

Any and Optional values can be nil.

func (*Type) CanBeOptional

func (t *Type) CanBeOptional() bool

CanBeOptional returns true iff t can be made into an optional type.

Only named structs can be optional.

func (*Type) ContainsKind

func (t *Type) ContainsKind(mode WalkMode, kinds ...Kind) bool

ContainsKind returns true iff t or subtypes of t match any of the kinds.

func (*Type) ContainsType

func (t *Type) ContainsType(mode WalkMode, types ...*Type) bool

ContainsType returns true iff t or subtypes of t match any of the types.

func (*Type) Elem

func (t *Type) Elem() *Type

Elem returns the element type of an Optional, Array, List or Map.

func (*Type) EnumIndex

func (t *Type) EnumIndex(label string) int

EnumIndex returns the Enum index for the given label. Returns -1 if the label doesn't exist.

func (*Type) EnumLabel

func (t *Type) EnumLabel(index int) string

EnumLabel returns the Enum label at the given index. It panics if the index is out of range.

func (*Type) Field

func (t *Type) Field(index int) Field

Field returns a description of the Struct or Union field at the given index.

func (*Type) FieldByName

func (t *Type) FieldByName(name string) (Field, int)

FieldByName returns a description of the Struct or Union field with the given name, and its index. Returns -1 if the name doesn't exist.

func (*Type) FieldIndexByName

func (t *Type) FieldIndexByName(name string) int

FieldIndexByName returns the index of the Struct or Union field with the given name. Returns -1 if the name doesn't exist.

func (*Type) IsBytes

func (t *Type) IsBytes() bool

IsBytes returns true iff the kind of type is []byte or [N]byte.

func (*Type) IsPartOfCycle

func (t *Type) IsPartOfCycle() bool

IsPartOfCycle returns true iff t is part of a cycle. Note that t is not considered to be part of a cycle if it merely contains another type that is part of a cycle; the type graph must cycle back through t to return true.

func (*Type) Key

func (t *Type) Key() *Type

Key returns the key type of a Set or Map.

func (*Type) Kind

func (t *Type) Kind() Kind

Kind returns the kind of type t.

func (*Type) Len

func (t *Type) Len() int

Len returns the length of an Array.

func (*Type) Name

func (t *Type) Name() string

Name returns the name of type t. Empty names are allowed.

func (*Type) NonOptional

func (t *Type) NonOptional() *Type

NonOptional returns t.Elem() if t is Optional, otherwise returns t.

func (*Type) NumEnumLabel

func (t *Type) NumEnumLabel() int

NumEnumLabel returns the number of labels in an Enum.

func (*Type) NumField

func (t *Type) NumField() int

NumField returns the number of fields in a Struct or Union.

func (*Type) String

func (t *Type) String() string

String returns a human-readable description of type t. Do not rely on the output format; it may change without notice. See Unique for a format that is guaranteed never to change.

func (*Type) Unique

func (t *Type) Unique() string

Unique returns a unique representation of type t. Two types A and B are guaranteed to return the same unique string iff A is equal to B. The format is guaranteed to never change.

A typical use case is to hash the unique representation to produce globally-unique type ids.

TODO(toddw): Make sure we're comfortable with the format we produce; if it needs to change, it needs to happen soon.

func (*Type) VDLIsZero

func (t *Type) VDLIsZero() bool

VDLIsZero returns true if t is nil or AnyType.

func (*Type) VDLWrite

func (t *Type) VDLWrite(enc Encoder) error

VDLWrite uses enc to encode type t.

Unlike regular VDLWrite implementations, this handles the case where t contains a nil value, to make code generation simpler.

func (*Type) Walk

func (t *Type) Walk(mode WalkMode, fn func(*Type) bool) bool

Walk performs a DFS walk through the type graph starting from t, calling fn for each visited type. If fn returns false on a visited type, the walk is terminated early, and false is returned by Walk. The mode controls which types in the type graph we will visit.

type TypeBuilder

type TypeBuilder struct {
	// contains filtered or unexported fields
}

TypeBuilder builds Types. There are two phases: 1) Create Pending* objects and describe each type, and 2) call Build. When Build is called, all types are created and may be retrieved by calling Built on the pending type. This two-phase building enables support for recursive types, and also makes it easy to construct a group of dependent types without determining their dependency ordering. The separation between Build and Built allows individual errors to be returned for each pending type, and easily associated with additional information for the pending type, e.g. position information in a compiler.

Each TypeBuilder instance enforces the rule that type names are unique; each named type must be represented by exactly one Type or PendingType object. E.g. you can't create an enum "Foo" and a struct "Foo" via the same TypeBuilder, nor can you create two structs named "Foo", even if they have the same fields. This rule simplifies the hash consing logic.

There is no enforcement of unique names across TypeBuilder instances; the val package allows different types with the same names. This allows support for a single named type with multiple versions, all handled within a single address space.

The zero TypeBuilder represents an empty builder.

func (*TypeBuilder) Array

func (b *TypeBuilder) Array() PendingArray

Array returns PendingArray, used to describe an Array type.

func (*TypeBuilder) Build

func (b *TypeBuilder) Build()

Build builds all pending types. Build must be called before Built may be called on each pending type to retrieve the final result.

Build guarantees that either all pending types are successfully built, or none of them are. I.e. all calls to Built will either return a non-nil Type and nil error, or nil Type. The pending type(s) that had build errors will return non-nil errors.

func (*TypeBuilder) Enum

func (b *TypeBuilder) Enum() PendingEnum

Enum returns PendingEnum, used to describe an Enum type.

func (*TypeBuilder) List

func (b *TypeBuilder) List() PendingList

List returns PendingList, used to describe a List type.

func (*TypeBuilder) Map

func (b *TypeBuilder) Map() PendingMap

Map returns PendingMap, used to describe a Map type.

func (*TypeBuilder) Named

func (b *TypeBuilder) Named(name string) PendingNamed

Named returns PendingNamed, used to describe a named type based on another type.

func (*TypeBuilder) Optional

func (b *TypeBuilder) Optional() PendingOptional

Optional returns PendingOptional, used to describe an Optional type.

func (*TypeBuilder) Set

func (b *TypeBuilder) Set() PendingSet

Set returns PendingSet, used to describe a Set type.

func (*TypeBuilder) Struct

func (b *TypeBuilder) Struct() PendingStruct

Struct returns PendingStruct, used to describe a Struct type.

func (*TypeBuilder) Union

func (b *TypeBuilder) Union() PendingUnion

Union returns PendingUnion, used to describe a Union type.

type TypeOrPending

type TypeOrPending interface {
	// contains filtered or unexported methods
}

TypeOrPending only allows *Type or Pending values; other values cause a compile-time error. It's used as the argument type for TypeBuilder methods, to allow either fully built *Type values or Pending values as subtypes.

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value is the generic representation of any value expressible in vanadium. All values are typed.

Not all methods apply to all kinds of values. Restrictions are noted in the documentation for each method. Calling a method inappropriate to the kind of value causes a run-time panic.

Cyclic values are not supported. The zero Value is invalid; use Zero or one of the *Value helper functions to create a valid Value.

func AnyValue

func AnyValue(x *Value) *Value

AnyValue is a convenience to create an Any value.

TODO(toddw): Remove this function when we disallow non-nil any.

func BoolValue

func BoolValue(tt *Type, x bool) *Value

BoolValue is a convenience to create a Bool value. If tt is nil, a value of BoolType is returned, otherwise requires tt must be of the Bool kind.

func BytesValue

func BytesValue(tt *Type, x []byte) *Value

BytesValue is a convenience to create a []byte value. The bytes are copied. If tt is nil, a value of ListType(ByteType) is returned, otherwise tt.IsBytes must be true.

func CopyValue

func CopyValue(v *Value) *Value

CopyValue returns a copy of the Value v.

func EnumValue

func EnumValue(tt *Type, index int) *Value

EnumValue is a convenience to create an Enum value. Requires that tt is of the Enum kind.

func FloatValue

func FloatValue(tt *Type, x float64) *Value

FloatValue is a convenience to create a Float32 or Float64 value. Requires that tt is one of those kinds.

func IntValue

func IntValue(tt *Type, x int64) *Value

IntValue is a convenience to create a Int8, Int16, Int32 or Int64 value. Requires that tt is one of those kinds.

func NonNilZeroValue

func NonNilZeroValue(t *Type) *Value

NonNilZeroValue returns a new Value of type t representing the non-nil zero value for t. It is is the same as ZeroValue, except if t is Optional, in which case it returns a Value representing the zero value of the elem type.

Panics if t == nil or t is Any.

func OptionalValue

func OptionalValue(x *Value) *Value

OptionalValue returns an optional value with elem assigned to x. Panics if the type of x cannot be made optional.

func SortValuesAsString

func SortValuesAsString(values []*Value) []*Value

SortValuesAsString sorts values by their String representation. The order of elements in values may be changed, and values is returned; no copy is made.

The ordering is guaranteed to be deterministic within a single executable, but may change across different versions of the code.

Typically used to get a deterministic ordering of set and map keys in tests. Do not depend on the ordering across versions of the code; it will change.

func StringValue

func StringValue(tt *Type, x string) *Value

StringValue is a convenience to create a String value. If tt is nil, a value of StringType is returned, otherwise requires tt must be of the String kind.

func TypeObjectValue

func TypeObjectValue(x *Type) *Value

TypeObjectValue is a convenience to create a TypeObject value.

func UintValue

func UintValue(tt *Type, x uint64) *Value

UintValue is a convenience to create a Byte, Uint16, Uint32 or Uint64 value. Requires that tt is one of those kinds.

func UnionValue

func UnionValue(tt *Type, index int, x *Value) *Value

UnionValue is a convenience to create a Union value. Requires that tt is of the Union kind.

func ValueFromReflect

func ValueFromReflect(rv reflect.Value) (*Value, error)

ValueFromReflect returns the value corresponding to rv.

func ValueOf

func ValueOf(v interface{}) *Value

ValueOf returns the value corresponding to v. It's a helper for calling ValueFromReflect, and panics on any errors.

func ZeroValue

func ZeroValue(t *Type) *Value

ZeroValue returns a new Value of type t representing the zero value for t:

o Bool:       false
o Numbers:    0
o String:     ""
o Enum:       label at index 0
o TypeObject: AnyType
o List:       empty collection
o Set:        empty collection
o Map:        empty collection
o Array:      zero values for all elems
o Struct:     zero values for all fields
o Union:      zero value of the type at index 0
o Any:        nil value, representing nonexistence
o Optional:   nil value, representing nonexistence

Panics if t == nil.

func (*Value) Assign

func (v *Value) Assign(x *Value) *Value

Assign the value v to x. If x is nil, v is set to its zero value. Panics if the type of v is not assignable from the type of x.

TODO(toddw): Remove this method when we disallow non-nil any.

func (*Value) AssignBool

func (v *Value) AssignBool(x bool)

AssignBool assigns the underlying Bool to x.

func (*Value) AssignBytes

func (v *Value) AssignBytes(x []byte)

AssignBytes assigns the underlying []byte or [N]byte to a copy of x. If the underlying value is []byte, the resulting v has len == len(x). If the underlying value is [N]byte, we require len(x) == N, otherwise panics.

func (*Value) AssignEnumIndex

func (v *Value) AssignEnumIndex(index int)

AssignEnumIndex assigns the underlying Enum to the label corresponding to index. Panics if the index is out of range.

func (*Value) AssignEnumLabel

func (v *Value) AssignEnumLabel(label string)

AssignEnumLabel assigns the underlying Enum to the label. Panics if the label doesn't exist in the Enum.

func (*Value) AssignField

func (v *Value) AssignField(index int, value *Value)

AssignField assigns the index'th field of the underlying Struct or Union to value. This chooses the field for union values; if the union value currently represents a different field, or the same field with a different value, it is overwritten. This doesn't affect other fields of struct values. Panics if the index is out of range, or if value isn't assignable to the Struct or Union field type.

func (*Value) AssignFloat

func (v *Value) AssignFloat(x float64)

AssignFloat assigns the underlying Float{32,64} to x.

func (*Value) AssignIndex

func (v *Value) AssignIndex(index int, elem *Value)

AssignIndex assigns the index'th element of the underlying Array or List to elem. Panics if the index is out of range, or if elem isn't assignable to the Array or List element type.

func (*Value) AssignInt

func (v *Value) AssignInt(x int64)

AssignInt assigns the underlying Int{8,16,32,64} to x.

func (*Value) AssignLen

func (v *Value) AssignLen(n int)

AssignLen assigns the length of the underlying List to n. Unlike Go slices, Lists do not have a separate notion of capacity.

func (*Value) AssignMapIndex

func (v *Value) AssignMapIndex(key, elem *Value)

AssignMapIndex assigns the value associated with key to elem in the underlying Map. Panics if key isn't assignable to the Map key type, or if elem isn't assignable to the Map elem type.

func (*Value) AssignSetKey

func (v *Value) AssignSetKey(key *Value)

AssignSetKey assigns key to the underlying Set. Panics if key isn't assignable to the Set key type.

func (*Value) AssignString

func (v *Value) AssignString(x string)

AssignString assigns the underlying String to x.

func (*Value) AssignTypeObject

func (v *Value) AssignTypeObject(x *Type)

AssignTypeObject assigns the underlying TypeObject to x. If x == nil we assign the zero TypeObject.

func (*Value) AssignUint

func (v *Value) AssignUint(x uint64)

AssignUint assigns the underlying Uint{16,32,64} or Byte to x.

func (*Value) Bool

func (v *Value) Bool() bool

Bool returns the underlying value of a Bool.

func (*Value) Bytes

func (v *Value) Bytes() []byte

Bytes returns the underlying value of a []byte or [N]byte. Mutations of the returned value are reflected in the underlying value.

func (*Value) ContainsKey

func (v *Value) ContainsKey(key *Value) bool

ContainsKey returns true iff key is present in the underlying Set or Map.

func (*Value) Decoder

func (vv *Value) Decoder() Decoder

Decoder returns a decoder that traverses vv.

func (*Value) DeleteMapIndex

func (v *Value) DeleteMapIndex(key *Value)

DeleteMapIndex deletes key from the underlying Map. Panics if the key isn't assignable to the Map key type.

func (*Value) DeleteSetKey

func (v *Value) DeleteSetKey(key *Value)

DeleteSetKey deletes key from the underlying Set. Panics if key isn't assignable to the Set key type.

func (*Value) Elem

func (v *Value) Elem() *Value

Elem returns the element value contained in the underlying Any or Optional. Returns nil if v.IsNil() == true.

func (*Value) EnumIndex

func (v *Value) EnumIndex() int

EnumIndex returns the index of the underlying Enum.

func (*Value) EnumLabel

func (v *Value) EnumLabel() string

EnumLabel returns the label of the underlying Enum.

func (*Value) Float

func (v *Value) Float() float64

Float returns the underlying value of a Float{32,64}.

func (*Value) Index

func (v *Value) Index(index int) *Value

Index returns the index'th element of the underlying Array or List. Panics if the index is out of range.

func (*Value) Int

func (v *Value) Int() int64

Int returns the underlying value of an Int{8,16,32,64}.

func (*Value) IsNil

func (v *Value) IsNil() bool

IsNil returns true iff v is Optional or Any and has the nil value.

func (*Value) IsValid

func (v *Value) IsValid() bool

IsValid returns true iff v is valid, where v == nil and v == new(Value) are invalid. Most other methods panic if called on an invalid Value.

func (*Value) IsZero

func (v *Value) IsZero() bool

IsZero returns true iff v is the zero value for its type.

func (*Value) Keys

func (v *Value) Keys() []*Value

Keys returns all keys present in the underlying Set or Map. The returned keys are in an arbitrary order; do not rely on the ordering.

func (*Value) Kind

func (v *Value) Kind() Kind

Kind returns the kind of type of v.

func (*Value) Len

func (v *Value) Len() int

Len returns the length of the underlying Array, List, Set or Map.

func (*Value) MapIndex

func (v *Value) MapIndex(key *Value) *Value

MapIndex returns the value associated with the key in the underlying Map, or nil if the key is not found in the map. Panics if the key isn't assignable to the map's key type.

func (*Value) NonOptional

func (v *Value) NonOptional() *Value

NonOptional returns v.Elem() if v is non-nil Optional, otherwise returns v.

func (*Value) RawString

func (v *Value) RawString() string

RawString returns the underlying value of a String.

func (*Value) String

func (v *Value) String() string

String returns a human-readable representation of the value. To retrieve the underlying value of a String, use RawString.

func (*Value) StructField

func (v *Value) StructField(index int) *Value

StructField returns the Struct field at the given index. Panics if the index is out of range.

func (*Value) StructFieldByName

func (v *Value) StructFieldByName(name string) *Value

StructFieldByName returns the Struct field for the given name. Returns nil if the name given is not one of the struct's fields.

func (*Value) Type

func (v *Value) Type() *Type

Type returns the type of v. All valid values have a non-nil type.

func (*Value) TypeObject

func (v *Value) TypeObject() *Type

TypeObject returns the underlying value of a TypeObject.

func (*Value) Uint

func (v *Value) Uint() uint64

Uint returns the underlying value of a Byte or Uint{16,32,64}.

func (*Value) UnionField

func (v *Value) UnionField() (int, *Value)

UnionField returns the field index and value from the underlying Union.

func (*Value) VDLEqual

func (v *Value) VDLEqual(x interface{}) bool

VDLEqual implements the Equaler interface method.

func (*Value) VDLIsZero

func (v *Value) VDLIsZero() bool

VDLIsZero implements the vdl.IsZeroer interface. Returns true iff v represents any(nil).

TODO(toddw): Describe the subtle difference with IsZero().

func (*Value) VDLRead

func (vv *Value) VDLRead(dec Decoder) error

VDLRead uses dec to decode a value into vv. If vv isn't valid (i.e. has no type), it will be filled in the exact type of value read from the decoder. Otherwise the type of vv must be compatible with the type of the value read from the decoder.

func (*Value) VDLWrite

func (vv *Value) VDLWrite(enc Encoder) error

VDLWrite writes this vdl Value to the encoder.

type WalkMode

type WalkMode int

WalkMode is the mode to perform a Walk through the type graph.

const (
	// WalkAll indicates we should walk through all types in the type graph.
	WalkAll WalkMode = iota
	// WalkInline indicates we should only visit subtypes of array, struct and
	// union.  Values of array, struct and union always include values of their
	// subtypes, thus the subtypes are considered to be inline.  Values of
	// optional, list, set and map might not include values of their subtypes, and
	// are not considered to be inline.
	WalkInline
)

type WireError

type WireError struct {
	Id        string        // Error Id, used to uniquely identify each error.
	RetryCode WireRetryCode // Retry behavior suggested for the receiver.
	Msg       string        // Error message, may be empty.
	ParamList []*Value      // Variadic parameters contained in the error.
}

WireError is the wire representation for the built-in error type. Errors and exceptions in each programming environment are converted to this type to ensure wire compatibility. Generated code for each environment provides automatic conversions into idiomatic native representations.

func (WireError) VDLIsZero

func (x WireError) VDLIsZero() bool

func (*WireError) VDLRead

func (x *WireError) VDLRead(dec Decoder) error

func (WireError) VDLReflect

func (WireError) VDLReflect(struct {
	Name string `vdl:"v.io/v23/vdl.WireError"`
})

func (WireError) VDLWrite

func (x WireError) VDLWrite(enc Encoder) error

type WireRetryCode

type WireRetryCode int

WireRetryCode is the suggested retry behavior for the receiver of an error. If the receiver doesn't know how to handle the specific error, it should attempt the suggested retry behavior.

const (
	WireRetryCodeNoRetry WireRetryCode = iota
	WireRetryCodeRetryConnection
	WireRetryCodeRetryRefetch
	WireRetryCodeRetryBackoff
)

func WireRetryCodeFromString

func WireRetryCodeFromString(label string) (x WireRetryCode, err error)

WireRetryCodeFromString creates a WireRetryCode from a string label.

func (*WireRetryCode) Set

func (x *WireRetryCode) Set(label string) error

Set assigns label to x.

func (WireRetryCode) String

func (x WireRetryCode) String() string

String returns the string label of x.

func (WireRetryCode) VDLIsZero

func (x WireRetryCode) VDLIsZero() bool

func (*WireRetryCode) VDLRead

func (x *WireRetryCode) VDLRead(dec Decoder) error

func (WireRetryCode) VDLReflect

func (WireRetryCode) VDLReflect(struct {
	Name string `vdl:"v.io/v23/vdl.WireRetryCode"`
	Enum struct{ NoRetry, RetryConnection, RetryRefetch, RetryBackoff string }
})

func (WireRetryCode) VDLWrite

func (x WireRetryCode) VDLWrite(enc Encoder) error

type Writer

type Writer interface {
	VDLWrite(enc Encoder) error
}

Writer is the interface that wraps the VDLWrite method.

VDLWrite writes out the receiver that implements this method to the Encoder. This method is auto-generated for all types defined in vdl. It may be implemented for regular Go types not defined in vdl, to customize the encoding.

Directories

Path Synopsis
Package vdltest provides a variety of VDL types and values for testing.
Package vdltest provides a variety of VDL types and values for testing.
internal/vdltestgen
Command vdltestgen generates types and values for the vdltest package.
Command vdltestgen generates types and values for the vdltest package.

Jump to

Keyboard shortcuts

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