PlainTLV
Project: PlainTLV | |
---|---|
Status | voltooid |
Betrokkenen | |
Kennisgebied(en) | Python
|
Afgeleide projecten | SpaceAnnounce |
Projectoverzicht – Project toevoegen |
PlainTLV is een Type/Length/Value dialect. Het voordeel van TLV is dat het uitermate simpel en snel te verwerken (en genereren) is. Dit komt omdat het veldlengtes specificeert ipv data te scheiden door afgesproken tekens. Dit betekent ook dat er geen escaping plaats hoeft te vinden van scheidingstekens, deze zijn er immers niet. PlainTLV heeft als verdere eigenschap dat de syntax zelf volledig in leesbare tekst gedaan wordt, wat het leerproces vergemakkelijkt.
PlainTLV will be a plaintext TLV dialect. The general benefits of TLV are that is it extremely easy to parse and generate, requiring only simple forward reads, and very little state tracking. Also, there is no need for escaping any content, since there are no actual delimiters.
Regularly, TLV is a binary format, and while this certainly has benefits of being a lot smaller in byte size, the drawback of that is that it is significantly less readable. PlainTLV will be in plaintext, and providing a few extra handholds for (human) readability.
Basic format
The basic format for a TLV item will be:
{{ type }} {{ length }} {{ separator }} {{ value }}
- There will be no delimiters between the fields named above (the spaces are for readability only).
- The type field will be a single alpha character. #Types are specified below.
- The length field will be variable length and should contain only digits. This field will end upon reading the separator value.
- The separator will be the colon (:)
- The value field will be either raw data, or a number of elements that the current type consists of (in case of dictionaries or lists). A length of zero will effectively mean that this field does not exist (or does exist with zero length, to be precise)
- N.B. Multiple TLV items will be placed after one another without spaces or other delimiters.
Types
PlainTLV in its current design has support for most Python types:
- Scalars
- i: The integer type.
- f: The float type.
- s: The string type.
- u: The unicode type. The value will be decoded from UTF8 encoding.
- n: The None type. The length field for this is ignored (and need not be specified)
- Iterables
- l: The list type. The length field specifies the number of items in the list.
- d: The dictionary type. The length field specifies the number of key/value pairs.