Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TLV: type-length-value

Status
Not open for further replies.

zemp

Programmer
Jan 27, 2002
3,301
CA
TLV, type-length-value or Type length encoded.
VB6 SP6

I am looking for an example or documentation to turn a recordset (or any collection of string values) into a TLV string of data. Any links to docs or samples would be appreciated.

Here is what I need:
<total record size byte 1><total record size byte 2><field type 1><field lengh 1><field data><field type 2><field length 2><field data 2>....etc

0x0 0x49 0x1 0x8 Address1 0x2 0x8 Address2 0x3 0x8 Address3 0x4 0x8 Address4 0x5 0x8 Address5 0x6 0x4 City 0x7 0x6 Postal 0x8 0x8 Province 0x9 0x7 Country 0xA 0x8 Currency

FYI, I have searched the net and countless sites with no luck using the criteia in the first line of this thread. Even if you could suggest better criteria that would be great.

Thanks



zemp
 
typically, recordsets are built of records, records are built from fields. fields, in a database, are of defined type, and types -with the exception of string (Text and Memo for Jet and most relational dbs) have a defined length, which is easily retrieved from the db documentation. even text fields have a 'defined' length, however it is possible that the content is less than the defined length.

on the other hand, if you want the displayed length of a field, each value MAY have a different length, even in different formats, so the only wat to obtain that value would be to evaluate the field as it is/will be displayed.

other than these generalities, i do not quite undestand the question

MichaelRed


 
Basically I need to convert a byte array (from the strings) into a binary file.

Basically the same functionality as the C# snipet below but in VB6.

Code:
int getLengthInt(byte[] b) {
    return (((int)b[0]) & 0xFF) << 8 | ((int)b[1]) & 0xFF;
}
 
byte[] getLengthArray(int size) {
    byte[] b = new byte[2];
    b[0] = (size >> 8) & 0xFF;
    b[1] = size & 0xFF;
}

zemp
 
This is a pretty simple "tag and length" format. Normally I see it with "tag" values that are field IDs, but here you want a "type" code instead. Seems simple enough.

The conversions of a length into a 16-bit unsigned value in 2 bytes is easy enough. Just code it the same as in the C# samples, using multiply by 256 for left-shift by 8 bits and integer divide by 256 for right-shift. Since VB5/6 have no unsigned integers you'll want to use a Long for these record lengths to get a full 16 bits of precision.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top