Show / Hide Table of Contents

ReadNestedTlv Method

ReadNestedTlv(int)

Read the TLV at the current position as a NestedTlv. Return a new TlvReader object whose position is the beginning of the NestedTlv's value, which is the tag of the NestedTlv's first sub-element. Move the position of the original reader to the byte beyond the current TLV.

C#
public TlvReader ReadNestedTlv(int expectedTag)

Parameters

Type Name Description
int expectedTag

The tag that should be at the current position, the NestedTlv's tag.

Returns

TlvReader

A new TlvReader object that contains the sub-elements of the NestedTlv, with the position set at the first sub-element.

Exceptions

Type Condition
TlvException

The tag was not the expected value, the tag or length is unsupported, or there was not enough data for the lengths given.

Remarks

The new object returned will contain the encoding of the sub-elements only.

If the tag at the current position in the encoding is not what was given as the expectedTag, or if the tag and/or length make up an invalid encoding, or if there are not enough bytes left in the encoding to read the tag, length, and value, this method will throw an exception.

For example, suppose the encoding is the following.

7C 0D 01 01 14 02 02 01 80 05 04 00 89 2C 33
This is a NestedTlv
7C 0D
   01 01
      14
   02 02
      01 80
   05 04
      00 89 2C 33
Suppose the internal position is at 0, the beginning of full encoding.
TlvReader newReader = reader.ReadNestedTlv(0x7C);
 This will return a new TlvReader object:
  new reader: 01 01 14 02 02 01 80 05 04 00 89 2C 33
              ^
              +--current position
 After the call, the internal position of the original reader is at
 the position just after the NestedTlv's value.
  original: 7C 0D 01 01 14 02 02 01 80 05 04 00 89 2C 33
                                                         ^
                                                         +--current position
Suppose the original reader is parsing something like this:
  01 01 14 7A 07 31 02 01 00 32 01 20 05 04 00 89 2C 33
This is a concatenation with a NestedTlv as one of the elements.
     01 01
        14
     7A 07
        31 02
           01 00
        32 01
           20
     05 04
        00 89 2C 33
Suppose the internal position is at 0, the beginning of full encoding.
ReadOnlyMemory<byte> value = reader.ReadValue(0x01);
 This returned a new ReadOnlyMemory object with the contents of the
 first TLV, namely the byte array { 0x14 }. It moved the pointer to
 the next TLV.
 01 01 14 7A 07 31 02 01 00 32 01 20 05 04 00 89 2C 33
          ^
          +--current position
TlvReader newReader = reader.ReadNestedTlv(0x7A);
 This will return a new TlvReader object:
  new reader: 31 02 01 00 32 01 20
              ^
              +--current position
 After the call, the internal position of the original reader is at
 the position just after the NestedTlv's value.
 01 01 14 7A 07 31 02 01 00 32 01 20 05 04 00 89 2C 33
                                     ^
                                     +--current position
In this article
Back to top Generated by DocFX