ReadInt32 Method
ReadInt32(Int32, Boolean)
Read the TLV at the current position, return the value as an int (a four-byte integer), and move the position to the byte beyond the current TLV.
public int ReadInt32(int expectedTag, bool bigEndian = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expectedTag | The tag that should be at the current position. |
System.Boolean | bigEndian | Specifies whether the result should be returned as big endian (true or no argument given) or little endian (false). |
Returns
An int, the value.
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 method will verify that the tag is expected. If it is, it will read the length, verify that it is four, then read that four-byte value, and return it as an int.
If the length of the value is not 4 (even if it is 0, 1, 2, or 3), this method will not advance the reader and throw an exception.
The method will return the value in big endian (most significant byte of the int is taken from value[0]), unless the bigEndian argument is false. If it is false, the result is returned in little endian (least significant byte of the int is taken from value[0]). The bigEndian argument has a default of true. This means you can call this method and leave out the bigEndian argument, and the method will return the int in big endian format.
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 not advance the reader and throw an exception.