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
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"
Parameters:
- Range: Range in the binary from which to get the data.
Reads a specified amount of byte into a new array of byte starting from the beggining of Binary.
Parameters:
- Count: Number of bytes to read.
Subdata mapped
Reads data with specified range from current buffer into a new 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.
Appends specified number of bytes from a given buffer into to the Binary.
Parameters:
- Buffer: Array of byte from which data will be taken.
- Count: Number of bytes to write.
Appends specified number of bytes from a given buffer into to the Binary.
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.
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()
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"
Parameters:
- Range: Range in the binary from which to get the data.
Reads a specified amount of byte into a new array of byte starting from the beggining of Binary.
Parameters:
- Count: Number of bytes to read.
Subdata mapped
Reads data with specified range from current buffer into a new 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.
Appends specified number of bytes from a given buffer into to the Binary.
Parameters:
- Buffer: Array of byte from which data will be taken.
- Count: Number of bytes to write.
Appends specified number of bytes from a given buffer into to the Binary.
Parameters:
- Buffer: Array of byte from which data will be taken.
- Offset: Starting index in the
buffer
. - Count: Number of bytes to write.