Solved

Type-length-value parsing

Posted on 2011-02-11
7
1,366 Views
Last Modified: 2012-05-11
Hi, I have to design a C++ class that can be used for parsing and generating Type-length-value messages.

All I can find that is useful is this link:
http://en.wikipedia.org/wiki/Type-length-value

It is not very helpful.

Can someone explain a little bit more about TLV messages and with some good simpke examples.


For example:
command_c/4/makeCall_c/phoneNumberToCall_c/8/"722-4246"

1. What does the first 4 mean???
2. Can there be any number of e.g. command_c types for different systems??
0
Comment
Question by:curiouskid
7 Comments
 
LVL 9

Assisted Solution

by:jhshukla
jhshukla earned 500 total points
ID: 34876852
1.
a. command_c is the type of the message. The number of bytes occupied by this token is always constant. Otherwise you would run into a lot of trouble.
b. 4 is the number of bytes occupied by the next token -- makeCall_c. It is an enum taking up 4 bytes. Once you recognize makeCall_c token, you may be able to figure out how much more you need to read.
c. The next piece tells you that callee phone number follows.
d. It is 8 bytes long
e. The number to call.

2. Yes.

===
Instead of trying to solve how you will parse a message, think how you would serialize a message so that it is easily parsable. You will either arrive at TLV scheme or end up with paradigm-shifting research material.
0
 

Author Comment

by:curiouskid
ID: 34877371
re:Once you recognize makeCall_c token, you may be able to figure out how much more you need to read.

So if I read makeCall_c then I should know that what follows is always phoneNumberToCall_c??
Is this rule defined somewhere in code??

i.e if I get a certin token then I will look up somewhere to see what token I should get next???
0
 

Author Comment

by:curiouskid
ID: 34878967
upping to 500 points
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 9

Accepted Solution

by:
jhshukla earned 500 total points
ID: 34879262
For now, yes. The rule is defined in the code. There are two approaches:
1. Some kind of lookup table where you can find what should be the next token.
2. Call a function for parsing makeCall_c message.

In the long term, no.

The easy approach is to assume that the following token is always phoneNumberToCall_c and there is nothing [i.e. end of message] after that. But you will lose flexibility. Say you want to include extension later. you will have to rewrite your parser. Seems like that is not you concern at the moment.

Once you have this working you can try to perform more complex parsing. e.g., you would
1. read the token,
2. find that it is phoneNumberToCall_c (could be something else. you will have to account for unexpected types as well).
3. start parsing for phoneNumberToCall_c,
4. finish parsing for phoneNumberToCall_c,
5. go to 1. Repeat till end of message.

you will also have to keep track of what values you have already read. If, for instance, phoneNumberToCall_c appears more than once, you have to decide what you will do -- throw exception, overwrite old value with latest one, keep the oldest one.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34879270
So if I read makeCall_c then I should know that what follows is always phoneNumberToCall_c??
Is this rule defined somewhere in code??

i.e if I get a certin token then I will look up somewhere to see what token I should get next???

Right. Whatever code is supposed to parse this data will know what to look for. Remember TLV is just a format or template for how to structure the data. The actual way the data is used is dependent on the application using it.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 36275157
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question