I've never heard of the TLV, but I have worked with KLV (Key-Length-Value).
What I recommend that you do is define your own class to represent the data. Something like:
Code:
class Metadata
{
public:
...
Type type;
ValLength length;
Value value;
};
Above, the
Type and
ValLength represent enumerated values that are used to describe the
Value. For example, for stats concerning an airplane:
Code:
enum Type
{
FUEL_REMAINING,
AIR_SPEED,
ALTITUDE,
etc
};
enum ValLength
{
BYTE, UBYTE, SHORT, USHORT, LONG, ULONG, LONGLONG, ULONGLONG, STRING
};
The "tricky" part is the data, or Value. It can be defined as a union of various types; for example:
Code:
struct Value
{
typedef union
{
// signed types
char sbyte;
short sshort;
int slong;
longlong slonglong;
// add unsigned counterparts, if you need them.
char cstr[127];
} Data;
Data data;
};
In conclusion, with the simple code above, you can identify a value (measurement) using [Type, ValLength, Value]. Thus if you wanted to create a Metadata object using FUEL_REMAINING, SHORT, and 43000, you would set the appropriate fields of the Metadata object like:
Code:
type = FUEL_REMAINING;
length = SHORT;
value.data.sshort = 43000;
You could consider associating with the Metadata class functions for serializing and de-serializing the object, similar to what was described in the Wiki page, or you could consider making a binary stream of the object data, thus compacting it for better storage or transmission to a remote server.
There's lots more information that I could discuss, but for now I'll leave it for you to discover how "easy" TLV (or KLV) really is.