PlainTLV

From Frack - Hackerspace Friesland
Jump to navigationJump to search
Project: PlainTLV
NoProjectPicture.jpg
Status voltooid
Betrokkenen
Gebruiker Elmer.jpg Elmer
Gebruiker Elmer.jpgElmer de Looff (Elmer) Rol: niet-deelnemer Deskundig met: Arduino, ENC28J60, Elektronica, GnuCash, HTML, LPD8806, Linux, MediaWiki, Mercurial, Netwerken, OpenVPN, Programmeren, Python, SSH, Software, Solderen Beginnend met: Dm-crypt, Javascript Werkt aan: Geen projecten :(
Kennisgebied(en) Python
Afgeleide projecten SpaceAnnounce
ProjectoverzichtProject 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
    1. i: The integer type.
    2. f: The float type.
    3. s: The string type.
    4. u: The unicode type. The value will be decoded from UTF8 encoding.
    5. n: The None type. The length field for this is ignored (and need not be specified)
  • Iterables
    1. l: The list type. The length field specifies the number of items in the list.
    2. d: The dictionary type. The length field specifies the number of key/value pairs.