TryReadUInt16 Method
TryReadUInt16(out UInt16, Int32, Boolean)
Try to read the TLV at the current position. If this succeeds, return
true and set the value
argument to the unsigned short that is the
V part of the TLV, and move the position to the byte beyond the current TLV.
public bool TryReadUInt16(out ushort value, int expectedTag, bool bigEndian = true)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | value | The output parameter where the value will be deposited. |
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 boolean, true
if the read succeeds, false
otherwise.
Remarks
This is the same as ReadUInt16(Int32, Boolean), except this method
will not throw an exception if there is an error in reading, only return
false
. That is, if the expected tag is not found at the
current position, or the length octets are not a valid encoding, or
the value is not exactly two bytes, or there is not enough data in
the buffer for the length given, this method will set value
to
0 and will return false
.
See ReadUInt16(Int32, Boolean) for more information on what this method does.
Note that if there is a valid TLV with the expected tag, but the
length is not 2, this method will return false
.