Solved

Type-length-value parsing

Posted on 2011-02-11
7
1,395 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best prediction based on two lists of numbers  in excel 2 71
JSON  parse help 8 52
DTD and JAVA versions 1 29
Need some help with design 13 13
Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

756 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