blob: 560841a7bd778a7b2ca8a2a29770b1d4548e6c7f [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vom
// Built-in type Ids
const (
// Primitive types.
WireIdBool = typeId(1)
WireIdByte = typeId(2)
WireIdString = typeId(3)
WireIdUint16 = typeId(4)
WireIdUint32 = typeId(5)
WireIdUint64 = typeId(6)
WireIdInt16 = typeId(7)
WireIdInt32 = typeId(8)
WireIdInt64 = typeId(9)
WireIdFloat32 = typeId(10)
WireIdFloat64 = typeId(11)
// Wire ids 12 and 13 were previously used for complex64 and complex 128.
WireIdTypeObject = typeId(14)
WireIdAny = typeId(15)
WireIdInt8 = typeId(16)
// Other commonly used composites.
WireIdByteList = typeId(39)
WireIdStringList = typeId(40)
// The first user-defined typeId is 41.
WireIdFirstUserType = typeId(41)
)
// typeId uniquely identifies a type definition within a vom stream.
type typeId uint64
// The wireType union is used to encode the payload part of each type message,
// using the regular rules for encoding union values. But unlike our regular
// encoding, the type message for wireType itself (and its fields) are never
// encoded; we need to bootstrap the system. Thus unlike regular values, the
// ordering of fields within the wire* types cannot be changed.
type wireType union {
// FIELD INDICES MUST NOT BE CHANGED.
NamedT wireNamed // INDEX = 0
EnumT wireEnum // INDEX = 1
ArrayT wireArray // INDEX = 2
ListT wireList // INDEX = 3
SetT wireSet // INDEX = 4
MapT wireMap // INDEX = 5
StructT wireStruct // INDEX = 6
UnionT wireUnion // INDEX = 7
OptionalT wireOptional // INDEX = 8
}
// wireNamed represents a type definition for named primitives.
type wireNamed struct {
Name string
Base typeId
}
// wireEnum represents an type definition for enum types.
type wireEnum struct {
Name string
Labels []string
}
// wireArray represents an type definition for array types.
type wireArray struct {
Name string
Elem typeId
Len uint64
}
// wireList represents a type definition for list types.
type wireList struct {
Name string
Elem typeId
}
// wireSet represents a type definition for set types.
type wireSet struct {
Name string
Key typeId
}
// wireMap represents a type definition for map types.
type wireMap struct {
Name string
Key typeId
Elem typeId
}
// wireField represents a field in a struct or union type.
type wireField struct {
Name string
Type typeId
}
// wireStruct represents a type definition for struct types.
type wireStruct struct {
Name string
Fields []wireField
}
// wireUnion represents a type definition for union types.
type wireUnion struct {
Name string
Fields []wireField
}
// wireOptional represents an type definition for optional types.
type wireOptional struct {
Name string
Elem typeId
}
// Control codes used in VOM wire format
//
// region 1: 0x80...0xBF (64 entries)
// region 2: 0xC0...0xDF (32 entries)
// region 3: 0xE0...0xEF (16 entries)
const (
WireCtrlNil = byte(0xe0) // Nil in optional or any
WireCtrlEnd = byte(0xe1) // End of struct or union
WireCtrlTypeIncomplete = byte(0xe2) // Marks that the type message is incomplete until future messages are received
)