Documentation ¶
Overview ¶
XDR Abstract Syntax Tree definition - a binary interchange format for XDR specifications
Index ¶
- Constants
- type Attribute
- type Attributes
- type Constant
- type ConstantKind
- type Declaration
- type DeclarationModifier
- type Declaration_Modifier
- type Definition
- type DefinitionKind
- type Definition_Body
- type EnumSpec
- type EnumSpec_Options
- type Specification
- type StructSpec
- type Type
- type TypeKind
- type UnionSpec
- type UnionSpec_Options
Constants ¶
const XDR_BIN_MAGIC = 0x895844520D0A1A0A
Binary magic: the `magic` field of the `specification` should be set to this value
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
An attribute of an object
type Attributes ¶
A set of attributes
func (Attributes) GetString ¶
func (as Attributes) GetString(name string) string
GetString attempts to look up the named attribute as a string, or returns the empty string
func (Attributes) GetStringDefault ¶
func (as Attributes) GetStringDefault(name, def string) string
GetStringDefault attempts to look up the named attribute as a string, or returns the specified default
type Constant ¶
type Constant struct { Type ConstantKind `json:"type"` VBool bool `json:"v_bool,omitempty"` VPosInt uint64 `json:"v_pos_int,omitempty"` VNegInt uint64 `json:"v_neg_int,omitempty"` VFloat float64 `json:"v_float,omitempty"` VString string `json:"v_string,omitempty"` VEnum uint32 `json:"v_enum,omitempty"` }
Constant is union constant
func (*Constant) AsU32 ¶
AsU32 attempts to reinterpret a constant as an unsigned 32-bit number
type ConstantKind ¶
type ConstantKind uint32
Type of a constant. These are a subset of XDR types
const ( CONST_BOOL ConstantKind = 0 CONST_POS_INT ConstantKind = 1 CONST_NEG_INT ConstantKind = 2 CONST_FLOAT ConstantKind = 3 CONST_STRING ConstantKind = 4 CONST_ENUM ConstantKind = 5 )
func (ConstantKind) MarshalText ¶
func (v ConstantKind) MarshalText() ([]byte, error)
func (ConstantKind) String ¶
func (v ConstantKind) String() string
func (*ConstantKind) UnmarshalText ¶
func (v *ConstantKind) UnmarshalText(buf []byte) error
func (ConstantKind) ValidEnum ¶
func (_ ConstantKind) ValidEnum(v int32) bool
type Declaration ¶
type Declaration struct { // Type of the field Type *Type `json:"type"` // Name of the field Name string `json:"name"` // Modifier of the type Modifier *Declaration_Modifier `json:"modifier"` // Field attributes Attributes Attributes `json:"attributes"` }
Field declaration
func (*Declaration) Equal ¶
func (l *Declaration) Equal(r *Declaration) bool
Equal returns if two declarations are equal
func (*Declaration) IsVoid ¶
func (d *Declaration) IsVoid() bool
IsVoid returns if this is a void (empty) declaration
type DeclarationModifier ¶
type DeclarationModifier uint32
How a declaration modifies its type
const ( DECLARATION_MODIFIER_NONE DeclarationModifier = 0 DECLARATION_MODIFIER_OPTIONAL DeclarationModifier = 1 DECLARATION_MODIFIER_FIXED DeclarationModifier = 2 DECLARATION_MODIFIER_FLEXIBLE DeclarationModifier = 3 DECLARATION_MODIFIER_UNBOUNDED DeclarationModifier = 5 )
func (DeclarationModifier) MarshalText ¶
func (v DeclarationModifier) MarshalText() ([]byte, error)
func (DeclarationModifier) String ¶
func (v DeclarationModifier) String() string
func (*DeclarationModifier) UnmarshalText ¶
func (v *DeclarationModifier) UnmarshalText(buf []byte) error
func (DeclarationModifier) ValidEnum ¶
func (_ DeclarationModifier) ValidEnum(v int32) bool
type Declaration_Modifier ¶
type Declaration_Modifier struct { Kind DeclarationModifier `json:"kind"` Size uint32 `json:"size,omitempty"` }
Modifier of the type
func (*Declaration_Modifier) ArmForSwitch ¶
func (u *Declaration_Modifier) ArmForSwitch(sw uint32) (string, bool)
func (*Declaration_Modifier) SwitchFieldName ¶
func (u *Declaration_Modifier) SwitchFieldName() string
func (*Declaration_Modifier) UnionDiscriminant ¶
func (u *Declaration_Modifier) UnionDiscriminant() interface{}
func (*Declaration_Modifier) UnionValue ¶
func (u *Declaration_Modifier) UnionValue() (interface{}, error)
type Definition ¶
type Definition struct { // The name of the definition Name string `json:"name"` // The attributes of the definition Attributes Attributes `json:"attributes"` Body *Definition_Body `json:"body"` }
A top-level definition
type DefinitionKind ¶
type DefinitionKind uint32
The kind of a definition
const ( DEFINITION_KIND_TYPE DefinitionKind = 0 DEFINITION_KIND_CONSTANT DefinitionKind = 1 )
func (DefinitionKind) MarshalText ¶
func (v DefinitionKind) MarshalText() ([]byte, error)
func (DefinitionKind) String ¶
func (v DefinitionKind) String() string
func (*DefinitionKind) UnmarshalText ¶
func (v *DefinitionKind) UnmarshalText(buf []byte) error
func (DefinitionKind) ValidEnum ¶
func (_ DefinitionKind) ValidEnum(v int32) bool
type Definition_Body ¶
type Definition_Body struct { Kind DefinitionKind `json:"kind"` // Body, for type definitions Type *Type `json:"type,omitempty"` // Body, for constant definitions Constant *Constant `json:"constant,omitempty"` }
Definition_Body is union definition.body
func (*Definition_Body) ArmForSwitch ¶
func (u *Definition_Body) ArmForSwitch(sw uint32) (string, bool)
func (*Definition_Body) SwitchFieldName ¶
func (u *Definition_Body) SwitchFieldName() string
func (*Definition_Body) UnionDiscriminant ¶
func (u *Definition_Body) UnionDiscriminant() interface{}
func (*Definition_Body) UnionValue ¶
func (u *Definition_Body) UnionValue() (interface{}, error)
type EnumSpec ¶
type EnumSpec struct { // Set of all options Options []*EnumSpec_Options `json:"options"` }
Definition of an enum
func (*EnumSpec) GetName ¶
GetName returns the canonical (first) name for the specified numeric value
type EnumSpec_Options ¶
type EnumSpec_Options struct { // Name of the enumerant Name string `json:"name"` // Value of the enumerant Value uint32 `json:"value"` }
Set of all options
type Specification ¶
type Specification struct { // Magic number: set to XDR_BIN_MAGIC Magic uint64 `json:"magic"` // Spec attributes (set using pragma directives) Attributes Attributes `json:"attributes"` // List of all definitions Definitions []*Definition `json:"definitions"` }
Root object of a specification
func (*Specification) GetConstant ¶
func (s *Specification) GetConstant(n string) (*Constant, error)
GetConstant looks up the named constant, returning an error if it is not found
func (*Specification) GetType ¶
func (s *Specification) GetType(n string) (*Type, error)
GetType looks up the named type, returning an error if it is not found
func (*Specification) NamedDefinition ¶
func (s *Specification) NamedDefinition(n string) *Definition
NamedDefinition looks for a definition with the specified name
func (*Specification) PutDefinition ¶
func (s *Specification) PutDefinition(d *Definition) error
PutDefinition appends a definition with the speicifed name, if it would not conflict with one which already exists
type StructSpec ¶
type StructSpec struct { // Set of struct members Members []*Declaration `json:"members"` }
Definition of an enum
func (*StructSpec) HasMember ¶
func (ss *StructSpec) HasMember(name string) bool
HasMember returns if a named member exists
type Type ¶
type Type struct { Kind TypeKind `json:"kind"` EnumSpec *EnumSpec `json:"enum_spec,omitempty"` StructSpec *StructSpec `json:"struct_spec,omitempty"` UnionSpec *UnionSpec `json:"union_spec,omitempty"` Ref string `json:"ref,omitempty"` TypeDef *Declaration `json:"type_def,omitempty"` }
Definition of a type
func Ref ¶
Ref returns a type which is a reference to the specified name
func (*Type) Resolve ¶
func (t *Type) Resolve(s *Specification) (*Type, error)
Resolve attempts to resolve a TYPE_REF into the underlying type, by looking at the passed specification
type TypeKind ¶
type TypeKind uint32
The kind of the type
const ( TYPE_VOID TypeKind = 0 TYPE_BOOL TypeKind = 1 TYPE_INT TypeKind = 2 TYPE_UNSIGNED_INT TypeKind = 3 TYPE_HYPER TypeKind = 4 TYPE_UNSIGNED_HYPER TypeKind = 5 TYPE_FLOAT TypeKind = 6 TYPE_DOUBLE TypeKind = 7 TYPE_STRING TypeKind = 8 TYPE_OPAQUE TypeKind = 9 TYPE_ENUM TypeKind = 10 TYPE_STRUCT TypeKind = 11 TYPE_UNION TypeKind = 12 TYPE_REF TypeKind = 13 TYPE_TYPEDEF TypeKind = 14 )
type UnionSpec ¶
type UnionSpec struct { // Discriminant field Discriminant *Declaration `json:"discriminant"` // Set of union member fields Members []*Declaration `json:"members"` // Mapping from values to union member. `member` is the index of the member in `members` Options map[uint32]uint32 `json:"options"` // If a default member is present, defines it DefaultMember *uint32 `xdr:"opt" json:"default_member,omitempty"` }
Definition of a union
func (*UnionSpec) GetMember ¶
func (us *UnionSpec) GetMember(name string) (uint32, *Declaration)
GetMember returns the member with the specified name, and its index, if it exists
func (*UnionSpec) HasMember ¶
HasMember returns if a member is already defined with the specified name