?
Solved

Type-length-value parsing

Posted on 2011-02-11
7
Medium Priority
?
1,485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 9

Assisted Solution

by:jhshukla
jhshukla earned 2000 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
Technology Partners: 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 2000 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 101

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

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

801 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