AsnDecoder.TryReadBitString Method

Definition

Attempts to copy a Bit String value from source with a specified tag under the specified encoding rules into destination.

public static bool TryReadBitString (ReadOnlySpan<byte> source, Span<byte> destination, System.Formats.Asn1.AsnEncodingRules ruleSet, out int unusedBitCount, out int bytesConsumed, out int bytesWritten, System.Formats.Asn1.Asn1Tag? expectedTag = default);
static member TryReadBitString : ReadOnlySpan<byte> * Span<byte> * System.Formats.Asn1.AsnEncodingRules * int * int * int * Nullable<System.Formats.Asn1.Asn1Tag> -> bool
Public Shared Function TryReadBitString (source As ReadOnlySpan(Of Byte), destination As Span(Of Byte), ruleSet As AsnEncodingRules, ByRef unusedBitCount As Integer, ByRef bytesConsumed As Integer, ByRef bytesWritten As Integer, Optional expectedTag As Nullable(Of Asn1Tag) = Nothing) As Boolean

Parameters

source
ReadOnlySpan<Byte>

The buffer containing encoded data.

destination
Span<Byte>

The buffer in which to write.

ruleSet
AsnEncodingRules

The encoding constraints to use when interpreting the data.

unusedBitCount
Int32

On success, receives the number of bits in the last byte which were reported as "unused" by the writer. This parameter is treated as uninitialized.

bytesConsumed
Int32

When this method returns, the total number of bytes for the encoded value. This parameter is treated as uninitialized.

bytesWritten
Int32

When this method returns, the total number of bytes written to destination. This parameter is treated as uninitialized.

expectedTag
Nullable<Asn1Tag>

The tag to check for before reading, or null for the default tag (Universal 3).

Returns

true if destination is large enough to receive the value of the Bit String; otherwise, false.

Exceptions

ruleSet is not defined.

The next value does not have the correct tag.

-or-

The length encoding is not valid under the current encoding rules.

-or-

The contents are not valid under the current encoding rules.

expectedTag.TagClass is Universal, but expectedTag.TagValue is not correct for the method.

-or-

destination overlaps source.

Remarks

The least significant bits in the last byte which are reported as "unused" by the unusedBitCount value will be copied into destination as unset bits, irrespective of their value in the encoded representation.

Applies to