TryReadValue Method
TryReadValue(out ReadOnlyMemory<Byte>, Int32)
Try to read the TLV at the current position. If this succeeds, return
true and set the value
argument to a new ReadOnlyMemory
object containing the value as a byte array, and move the position to
the byte beyond the current TLV.
public bool TryReadValue(out ReadOnlyMemory<byte> value, int expectedTag)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlyMemory<System.Byte> | value | The output parameter where the value will be deposited. |
System.Int32 | expectedTag | The tag that should be at the current position. |
Returns
A boolean, true
if the read succeeds, false
otherwise.
Remarks
This is the same as ReadValue
, 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
there is not enough data in the buffer for the length given, this
method will return false
.
See the documentation for ReadValue
for more information
on what this method does.
Note that the value returned is a reference to the input encoding. Do not clear or alter the encoding until after the full encoding has been read and each value operated on.