TLV format

TLV format

TLV is a way of storing data to facilitate quick parsing of that data.

Its mainly used in transffering data in binary format in network communications.Simple exa,ple is using it in Payment Controller POS where POS will act as a transmitter and Server will be acting as a receiver.

Typically, you read the type(tag), length and value and then send those datum to a processor function. This processor functions only function will be to process type X. Then, you read the next type, it’s length and value and send it to the appropriate processor.

It’s typically used as an easy way to process data without a lot of extra overhead.

T = Tag/Type , 2 Byte hex value

L = Length , 2 Byte hex value

V = Value, L ASCII characters.


The first field is the “type” of data being processed, the second field specifies the “length” of the value, the third field contains a “length” amount of data representing the value for the “type”.

Multiple pieces of data can be transmitted in the same message by appending more triplets to a previously existing message.

Each triplet is a “top level” description, there is typically no nesting of items in TLV (although you could come up with a way to do so by encoding TLV triplets in the V of another tag).

The pros of this format is that it’s a dead simple format (easy to parse, you can skip new added fields in old programs).It’s a relatively compact encoding format.It’s relatively simple to parse you can write  a basic X.690 parser in a couple of hours).The X.690 TLV has support for nested types

TLV’s biggest disadvantage is that it is not directly human readable. Note however if the data is converted to hex it is only moderately difficult to read.Further, cons are that it’s a dead simple format (no built-in hierarchy support, encodes binary poorly, data type must be known to both sides beforehand or transmitted in some custom-encoded way, very poor support for when the data changes over time are not additive but are substitutions, etc). Some of these cons are fixable, like you can encode binary to transmit it, but that’s just more work to de-encode on the other end.

We use TLV for data formatting. And if we want to send data to receiver in binary form, we prepare a TLV package that is contain Tag-Length-Value datas. For example;
Data Tag = DF 82 0A
Data Length = 03
Data Value = 30 31 32.
when we want to send it we concatenate this 3 row datas like DF 82 0A 03 30 31 32. Data packages can contain lots of datas like that.

When receiver get it, parsing package is very easy and receiver can parse all of data smoothly.

Related article:

Parser code for TLV format

Resolving technical problems:

Solve your technical problems instantly

We provide Remote Technical Support from Monday to Sunday, 7:00PM to 1:00 AM

Mail your problem details at [email protected] along with your mobile numberand we will give you a call for further details. We usually attend your problems within 60 minutes and solve it in maximum 2 days.

One thought on “TLV format”

  1. You have to extract all tags and subtags from the following string(i.e in TLV format) and store in some data
    [email protected]0A0000005240135biv

    Tag Breakup (TLV):
    tag0 2 01
    tag1 2 12
    tag2 16 4725001000000012
    tag4 15 526550000000001
    tag6 16 6100090000000031
    tag8 23 ABCD0001238123801519337
    tag26 35 [email protected]
    subtag0 10 A000000524 subtag1 10 [email protected] subtag2 3 1.0
    tag27 72 subtag0 10
    subtag1 35 bivek123456789012345678901234552013
    subtag2 15
    tag28 30 0010A0000005240112703080939644 subtag0 10 A000000524
    subtag1 12 703080939644
    tag52 4 5411
    tag53 3 356
    tag54 3 2.0
    tag58 2 IN
    tag59 10 Bivek Rath
    tag60 6 MUMBAI
    tag61 6 400067
    tag62 41 0203***0403***0603***0708000000030804test
    subtag2 3 ***

Comments are closed.