Class: ReadableDataChannel

Represents a data channel for reading data.

Constructor

Initializes the data channel.

init (ReadableByteChannel byteChannel, ByteOrder bOrder)
  • byteChannel ReadableByteChannel
  • The channel, which would represent the source to read/write data

Methods

readInt16

Reads a 16 bit integer.

readInt32

Reads a 32 bit integer.

readInt64

Reads a 64 bit integer.

readFloat32

Reads a 32 bit float.

readFloat64

Reads a 64 bit float.

readBool

Reads a byte and convert its value to boolean.

readString

Reads the string value represented through the provided number of bytes.

readVarInt

Reads a variable length integer.

close

Closes the data channel.

readInt16

function readInt16() returns int | Error
Isolated Function

Reads a 16 bit integer.

1int|io:Error result = dataChannel.readInt16();

Return Type

(int | Error)

The value of the integer, which is read or else an io:Error if any error occurred

readInt32

function readInt32() returns int | Error
Isolated Function

Reads a 32 bit integer.

1int|io:Error result = dataChannel.readInt32();

Return Type

(int | Error)

The value of the integer, which is read or else an io:Error if any error occurred

readInt64

function readInt64() returns int | Error
Isolated Function

Reads a 64 bit integer.

1int|io:Error result = dataChannel.readInt64();

Return Type

(int | Error)

The value of the integer, which is read or else an io:Error if any error occurred

readFloat32

function readFloat32() returns float | Error
Isolated Function

Reads a 32 bit float.

1float|io:Error result = dataChannel.readFloat32();

Return Type

(float | Error)

The value of the float which is read or else io:Error if any error occurred

readFloat64

function readFloat64() returns float | Error
Isolated Function

Reads a 64 bit float.

1float|io:Error result = dataChannel.readFloat64();

Return Type

(float | Error)

The value of the float which is read or else io:Error if any error occurred

readBool

function readBool() returns boolean | Error
Isolated Function

Reads a byte and convert its value to boolean.

1boolean|io:Error result = dataChannel.readBool();

Return Type

(boolean | Error)

boolean value which is read or else io:Error if any error occurred

readString

function readString(int nBytes, string encoding) returns string | Error
Isolated Function

Reads the string value represented through the provided number of bytes.

1string|io:Error string = dataChannel.readString(10, "UTF-8");

Parameters

  • nBytes int
  • Specifies the number of bytes, which represents the string

  • encoding string
  • Specifies the char-set encoding of the string

Return Type

(string | Error)

The value of the string or else io:Error if any error occurred

readVarInt

function readVarInt() returns int | Error
Isolated Function

Reads a variable length integer.

1int|io:Error result = dataChannel.readVarInt();

Return Type

(int | Error)

The value of the integer which is read or else io:Error if any error occurred

close

function close() returns Error?
Isolated Function

Closes the data channel. After a channel is closed, any further reading operations will cause an error.

1io:Error? err = dataChannel.close();

Return Type

(Error?)

() if the channel is closed successfully or else an io:Error if any error occurred