§1.4.

Notational Conventions

This document uses the conventions detailed in ([RFC9000], Section 1.3) when describing the binary encoding.

1.4.1. Variable-Length Integers

MoQT requires a variable-length integer encoding with the following properties:

  1. The encoded length can be determined from the first encoded byte.

  2. The range of 1 byte values is as large as possible.

  3. All 64 bit numbers can be encoded.

The variable-length integer encoding uses the number of leading 1 bits of the first byte to indicate the length of the encoding in bytes. The remaining bits after the first 0 and subsequent bytes, if any, represent the integer value, encoded in network byte order.

Integers are encoded in 1, 2, 3, 4, 5, 6, 8, or 9 bytes and can encode up to 64 bit unsigned integers. The following table summarizes the encoding properties.

Table 1: Summary of Integer Encodings
Leading Bits Length (bytes) Usable Bits Range
0 1 7 0-127
10 2 14 0-16383
110 3 21 0-2097151
1110 4 28 0-268435455
11110 5 35 0-34359738367
111110 6 42 0-4398046511103
11111110 8 56 0-72057594037927935
11111111 9 64 0-18446744073709551615

The following table contains some example encodings:

Table 2: Example Integer Encodings
Byte Sequence Decimal Value
0x25 37
0x8025 37
0xbbbd 15,293
0xdd7f3e7d 494,878,333
0xfaa1a0e403d8 2,893,212,287,960
0xfefa318fa8e3ca11 70,423,237,261,249,041
0xffffffffffffffffff 18,446,744,073,709,551,615

11111100 is an invalid code point. An endpoint that receives this value MUST close the session with a PROTOCOL_VIOLATION.

To reduce unnecessary use of bandwidth, variable length integers SHOULD be encoded using the least number of bytes possible to represent the required value.

x (vi64):

Indicates that x holds an integer value using the variable-length encoding as described above.

1.4.2. Location Structure

Location identifies a particular Object in a Group within a Track.

Location {
  Group (vi64),
  Object (vi64)
}
Figure 1: Location structure

In this document, a Location can be expressed in the form of {GroupID, ObjectID}, where GroupID and ObjectID indicate the Group ID and Object ID of the Location, respectively. The constituent parts of any Location A can be referred to using A.Group or A.Object.

Location A < Location B if:

A.Group < B.Group || (A.Group == B.Group && A.Object < B.Object)

1.4.3. Key-Value-Pair Structure

Key-Value-Pair is a flexible structure designed to carry key/value pairs in which the key is a variable length integer and the value is either a variable length integer or a byte field of arbitrary length.

Key-Value-Pairs encode a Type value as a delta from the previous Type value, or from 0 if there is no previous Type value. This is efficient on the wire and makes it easy to ensure there is only one instance of a type when needed. The previous Type value plus the Delta Type MUST NOT be greater than 2^64 - 1. If a Delta Type is received that would be too large, the Session MUST be closed with a PROTOCOL_VIOLATION.

Key-Value-Pair is used in both the data plane and control plane, but is optimized for use in the data plane.

Key-Value-Pair {
  Delta Type (vi64),
  [Length (vi64),]
  Value (..)
}
Figure 2: MOQT Key-Value-Pair
  • Delta Type: an unsigned integer, encoded as a varint, identifying the Type as a delta encoded value from the previous Type, if any. The Type identifies the type of value and also the subsequent serialization.

  • Length: Only present when Type is odd. Specifies the length of the Value field in bytes. The maximum length of a value is 2^16-1 bytes. If an endpoint receives a length larger than the maximum, it MUST close the session with a PROTOCOL_VIOLATION.

  • Value: A single varint encoded value when Type is even, otherwise a sequence of Length bytes.

If a receiver understands a Type, and the following Value or Length/Value does not match the serialization defined by that Type, the receiver MUST close the session with error code KEY_VALUE_FORMATTING_ERROR.

1.4.4. Reason Phrase Structure

Reason Phrase provides a way for the sender to encode additional diagnostic information about the error condition, where appropriate.

Reason Phrase {
  Reason Phrase Length (vi64),
  Reason Phrase Value (..)
}
  • Reason Phrase Length: A variable-length integer specifying the length of the reason phrase in bytes. The reason phrase length has a maximum value of 1024 bytes. If an endpoint receives a length exceeding the maximum, it MUST close the session with a PROTOCOL_VIOLATION

  • Reason Phrase Value: Additional diagnostic information about the error condition. The reason phrase value is encoded as UTF-8 string and does not carry information, such as language tags, that would aid comprehension by any entity other than the one that created the text.

This is one section of the MoQT specification, rendered per-section for quick reference and citation. The authoritative text is draft-ietf-moq-transport-17 at the IETF.