ReadInt16 Method
ReadInt16(Int32, Boolean)
Read the TLV at the current position, return the value as a short (a two-byte integer), and move the position to the byte beyond the current TLV.
public short ReadInt16(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
A short, 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 two, then read that two-byte value, and return it as a short.
If the length of the value is not 2 (even if it is 0 or 1), 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 short 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 short 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 short 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.