BTIC CTLV

BTIC Compact TLV:

Design Ideas:
 * Partly based on the BTIC1C TLV
 * May incorporate ASN.1 BER like encodings.
 * Supports message compression.
 * Only parts relevant to a given format need to be supported by the decoder.
 * An encoder need not assume sane handling of additional features.

BTE Message Protocol

Basic Tagging (BTIC)
A subset will be used in BTIC and BTAC codec families. Tags beyond these are unlikely to be understood.

Special Tag Bytes:
 * 0xE0: End-Of-Image Marker (BTIC/BTAC)
 * 0xE1: len=Word24, Image Data (BTIC/BTAC)
 * 0xE2: len=Byte, Image Data (BTIC/BTAC)
 * 0xE3: len=Word24, tag=TWOCC
 * 0xE4: len=Word24, tag=FOURCC
 * 0xE5: len=Byte, tag=TWOCC
 * 0xE6: len=Word56, tag=FOURCC

Tag Byte
ccct-tttt
 * ccc=Tag Class
 * 0=Public Primitive
 * Data directly follows tag (no length).
 * 1=Public Composite
 * Length follows, with this many bytes following.
 * 2=Private Primitive
 * 3=Private Composite
 * 4=Context Primitive
 * 5=Context Composite
 * 6=Reserved
 * 7=Special Encoding
 * ttttt=Tag (For classes 0-3)
 * 0-30=Tag is encoded directly.
 * 31=Tag is escaped (VLIE coded tag follows).

Public Tags:
 * Have a meaning which is built into the TLV format.
 * Always Decodable

Private Tags:
 * Meaning depends on the format.
 * Should be decodable anywhere within a given format.

Context Tags:
 * Meaning depends on where they appear.
 * Decoding requires understanding the tag.

Primitive vs Composite:
 * Primitive tags consist of a tag directly followed by raw data.
 * Decoding requires understanding the tag.
 * Composite tags will consist of a tag followed by a length and data.
 * May be possible to skip tags.

Special Tag Bytes:
 * 0xE0: End-Of-Data Marker, Context Specific
 * 0xE1: len=Word24, Context-Specific Data
 * 0xE2: len=Byte, Context-Specific Data
 * 0xE3: len=Word24, tag=TWOCC
 * 0xE4: len=Word24, tag=FOURCC
 * 0xE5: len=Byte, tag=TWOCC
 * 0xE6: len=Word56, tag=FOURCC
 * 0xE7, len:WORD24, tag:EIGHTCC
 * 0xE8, len:WORD24, tag:SIXTEENCC
 * 0xE9, len:Word56, tag:EIGHTCC
 * 0xEA, len:WORD56, tag:SIXTEENCC
 * 0xEB: len=Byte, tag=FOURCC
 * 0xEC-0xEE=Reserved
 * 0xEF: Sync Marker
 * 0xEF, Hash=Word24, E3-EA ...
 * 0xF0-0xFE=Reserved
 * 0xFF: Magic Tag-Escape Byte
 * Used with escape-coded data.

SIXTEENCC markers may be either a SIXTEENCC or a GUID. Bit patterns will distinguish them (as GUID and SIXTEENCC use incompatible bit patterns).

Tags (TC=0/1):
 * 0=EOL (TC=0)
 * Lone Tag, No Data
 * Terminates a list or object.
 * 1=Bool / (Literal Small Value) (TC=0)
 * Byte Follows, 0=False, 1=True, 2-255=Reserved
 * 2=Int (SVLIE)
 * 3=Bit Array
 * Same as byte-array
 * First byte gives the mod-8 size of the array.
 * 4=Byte Array (TC=1)
 * Encodes a raw collection of bytes.
 * 5=Null (TC=0)
 * 6=UUID (128-bit UUID)
 * 9=Float (TC=0)
 * Floating point number
 * Encoded as an SVLIE Pair
 * 12=String (TC=0)
 * Null Terminated UTF-8 String.

Sync Marker
The sync marker is intended to allow synchronizing with a message stream. This marker would then be used to highlight points for the decoder to synchronize with the stream and begin decoding. This is only intended for use at the top-level, and payload data should not include this marker.

Form:
 * EF HH HH HH E3-EA ...
 * Hash Includes:
 * The sync marker, with the hash field initialized to 'BTE'.
 * Alternate initial values may be used for non-matching syncs.
 * A sync will not match if different initial values are assumed.
 * The following TLV marker.

Hash: cs=data; cse=data+len; hash=0; while(cs>8;

FOURCC Conventions
Case will be significant:
 * 'ABCD': Public, Must understand.
 * 'abcd': Private/Optional
 * First letter: Public / private;
 * Second letter: Must Understand / optional.
 * Third/Fourth letter:
 * If third letter case==first letter.
 * Fourth is ignored.
 * If third letter case!=first letter
 * Fourth means Primitive/composite.
 * Composite tags contain a list of other tags.

For TWOCC tags, only the first 2 letters are significant.

VLIE
VLIE
 * 0xxx-xxxx
 * 0-127
 * 10xx-xxxx
 * Special (Escape)
 * 0=Null/Undefined, Indefinite Length
 * 110x-xxxx xxxx-xxxx
 * Two-Byte Form (0-8191)
 * 1110-xxxx xxxx-xxxx xxxx-xxxx
 * Three-Byte Form (8192-1M)

SVLIE
 * VLIE with sign folded into LSB
 * 0, -1, 1, -2, 2, ...

VLIE is used for tag and length values.

FVLIE
 * Exponent:SVLIE
 * Fraction:SVLIE
 * Value encoded as Fraction*(2.0^Exponent)
 * If Exponent is Null, Fraction encodes special values:
 * 0=+NaN, -1=-NaN, 1=Inf, -2=-Inf