blob: aa01a38ada68bb35718cda83542dfeff3223ced7 [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
// Version is the vom version.
type Version byte
const (
Version80 = Version(0x80)
Version81 = Version(0x81)
DefaultVersion = Version81
)
// 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
)