ByteStream

Object represents stream of bytes

Instance attributes

eos: bool

Indicates, if current position is in the end of byte stream

pos: int

Current position in the byte stream

size: int

Size of byte stream in bytes

Instance methods

seek(position): int

Change current position in byte stream.

Table 1. Parameters

position

Integer

Position to seek to

Return

Actual position if position change was successful or -1 if position change was not successful.

readByte(): int (32 bit)

Read byte from byte stream and return it’s value.

readInt16B(): int (32 bit)

Read big-endian 16-bit signed integer from byte stream and return it’s value.

readInt32B(): int (32 bit)

Read big-endian 32-bit signed integer from byte stream and return it’s value.

readInt64B(): int (64 bit)

Read big-endian 64-bit signed integer from byte stream and return it’s value.

readUInt16B(): int (32 bit)

Read big-endian 16-bit unsigned integer from byte stream and return it’s value.

readUInt32B(): int (32 bit)

Read big-endian 32-bit unsigned integer from byte stream and return it’s value.

readUInt64B(): int (64 bit)

Read big-endian 64-bit unsigned integer from byte stream and return it’s value.

readFloatB(): floating-point number

Read 8 bytes from stream as big-endian floating-point number and return it’s value. Deprecated from v 5.1.2, readFloat64B should be used instead.

readFloat32B(): floating-point number (32 bit)

Read 32 bytes from stream as big-endian floating-point number and return it’s value. Added in v 5.1.2.

readFloat64B(): floating-point number (64 bit)

Read 64 bytes from stream as big-endian floating-point number and return it’s value. Added in v 5.1.2.

readInt16L(): int (32 bit)

Read little-endian 16-bit signed integer from byte stream and return it’s value.

readInt32L(): int (32 bit)

Read little-endian 32-bit signed integer from byte stream and return it’s value.

readInt64L(): int (64 bit)

Read little-endian 64-bit signed integer from byte stream and return it’s value.

readUInt16L(): int (32 bit)

Read littleig-endian 16-bit unsigned integer from byte stream and return it’s value.

readUInt32L(): int (32 bit)

Read little-endian 32-bit unsigned integer from byte stream and return it’s value.

readUInt64L(): int (64 bit)

Read little-endian 64-bit unsigned integer from byte stream and return it’s value.

readFloatL(): floating-point number

Read 8 bytes from stream as little-endian floating-point number and return it’s value. Deprecated from v 5.1.2, readFloat64L should be used instead.

readFloat32L(): floating-point number (32 bit)

Read 32 bytes from stream as little-endian floating-point number and return it’s value. Added in v 5.1.2.

readFloat64L(): floating-point number (64 bit)

Read 64 bytes from stream as little-endian floating-point number and return it’s value. Added in v 5.1.2.

readCString(): String

Read C-string from stream and return it’s value. It’s expected that string in the stream is terminates by a null character.

readPString(): String

Read Pascal string from stream and return it’s value. It’s expected that first byte of string in the stream contains length of the string.

readString(length): String

Read string from stream and return it’s value.

Table 2. Parameters

length

Integer

Length of the string

writeByte(value): void

Write provided value as byte to the byte stream at current position.

writeInt16B(value): void

Write provided value to the byte stream as big-endian 16-bit integer .

writeInt32B(value): void

Write provided value to the byte stream as big-endian 32-bit integer.

writeInt64B(value): void

Write provided value to the byte stream as big-endian 64-bit integer.

writeFloatB(value): void

Write provided value to the byte stream as big-endian 64-bit float. Deprecated from v 5.1.2, writeFloat64B should be used instead.

writeFloat32B(value): void

Write provided value to the byte stream as big-endian 32-bit float. Added in v 5.1.2.

writeFloat64B(value): void

Write provided value to the byte stream as big-endian 64-bit float. Added in v 5.1.2.

writeInt16L(value): void

Write provided value to the byte stream as little-endian 16-bit integer.

writeInt32L(value): void

Write provided value to the byte stream as little-endian 32-bit integer.

writeInt64L(value): void

Write provided value to the byte stream as little-endian 64-bit integer.

writeFloatL(value): void

Write provided value to the byte stream as little-endian 64-bit float. Deprecated from v 5.1.2, writeFloat64L should be used instead.

writeFloat32L(value): void

Write provided value to the byte stream as little-endian 32-bit float. Added in v 5.1.2.

writeFloat64L(value): void

Write provided value to the byte stream as little-endian 64-bit float. Added in v 5.1.2.

writeCString(string): void

Write provided string to the byte stream as null-terminated string (C-string).

writePString(string): void

Write provided string to the byte stream as Pascal string (first byte is string length).

writeString(string): void

Write provided string to the byte stream.

Constructors

ByteStream()

Creates new byte stream.

Return

ByteStream object.

bytestream = new ByteStream();
bytestream.writeString("xyz");
bytestream.seek(0);
while (!bytestream.eos) {
  b = bytestream.readByte();
  print(d2x(b,2) .. " "); // prints "78 79 7A"
}