Solved

Type-length-value parsing

Posted on 2011-02-11
7
1,437 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 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
Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

 
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 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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

687 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