Binary

Overview

Represents in memory byte buffer.

Binary allows random access reads, but only sequential writes. The Binary automatically grows as data is written to it.

Use case

You can use Binary class whenver you need an in memory byte buffer with auto grow ability.

var Bin := new Sugar.Binary([72, 101, 108, 108, 111]);
Bin.Write([32, 87, 111, 114, 108, 100], 6);

writeLn(new Sugar.String(Bin.ToArray));

Output:

Hello World

Location

  • Reference: Sugar
  • Namespace: Sugar

 

constructor (array of Byte)

Creates a new instance of the class and copies data from specified byte array.

 

constructor(anArray: array of Byte)

 

Binary(Byte[] anArray)

 

init(_ anArray: Byte...)

 

Binary(Byte[] anArray)

 

Sub New(anArray As Byte())

Parameters:

  • anArray: Byte array to copy.

constructor (Binary)

Creates a new instance of the class and copies data from specified Binary class.

 

constructor(Bin: Binary)

 

Binary(Binary Bin)

 

init(_ Bin: Binary)

 

Binary(Binary Bin)

 

Sub New(Bin As Binary)

Parameters:

  • Bin: Binary to copy.

Assign  mapped

Replaces current buffer with data from specified Binary.

 

method Assign(Bin: Binary)

 

void Assign(Binary Bin)

 

func Assign(_ Bin: Binary)

 

void Assign(Binary Bin)

 

Sub Assign(Bin As Binary)

Parameters:

  • Bin: Binary from which data will be copied.

Clear  mapped

Removes all data from the buffer.

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

 

Sub Clear()

Length

Gets length of buffer.

 

property Length: Int32 read;

 

Int32 Length { get; }

 

var Length: Int32 { get{} }

 

Int32 Length { __get; }

 

ReadOnly Property Length() As Int32

Read (Range): array of Byte  mapped

Reads an array of byte with specified range from Binary.

var Bin := new Sugar.Binary(Sugar.String("Hello World").ToByteArray);
writeLn(new Sugar.String(Bin.Read(Sugar.Range.MakeRange(6, 5)))); //outputs "World"

 

method Read(Range: Range): array of Byte

 

Byte[] Read(Range Range)

 

func Read(_ Range: Range) -> Byte...

 

Byte[] Read(Range Range)

 

Function Read(Range As Range) As Byte()

Parameters:

  • Range: Range in the binary from which to get the data.

Read (Int32): array of Byte  mapped

Reads a specified amount of byte into a new array of byte starting from the beggining of Binary.

 

method Read(Count: Int32): array of Byte

 

Byte[] Read(Int32 Count)

 

func Read(_ Count: Int32) -> Byte...

 

Byte[] Read(Int32 Count)

 

Function Read(Count As Int32) As Byte()

Parameters:

  • Count: Number of bytes to read.

Subdata  mapped

Reads data with specified range from current buffer into a new Binary.

 

method Subdata(Range: Range): Binary

 

Binary Subdata(Range Range)

 

func Subdata(_ Range: Range) -> Binary

 

Binary Subdata(Range Range)

 

Function Subdata(Range As Range) As Binary

Parameters:

  • Range: Range in the binary from which to get the data.

ToArray  mapped

Copies data of the Binary into a new array.

 

method ToArray: array of Byte

 

Byte[] ToArray()

 

func ToArray() -> Byte...

 

Byte[] ToArray()

 

Function ToArray() As Byte()

Write (array of Byte)  mapped

Appends all bytes from a given buffer into to the Binary.

 

method Write(Buffer: array of Byte)

 

void Write(Byte[] Buffer)

 

func Write(_ Buffer: Byte...)

 

void Write(Byte[] Buffer)

 

Sub Write(Buffer As Byte())

Parameters:

  • Buffer: Array of byte from which data will be taken.

Write (Binary)  mapped

Appends data from a given Binary.

 

method Write(Bin: Binary)

 

void Write(Binary Bin)

 

func Write(_ Bin: Binary)

 

void Write(Binary Bin)

 

Sub Write(Bin As Binary)

Parameters:

  • Bin: Binary containing data to append.

Write (array of Byte, Int32)  mapped

Appends specified number of bytes from a given buffer into to the Binary.

 

method Write(Buffer: array of Byte; Count: Int32)

 

void Write(Byte[] Buffer, Int32 Count)

 

func Write(_ Buffer: Byte..., _ Count: Int32)

 

void Write(Byte[] Buffer, Int32 Count)

 

Sub Write(Buffer As Byte(), Count As Int32)

Parameters:

  • Buffer: Array of byte from which data will be taken.
  • Count: Number of bytes to write.

Write (array of Byte, Int32, Int32)  mapped

Appends specified number of bytes from a given buffer into to the Binary.

 

method Write(Buffer: array of Byte; Offset: Int32; Count: Int32)

 

void Write(Byte[] Buffer, Int32 Offset, Int32 Count)

 

func Write(_ Buffer: Byte..., _ Offset: Int32, _ Count: Int32)

 

void Write(Byte[] Buffer, Int32 Offset, Int32 Count)

 

Sub Write(Buffer As Byte(), Offset As Int32, Count As Int32)

Parameters:

  • Buffer: Array of byte from which data will be taken.
  • Offset: Starting index in the buffer.
  • Count: Number of bytes to write.

 

Length

Gets length of buffer.

 

property Length: Int32 read;

 

Int32 Length { get; }

 

var Length: Int32 { get{} }

 

Int32 Length { __get; }

 

ReadOnly Property Length() As Int32

 

constructor (array of Byte)

Creates a new instance of the class and copies data from specified byte array.

 

constructor(anArray: array of Byte)

 

Binary(Byte[] anArray)

 

init(_ anArray: Byte...)

 

Binary(Byte[] anArray)

 

Sub New(anArray As Byte())

Parameters:

  • anArray: Byte array to copy.

constructor (Binary)

Creates a new instance of the class and copies data from specified Binary class.

 

constructor(Bin: Binary)

 

Binary(Binary Bin)

 

init(_ Bin: Binary)

 

Binary(Binary Bin)

 

Sub New(Bin As Binary)

Parameters:

  • Bin: Binary to copy.

Assign  mapped

Replaces current buffer with data from specified Binary.

 

method Assign(Bin: Binary)

 

void Assign(Binary Bin)

 

func Assign(_ Bin: Binary)

 

void Assign(Binary Bin)

 

Sub Assign(Bin As Binary)

Parameters:

  • Bin: Binary from which data will be copied.

Clear  mapped

Removes all data from the buffer.

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

 

Sub Clear()

Read (Range): array of Byte  mapped

Reads an array of byte with specified range from Binary.

var Bin := new Sugar.Binary(Sugar.String("Hello World").ToByteArray);
writeLn(new Sugar.String(Bin.Read(Sugar.Range.MakeRange(6, 5)))); //outputs "World"

 

method Read(Range: Range): array of Byte

 

Byte[] Read(Range Range)

 

func Read(_ Range: Range) -> Byte...

 

Byte[] Read(Range Range)

 

Function Read(Range As Range) As Byte()

Parameters:

  • Range: Range in the binary from which to get the data.

Read (Int32): array of Byte  mapped

Reads a specified amount of byte into a new array of byte starting from the beggining of Binary.

 

method Read(Count: Int32): array of Byte

 

Byte[] Read(Int32 Count)

 

func Read(_ Count: Int32) -> Byte...

 

Byte[] Read(Int32 Count)

 

Function Read(Count As Int32) As Byte()

Parameters:

  • Count: Number of bytes to read.

Subdata  mapped

Reads data with specified range from current buffer into a new Binary.

 

method Subdata(Range: Range): Binary

 

Binary Subdata(Range Range)

 

func Subdata(_ Range: Range) -> Binary

 

Binary Subdata(Range Range)

 

Function Subdata(Range As Range) As Binary

Parameters:

  • Range: Range in the binary from which to get the data.

ToArray  mapped

Copies data of the Binary into a new array.

 

method ToArray: array of Byte

 

Byte[] ToArray()

 

func ToArray() -> Byte...

 

Byte[] ToArray()

 

Function ToArray() As Byte()

Write (array of Byte)  mapped

Appends all bytes from a given buffer into to the Binary.

 

method Write(Buffer: array of Byte)

 

void Write(Byte[] Buffer)

 

func Write(_ Buffer: Byte...)

 

void Write(Byte[] Buffer)

 

Sub Write(Buffer As Byte())

Parameters:

  • Buffer: Array of byte from which data will be taken.

Write (Binary)  mapped

Appends data from a given Binary.

 

method Write(Bin: Binary)

 

void Write(Binary Bin)

 

func Write(_ Bin: Binary)

 

void Write(Binary Bin)

 

Sub Write(Bin As Binary)

Parameters:

  • Bin: Binary containing data to append.

Write (array of Byte, Int32)  mapped

Appends specified number of bytes from a given buffer into to the Binary.

 

method Write(Buffer: array of Byte; Count: Int32)

 

void Write(Byte[] Buffer, Int32 Count)

 

func Write(_ Buffer: Byte..., _ Count: Int32)

 

void Write(Byte[] Buffer, Int32 Count)

 

Sub Write(Buffer As Byte(), Count As Int32)

Parameters:

  • Buffer: Array of byte from which data will be taken.
  • Count: Number of bytes to write.

Write (array of Byte, Int32, Int32)  mapped

Appends specified number of bytes from a given buffer into to the Binary.

 

method Write(Buffer: array of Byte; Offset: Int32; Count: Int32)

 

void Write(Byte[] Buffer, Int32 Offset, Int32 Count)

 

func Write(_ Buffer: Byte..., _ Offset: Int32, _ Count: Int32)

 

void Write(Byte[] Buffer, Int32 Offset, Int32 Count)

 

Sub Write(Buffer As Byte(), Offset As Int32, Count As Int32)

Parameters:

  • Buffer: Array of byte from which data will be taken.
  • Offset: Starting index in the buffer.
  • Count: Number of bytes to write.