| // 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) |
| WireIdComplex64 = typeId(12) |
| WireIdComplex128 = typeId(13) |
| 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 |
| |
| // Control codes for chunked messages. |
| // Chunks in multi-chunk messages begin with one of these values. |
| // Single-chunk messages do not use these control codes and instead begin with a |
| // type id. |
| WireCtrlValueFirstChunk = byte(0xe2) // First chunk in a multi-chunk value message |
| WireCtrlValueChunk = byte(0xe3) // Continuation of a multi-chunk value message |
| WireCtrlValueLastChunk = byte(0xe4) // Final chunk in a multi-chunk value message |
| WireCtrlTypeFirstChunk = byte(0xe5) // First chunk in a multi-chunk type message |
| WireCtrlTypeChunk = byte(0xe6) // Continuation of a multi-chunk type message |
| WireCtrlTypeLastChunk = byte(0xe7) // Final chunk in a multi-chunk type message |
| |
| WireCtrlTypeIncomplete = byte(0xe8) // Marks that the type message is incomplete until future messages are received |
| ) |