Solved

Type-length-value parsing

Posted on 2011-02-11
7
1,309 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
Comment Utility
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
Comment Utility
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
Comment Utility
upping to 500 points
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 9

Accepted Solution

by:
jhshukla earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now