Aztec® Programming Language
Version 1.1 Alpha 2

Copyright © 2010-2017, Aztec Development Group, All Rights Reserved

Download Aztec

Search        Contact Us

That was then... this is now.

Don't ask me to be Mr. Clean... baby I don't know how.

- Gregg Allman

 

aztec.io.MemoryStream

public class MemoryStream from<StreamIO>

Base

StreamIO

MemoryStream

The MemoryStream class provides binary stream I/O for memory buffers, which can grow dynamically as needed. It provides an internal pointer position within the buffer where the next read or write operation will occur. It supports direct access, so the pointer position can be manually moved around to read or write anywhere within the memory buffer. Each read and write operation also advances the pointer position by the size of the read/write operation..

MemoryStream Methods

MemoryStream() Constructor for the MemoryStream class
Size() Returns the current size of the binary memory buffer
BytesAvailable() Virtual method to return the number of bytes available to read before end of buffer
Pos() Virtual method to return the current position within the memory buffer
SetPos() Virtual method to set the current position within the memory buffer
DirectAccess() Virtual method to return true since Direct Access I/O is available for memory buffers
EndOfStream() Virtual method to return true if currently at end of stream
Clear() Clears some or all of current contents of (writable) memory buffer and sets position to end of stream
Encrypt() Encrypts the memory buffer with optional user keys
Decrypt() Decrypts the (previously encrypted) memory buffer with optional user keys
Read() Virtual method to read a single 8 byte integer from the memory buffer
Read() Virtual method to read a single "small" integer from the memory buffer (1, 2 or 4 bytes)
Read() Virtual method to read a single float from the memory buffer (4 or 8 bytes)
Read() Virtual method to read a text string from the memory buffer (default length or specific length)
Read() Virtual method to read a boolean from the memory buffer
Read() Virtual method to read a binary buffer (stream) from the memory buffer
Write() Virtual method to write a single 8 byte integer to the memory buffer
Write() Virtual method to write a single "small" integer to the memory buffer (1, 2 or 4 bytes)
Write() Virtual method to write a single float to the memory buffer (4 or 8 bytes)
Write() Virtual method to write a single text string (default or specific length) to the memory buffer
Write() Virtual method to write a single boolean to the memory buffer
Write() Virtual method to write a binary buffer (stream) to the memory buffer

Derived Classes

See Also

 


MemoryStream()

public method MemoryStream(int IOMode = StreamIO.ReadWriteMode, int BufferSize = 32767)

Parameters

IOMode

Indicates type of I/O which is valid (Write or ReadWrite)

BufferSize

Initial size of the INTERNAL memory buffer

Return Value

None

Description

Constructor for the MemoryStream class. The I/O mode (WriteMode or ReadWriteMode) is specified along with the initial INTERNAL size of the memory buffer. This buffer size can increase as needed when data is written to it. Note that the internal memory buffer size is NOT typically the same as the value returned by the Size() method or BytesAvailable() method. These methods apply to the actual data which has been written into the memory buffer, not the maximum internal size of the buffer which contains the data written into this stream. The MemoryStream object comes out of this constructor with an empty buffer, thus a "Size()" of zero and "BytesAvailable()" of zero.

 

The default I/O mode for memory buffers is ReadWriteMode.

 

MemoryStream Class


Size()

public virtual method<int> Size()

Parameters

None

Return Value

Number of bytes in memory buffer

Description

Returns the total number of bytes currentlly in the memory buffer, accounting for all stream I/O already performed into the buffer..

 

MemoryStream Class


BytesAvailable()

public virtual method<int> BytesAvailable()

Parameters

None

Return Value

Number of bytes available to read

Description

Returns the number of bytes available to read from the memory buffer. It is based on the current pointer position and the total size of the buffer.

 

MemoryStream Class


Pos()

public virtual method<int> Pos()

Parameters

None

Return Value

Current read/write pointer position

Description

Virtual method to return the current pointer position within the memory buffer (one based). The next read or write operation takes place at this position.

 

MemoryStream Class


SetPos()

public virtual method<bool> SetPos(int PointerPosition)

Parameters

PointerPosition

One based position in stream to read/write

Return Value

true if successful

Description

Virtual method to set the current read/write pointer position with the memory buffer (one based). The next read or write operation will take place at this position.

 

MemoryStream Class


DirectAccess()

public virtual method<bool> DirectAccess()

Parameters

None

Return Value

Returns true

Description

Virtual method to return the direct access mode, which is always 'true' for memory buffers.

 

MemoryStream Class


EndOfStream()

public virtual method<bool> EndOfStream()

Parameters

None

Return Value

Returns true if at end of stream

Description

Virtual method to return the value of the "end of stream" flag. If there are no bytes available in the memory buffer to read, this method returns true and false if there are one or more bytes available to read.

 

MemoryStream Class


Clear()

public method Clear(int Position = 1)

Parameters

Position

One based starting position for clear operation

Return Value

None

Description

Method to clear the contents of the memory buffer and reset the current position to the end of the remaining buffer. If position is one (default), it clears the entire contents of the buffer. If the stream is specified as "Read", this method will fire a StreamException.

 

MemoryStream Class


Encrypt()

public method Encrypt(int ApplicationKey = 0)

Parameters

ApplicationKey

Key that the caller of the method can pass in to further protect the contents (default of 0)

Return Value

None

Description

This instance method performs an internal encryption process on the memory buffer. It encrypts from the current buffer position to the end of the buffer. Therefore, it is important that the caller set the correct position within the memory buffer before it is encrypted and then subsequently when it is decrypted.

 

Encryption is performed by an internal algorithm that is not RSA compatible, and Aztec Development Group does not guarantee its effectiveness. It is not intended for use with highly secret encryption requirements such as might be needed for military or government applications. This method is simply intended for situations where it is useful or necessary to prevent those who could potentially see the data from quickly knowing its contents. It would likely take an encryption expert a reasonable amount of time to break the code generated by the multi-level internal algorithm, and it would be mostly unbreakable by someone who is not an expert.

 

In addition to the internal default encryption which is performed, the user can optionally pass in an application key. The method performs further processing on the memory buffer given the application key, and it helps to protect the contents of the buffer further. The encrypted buffer cannot be successfully decrypted unless that same key is used.

 

MemoryStream Class


Decrypt()

public method Decrypt(int ApplicationKey = 0)

Parameters

ApplicationKey

Key that the caller of the method can pass in to decrypt the string (default of 0)

Return Value

None

Description

This instance method performs an internal decryption process on the memory buffer (that has presumably already been encrypted using the same key that was passed in). It decrypts from the current buffer position to the end of the buffer. Therefore, it is important that the caller set the correct position within the memory buffer before it is decrypted to match the same buffer position as when it was encrypted. It is also important that the same application key be used for decryption that was used for the original encryption process of this buffer.

 

Encryption is performed by an internal algorithm that is not RSA compatible, and Aztec Development Group does not guarantee its effectiveness. It is not intended for use with highly secret encryption requirements such as might be needed for military or government applications. This method is simply intended for situations where it is useful or necessary to prevent those who could potentially see the data from quickly knowing its contents. It would likely take an encryption expert a reasonable amount of time to break the code generated by the multi-level internal algorithm, and it would be mostly unbreakable by someone who is not an expert.

 

In addition to the internal default encryption which is performed, the user can optionally pass in an application key. The method performs further processing on the memory buffer given the application key, and it helps to protect the contents of the buffer further. The encrypted buffer cannot be successfully decrypted unless that same key is used.

 

MemoryStream Class


Read()

public virtual method Read(int ref IntBucket, bool PeekOnly = false)

Parameters

IntBucket

Integer reference to receive the value

PeekOnly

If true, peek without reading/removing

Return Value

None

Description

Virtual method to read a single binary 8 byte integer value from the memory stream and copy the value into the IntBucket.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

MemoryStream Class


Read()

public virtual method Read(int ref IntBucket, SmallInt IntSizeEnum, bool IsSigned = true, bool PeekOnly = false)

Parameters

IntBucket

Integer reference to receive the value

IntSizeEnum

Enumeration to indicate 1, 2 or 4 byte integer

IsSigned

Treat as signed integer If true, and unsigned if false (default is false)

PeekOnly

Peek without reading/removing if true (default is false)

Return Value

None

Description

Virtual method to read a single "small" binary integer value from the memory stream and copy the value into the IntBucket. The size of the integer read operation is specified by IntSizeEnum, and represents 1, 2 or 4 bytes. The "IsSigned" flag is also used to affect how the binary integer buffer is interpreted, signed or unsiged.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

MemoryStream Class


Read()

public virtual method Read(float ref FloatBucket, bool Read32BitFloat = false, bool PeekOnly = false)

Parameters

FloatBucket

Float reference to receive the value

Read32BitFloat

Read 32 bit (4 byte) float if true (default is false)

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a single binary floating point value from the memory buffer and copy the value into the FloatBucket. The default size of the float read operation is 8 bytes, but can be changed to 4 bytes by setting the "Read32BitFloat" flag. If the "PeekOnly" flag is true, the value is read but the buffer pointer position is not advanced, so the next read operation will read the same data.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

MemoryStream Class


Read()

public virtual method Read(string ref StringBucket, bool ExtractLength = true, int ReadSize = 0, bool PeekOnly = false)

Parameters

StringBucket

String reference to receive the value

ExtractLength

Read the string length from the stream if true

ReadSize

Size of the read operation if ExtractLength is false

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a single string from the memory buffer and copy the value into the StringBucket. This supports reading a variable length string, and there are two ways of handling this. If the "ExtractLength" flag is true, the size of the string is actually read from the buffer (as a 4 byte integer) and then the string read operation is dictacted by that size. If the "ExtractLength" flag is false, the "ReadSize" value is then used to dictate the length of the string to be read.

 

If the "PeekOnly" flag is true, the value is read but the buffer pointer position is not advanced, so the next read operation will read the same data.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

MemoryStream Class


Read()

public virtual method Read(bool ref BoolBucket, bool PeekOnly = false)

Parameters

BoolBucket

Boolean reference to receive the value

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a single binary boolean value from the memory buffer and copy the value into the BoolBucket. It is read as a one byte value. If the "PeekOnly" flag is true, the value is read but the buffer pointer position is not advanced, so the next read operation will read the same data.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

MemoryStream Class


Read()

public virtual method Read(StreamIO StreamBucket, int ReadSize = 0, bool PeekOnly = false)

Parameters

StreamBucket

Stream reference to receive the data

ReadSize

Size of the binary read operation

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a binary block of data from the memory buffer and write it into the target stream (StreamBucket). The size of the read operation is specified. If the target stream supports "random access", the data is written at the current pointer position within that target stream. If the "PeekOnly" flag is true, the value is read but the buffer pointer position is not advanced, so the next read operation will read the same data.

 

If the ReadSize is specified as zero, the read operation goes all the way to the end of this stream.

 

If the stream is specified as "WriteMode", this method will fire a StreamException.

 

MemoryStream Class


Write()

public virtual method Write(int Value)

Parameters

Value

Integer value to be written

Return Value

None

Description

Virtual method to write a single 8 byte binary integer value to the memory stream.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

MemoryStream Class


Write()

public virtual method Write(int Value, SmallInt IntSizeEnum)

Parameters

Value

Integer value to be written

IntSizeEnum

Enumeration to indicate 1, 2 or 4 byte integer

Return Value

None

Description

Virtual method to write a single "small" binary integer value to the memory stream. The size of the integer write operation is specified by IntSizeEnum, and represents 1, 2 or 4 bytes. The integer value must fit within one of the two valid ranges for the integer size that was specified. For each integer size, there is a valid "signed" range and a separate value "unsigned" range. Refer to the 'int' class documention for more details.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

MemoryStream Class


Write()

public virtual method Write(float Value, bool Write32BitFloat = false)

Parameters

Value

Float value to be written

Write32BitFloat

Write 32 bit (4 byte) float if true (default is false)

Return Value

None

Description

Virtual method to write a single binary floating point value to the memory buffer. The default size of the float write operation is 8 bytes, but can be changed to 4 bytes by setting the "Write32BitFloat" flag. If the "Write32BitFlag" is set, the floating point value must fit within the valid range for a 4 byte float. Refer to the 'float' class documention for more details.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

MemoryStream Class


Write()

public virtual method Write(string Value, bool EmbedLength = true, int OverrideLength = 0)

Parameters

Value

String value to be written to stream

EmbedLength

If true, embed string length into stream before the string

OverrideLength

Override length for string to be written

Return Value

None

Description

Virtual method to write a single string to the memory buffer. If the "EmbedLength" flag is true, the length of the string is embedded in the buffer before the text string itself (as a 4 byte integer). By default, the entire string is written to the buffer, but if "OverrideLength" is greater than zero, then the override length will be used instead.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

MemoryStream Class


Write()

public virtual method Write(bool Value)

Parameters

Value

Boolean value to be written

Return Value

None

Description

Virtual method to write a single binary boolean value to the memory buffer. It is written as a one byte integer value repesenting the enumeration index.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

MemoryStream Class


Write()

public virtual method Write(StreamIO SourceStream, int WriteSize = 0)

Parameters

SourceStream

Source stream reference

WriteSize

Size of the binary write operation

Return Value

None

Description

Virtual method to read a binary block of data from the source stream and write it into this memory buffer. The size of the read and write operation is specified by "WriteSize". If the source stream supports "random access", the data is read from the current pointer position within that source stream and then written into this buffer (at current buffer pointer position). If the WriteSize is specified as zero, the read operation from the source stream goes all the way to the end of that stream.

 

If the stream is specified as "ReadMode", this method will fire a StreamException.

 

MemoryStream Class

 

Copyright © 2010-2017

Aztec Development Group

All Rights Reserved

Download Aztec