Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7653769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:06:30+00:00 2026-05-31T12:06:30+00:00

I am decoding an array of bytes which are in TLV format (Tag-Length-Value). Sometimes

  • 0

I am decoding an array of bytes which are in TLV format (Tag-Length-Value). Sometimes the Length of a Value is infinite. i.e I have to read the succeeding bytes until I get to two consequent zero bytes meaning the end of Value. The problem is when the Value of a TLV is itself constructed of another TLV with infinite Length. I am trying to figure out the best way to decode such TLVs with nested infinite values.

In the following example, each square indicates one byte. After reading L1, I realize that the length of V1 is infinite, which means that I have to read the succeeding bytes until I get to two zero bytes. But the first two zero bytes after L1 indicate the end of V3, not V1:

                                V3                            
                                .                             
                                |             end of V2       
                                \            -----------
+----+----+----+----+----+----+----+----+----+----+----+----+----+
| T1 | L1 | T2 | L2 | T3 | L3 | 13 | 0  | 0  | 0  | 0  | 0  | 0  |
+----+----/----+----/----+----/----+----+----+----+----+----+----+
          |         |         |    -----------         -----------
          |         |         |    end of V3           end of V1
          \         |         |
    V1 Starts here  |         |
                    |         |
                    \         |
              V2 Starts here  |
                              |
                              \
                        V3 starts here 

I need a method/algorithm to detect the end of V1. Any advice would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:06:31+00:00Added an answer on May 31, 2026 at 12:06 pm

    A simple approach is to use a recursive function: each time the function reads until it finds two double zeros, and then returns that position, so that the previous invocation knows where to continue looking for its own double zero terminator.

    Alternatively, you could track the nesting level with an integer: increase each time you start reading a new TLV, decrease it when it finds a double zero. The reading is over when the nesting level is zero again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Ruby have an equivalent to .NET's Encoding.ASCII.GetString(byte[]) ? Encoding.ASCII.GetString(bytes[]) takes an array of
I have an array of bytes that has come from a barcode reader (connected
I have an array of names which I am reading in from a mysql
I have a .NET string which is Base64 encoded representation of an array of
I have a script on one server which is posting a json array to
While decoding,I am getting NSData bytes by decoding a string.I am converting NSData bytes
I have problems decoding several Chars. In the Database, the Chars Ä, Ö and
I am reading up about Encoding and Decoding and I noticed that sometimes people
I have to send a byte array (encoded photo) from my PHP client to
While working on decoding some video streaming standards I have noticed a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.