ASN1C C# Runtime Library  7.4
Public Member Functions | Properties | List of all members
Asn1PerOutputStream Class Reference
Inheritance diagram for Asn1PerOutputStream:
Asn1OutputStream

Public Member Functions

virtual void AddCaptureBuffer (System.IO.MemoryStream buffer)
 
 Asn1PerOutputStream (System.IO.Stream os, bool aligned)
 
 Asn1PerOutputStream (System.IO.Stream os, int bufSize, bool aligned)
 
virtual void BinDump (System.String varName)
 
virtual void BinDump (System.IO.StreamWriter outs, System.String varName)
 
virtual void ByteAlign ()
 
override void Close ()
 
virtual void EncodeBit (bool value)
 
virtual void EncodeBit (bool value, System.String ident)
 
virtual void EncodeBits (byte value, int nbits)
 
virtual void EncodeBits (byte[] value, int offset, int nbits)
 
virtual void EncodeBits (byte[] value, int offset, int nbits, System.String ident)
 
virtual void EncodeCharString (System.String value, int nchars, int offset, int abpc, int ubpc, Asn1CharSet charSet)
 
virtual void EncodeConsWholeNumber (long adjustedValue, long rangeValue, System.String ident)
 
virtual void EncodeConsWholeNumber (long adjustedValue, long rangeValue)
 
virtual void EncodeInt (long value, int nbits, System.String ident)
 
virtual void EncodeInt (long value, int nbits)
 
virtual void EncodeInt (long value, bool encodeLen, bool signExtend, System.String ident)
 
virtual void EncodeInt (long value, bool encodeLen, bool signExtend)
 
virtual long EncodeLength (long value)
 
virtual void EncodeLength (long value, long lower, long upper)
 
virtual void EncodeLengthEOM (long value)
 
virtual void EncodeOctetString (byte[] value, int offset, int nbytes)
 
virtual void EncodeOIDLengthAndValue (int[] value)
 
virtual void EncodeOpenType (byte[] value, int offset, int nbytes)
 
virtual void EncodeRelOIDLengthAndValue (int[] value)
 
virtual void EncodeSmallLength (int value)
 
virtual void EncodeSmallNonNegWholeNumber (int value)
 
override void Flush ()
 
virtual void RemoveCaptureBuffer (System.IO.MemoryStream buffer)
 
override void Write (byte[] b)
 
override void Write (System.Byte[] b, int off, int len)
 
override void WriteByte (int b)
 
override void WriteByte (byte b)
 
- Public Member Functions inherited from Asn1OutputStream
 Asn1OutputStream (System.IO.Stream os)
 
override void Close ()
 
override void Flush ()
 
override int Read (byte[] buffer, int offset, int count)
 
override long Seek (long offset, System.IO.SeekOrigin origin)
 
override void SetLength (long value)
 
override void Write (System.Byte[] b, int off, int len)
 
void Write2Bytes (int value)
 
void Write4Bytes (int value)
 
override void WriteByte (byte b)
 

Properties

virtual bool Aligned [get]
 
virtual Asn1PerTraceHandler TraceHandler [get]
 
- Properties inherited from Asn1OutputStream
override bool CanRead [get]
 
override bool CanSeek [get]
 
override bool CanWrite [get]
 
Asn1Context Context [get]
 
override long Length [get]
 
override long Position [get, set]
 

Detailed Description

This class handles the output stream for encoding of ASN.1 messages as specified in the Packed Encoding Rules (PER) ITU-T X.691 standard.

Constructor & Destructor Documentation

◆ Asn1PerOutputStream() [1/2]

Asn1PerOutputStream ( System.IO.Stream  os,
bool  aligned 
)

This constructor creates a buffered PER output stream object with the default size of buffer. Whenever the buffer becomes full, the buffer will be flushed to the stream.

Parameters
osThe underlying System.IO.Stream object.
alignedIndicates whether PER aligned or unaligned encoding should be done.

◆ Asn1PerOutputStream() [2/2]

Asn1PerOutputStream ( System.IO.Stream  os,
int  bufSize,
bool  aligned 
)

This constructor creates a buffered PER output stream object with the specified size of buffer. Whenever the buffer becomes full, the buffer will be flushed to the stream.

Parameters
osThe underlying System.IO.Stream object.
bufSizeThe buffer size.
alignedtrue for PER aligned or false for PER unaligned encoding.

Member Function Documentation

◆ AddCaptureBuffer()

virtual void AddCaptureBuffer ( System.IO.MemoryStream  buffer)
virtual

This method is used to add a capture buffer to the internal capture buffer list. A capture buffer is used to capture all bytes read from this position forward from the input stream.

Parameters
bufferBuffer into which captured bytes are to be stored

Referenced by Asn1PerOutputStreamTraceHandler.Enable().

◆ BinDump() [1/2]

virtual void BinDump ( System.String  varName)
virtual

This method invokes an overloaded version of BinDump to dump the encoded message to standard output.

Parameters
varNameName of top-level message object variable

◆ BinDump() [2/2]

virtual void BinDump ( System.IO.StreamWriter  outs,
System.String  varName 
)
virtual

This method dumps the encoded message in a human-readable format showing a bit trace of all fields to the given print output stream.

Parameters
outsStreamWriter object to which output should be written
varNameName of top-level message object variable

References Asn1PerOutputStreamTraceHandler.Print().

◆ ByteAlign()

virtual void ByteAlign ( )
virtual

This methods byte-aligns the buffer.

References Asn1PerEncodeBuffer.ByteAlign().

◆ Close()

override void Close ( )

Close the stream. Writes all bytes (even unfinished) before closing. Throws, exception thrown by the underlying System.IO.Stream object.

References Asn1PerEncodeBuffer.EncodeBits(), Asn1PerMessageBuffer.MsgBitCnt, and Asn1PerEncodeBuffer.Reset().

◆ EncodeBit() [1/2]

virtual void EncodeBit ( bool  value)
virtual

This method encodes a single bit value.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueBoolean value of bit to be encoded.
Exceptions
Asn1ExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeBit().

◆ EncodeBit() [2/2]

virtual void EncodeBit ( bool  value,
System.String  ident 
)
virtual

This method encodes a single bit value.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueBoolean value of bit to be encoded.
identBit field identifier name for tracing.
Exceptions
Asn1ExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeBit().

◆ EncodeBits() [1/3]

virtual void EncodeBits ( byte  value,
int  nbits 
)
virtual

This method encodes bit values from an octet. The most significant bits from the octet are encoded.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueOctet containing bits to be encoded
nbitsNumber of bits to encode
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeBits().

◆ EncodeBits() [2/3]

virtual void EncodeBits ( byte []  value,
int  offset,
int  nbits 
)
virtual

This method encodes bit values from an array of octets.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueOctet array containing bits to be encoded
offsetStarting byte offset in value
nbitsNumber of bits to encode
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeBits().

◆ EncodeBits() [3/3]

virtual void EncodeBits ( byte []  value,
int  offset,
int  nbits,
System.String  ident 
)
virtual

This method encodes bit values from an array of octets.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueOctet array containing bits to be encoded
offsetStarting byte offset in value
nbitsNumber of bits to encode
identBit field identifier name for tracing.
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeBits().

◆ EncodeCharString()

virtual void EncodeCharString ( System.String  value,
int  nchars,
int  offset,
int  abpc,
int  ubpc,
Asn1CharSet  charSet 
)
virtual

This method encodes the contents of a known-multiplier character string type. This version assumes a permitted alphabet constraint was specified.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueString containing characters to encode
ncharsNumber of characters from string to encode
offsetOffset to first char in string to encode
abpcNumber of bits per character (aligned)
ubpcNumber of bits per character (unaligned)
charSetObject representing permitted alphabet constraint character set (optional)
Exceptions
Asn1ExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeCharString().

◆ EncodeConsWholeNumber() [1/2]

virtual void EncodeConsWholeNumber ( long  adjustedValue,
long  rangeValue,
System.String  ident 
)
virtual

This method implements the rules to encode a constrained whole number as specified in section 10.5 of the X.691 standard.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
adjustedValueAdjusted value to be encoded = value - lower range endpoint value
rangeValuelower - upper + 1
identBit field identifier name for tracing.
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeConsWholeNumber().

◆ EncodeConsWholeNumber() [2/2]

virtual void EncodeConsWholeNumber ( long  adjustedValue,
long  rangeValue 
)
virtual

This method implements the rules to encode a constrained whole number as specified in section 10.5 of the X.691 standard.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
adjustedValueAdjusted value to be encoded = value - lower range endpoint value
rangeValuelower - upper + 1
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeConsWholeNumber().

◆ EncodeInt() [1/4]

virtual void EncodeInt ( long  value,
int  nbits,
System.String  ident 
)
virtual

This method encodes bit values from an integer value. The least significant bits from the integer are encoded.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueInteger containing bits to be encoded
nbitsNumber of bits to encode
identBit field identifier name for tracing.
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeInt().

◆ EncodeInt() [2/4]

virtual void EncodeInt ( long  value,
int  nbits 
)
virtual

This method encodes bit values from an integer value. The least significant bits from the integer are encoded.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueInteger containing bits to be encoded
nbitsNumber of bits to encode
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeInt().

◆ EncodeInt() [3/4]

virtual void EncodeInt ( long  value,
bool  encodeLen,
bool  signExtend,
System.String  ident 
)
virtual

This method implements the rules to encode either a non-negative binary integer as specified in section 10.3 or a two's complement binary integer as specified in section 10.4 of the X.691 standard.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueInteger value to be encoded
encodeLenFlag indicating length determinant should be encoded before encoding integer value.
signExtendFlag indicating if sign extension should be performed.
identBit field identifier name for tracing.
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeInt().

◆ EncodeInt() [4/4]

virtual void EncodeInt ( long  value,
bool  encodeLen,
bool  signExtend 
)
virtual

This method implements the rules to encode either a non-negative binary integer as specified in section 10.3 or a two's complement binary integer as specified in section 10.4 of the X.691 standard.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueInteger value to be encoded
encodeLenFlag indicating length determinant should be encoded before encoding integer value.
signExtendFlag indicating if sign extension should be performed.
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeInt().

◆ EncodeLength() [1/2]

virtual long EncodeLength ( long  value)
virtual

This method encodes a general (unconstrained) length determinant value as described in section 10.9 or the X.691 standard.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueLength value to be encoded
Returns
Value that was actually encoded. This may be less than the value that was passed in if fragementation was done (i.e the value was >= 16k).
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeLength().

◆ EncodeLength() [2/2]

virtual void EncodeLength ( long  value,
long  lower,
long  upper 
)
virtual

This method encodes a constrained length determinant value.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueLength value to be encoded
lowerLower bound (inclusive) of length value range
upperUpper bound (inclusive) of length value range
Exceptions
Asn1ExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeLength().

◆ EncodeLengthEOM()

virtual void EncodeLengthEOM ( long  value)
virtual

This method checks to see if a zero byte needs to be added after a fragmented length has been encoded. It will add it to the byte stream if necessary.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueOriginal length value that was encoded.
Exceptions
Asn1ExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeLengthEOM().

◆ EncodeOctetString()

virtual void EncodeOctetString ( byte []  value,
int  offset,
int  nbytes 
)
virtual

This method encodes the given array of bytes as an unconstrained octet string value.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueByte array containing data to encode. This is assumed to contain a previously encoded PER component.
offsetStarting offset in byte array value
nbytesNumber of bytes to encode
Exceptions
Asn1ExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeOctetString().

◆ EncodeOIDLengthAndValue()

virtual void EncodeOIDLengthAndValue ( int []  value)
virtual

This method encodes the length and contents of an object identifier value.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueInteger array containing arcs to encode
Exceptions
Asn1ExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeOIDLengthAndValue().

Referenced by Asn1ObjectIdentifier.ToString().

◆ EncodeOpenType()

virtual void EncodeOpenType ( byte []  value,
int  offset,
int  nbytes 
)
virtual

This method encodes the given array of bytes as an open type.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueByte array containing data to encode. This is assumed to contain a previously encoded PER component.
offsetStarting offset in byte array value
nbytesNumber of bytes to encode
Exceptions
Asn1ExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeOpenType().

Referenced by Asn1ChoiceExt.Encode(), and Asn1OpenType.ToString().

◆ EncodeRelOIDLengthAndValue()

virtual void EncodeRelOIDLengthAndValue ( int []  value)
virtual

This method encodes the length and contents of a relative object identifier value.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueInteger array containing arcs to encode
Exceptions
Asn1ExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeRelOIDLengthAndValue().

Referenced by Asn1RelativeOID.DecodeXML().

◆ EncodeSmallLength()

virtual void EncodeSmallLength ( int  value)
virtual

This method implements the rules to encode a normally small length as specified in section 11.9 of the X.691 standard.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueValue to be encoded
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeSmallLength().

◆ EncodeSmallNonNegWholeNumber()

virtual void EncodeSmallNonNegWholeNumber ( int  value)
virtual

This method implements the rules to encode a small non-negative whole number as specified in section 10.6 of the X.691 standard.

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
valueValue to be encoded
Exceptions
Asn1InvalidArgExceptionAny exception thrown by the underlying Asn1PerEncodeBuffer.

References Asn1PerEncodeBuffer.EncodeSmallNonNegWholeNumber().

◆ Flush()

override void Flush ( )

Flush the buffer to the stream. It writes whole bytes only. Throws, exception thrown by the underlying System.IO.Stream object.

◆ RemoveCaptureBuffer()

virtual void RemoveCaptureBuffer ( System.IO.MemoryStream  buffer)
virtual

This method is used to remove a capture buffer from the internal capture buffer list. The add and remove methods can be used to get a set of raw bytes from the input stream for further processing.

Parameters
bufferBuffer in which captured bytes stored

◆ Write() [1/2]

override void Write ( byte []  b)
virtual

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call Write(b, 0, b.length).

Parameters
bthe binary data.
Exceptions
System.SystemExceptionif an I/O error occurs.

Reimplemented from Asn1OutputStream.

◆ Write() [2/2]

override void Write ( System.Byte []  b,
int  off,
int  len 
)

Writes len bytes from the specified byte array to this output stream.

Parameters
bthe data.
offThe offset in array at which to begin write.
lenThe number of bytes to write.
Exceptions
System.SystemExceptionif an I/O error occurs. In particular, write call after the the output stream is closed.

◆ WriteByte() [1/2]

override void WriteByte ( int  b)
virtual

Writes the specified byte to this output stream.

Parameters
bthe byte.
Exceptions
System.SystemExceptionif an I/O error occurs. In particular, an write call after the output stream has been closed.

Reimplemented from Asn1OutputStream.

◆ WriteByte() [2/2]

override void WriteByte ( byte  b)

Writes the specified byte to this output stream.

Parameters
bthe byte.
Exceptions
System.SystemExceptionif an I/O error occurs. In particular, an write call after the output stream has been closed.

Property Documentation

◆ Aligned

virtual bool Aligned
get

Gets PER aligned encoding has been specified.

Value: true is aligned; otherwise false

◆ TraceHandler

virtual Asn1PerTraceHandler TraceHandler
get

Gets a reference to the internal trace handler object used to trace the bit fields within a PER message.

Value: Asn1PerTraceHandler object