Libraries.Containers.Support.ByteReader Documentation
The ByteReader class is designed to read through ByteArrays that store low level byte information from files. The purpose is to provide a way to manipulate bytes efficiently in Quorum, which is necessary for some specialized applications. The values in each position in the array are raw bytes, which means any integer returned is 8 bits in length. As such, they are individually between the numbers -128 and 127. The ByteReader can be used to easily retrieve bytes as well as numbers, booleans, and integers.
Example Code
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
class Main
action main
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
integer nextByte = reader:NextByteAsInteger()
end
end
Inherits from: Libraries.Language.Object
Actions Documentation
CheckIfTrueTypeCollection()
This action checks if the font file being read is a .ttc file or not. If it is .ttc instead of .ttf, it has a different structure and must be read differently than a .ttf file. .ttc files always have the tag "ttcf" at the start of the file. Returns true if the file being read is a .ttc file, and false if it is a .ttf file.
Return
boolean: Returns true if the file is in .ttc format, and false otherwise.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
boolean result = reader:CheckIfTrueTypeCollection()
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
GetByteArray()
This action returns the ByteArray that is currently being read from.
Return
Libraries.Containers.ByteArray: Returns the ByteArray that is currently being read from.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
ByteArray copy = reader:GetByteArray()
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetPosition()
This action returns the current index position from which the ByteReader is currently reading.
Return
integer: Returns the index value of the current position within the ByteArray.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
integer location = reader:GetPosition()
HasNextInteger()
This action checks if there are enough bytes remaining in the ByteArray to be assigned to an integer.
Return
boolean: Returns true if there are at least four bytes still in the array, and false if not.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
boolean canRead = reader:HasNextInteger()
NextByteAsBoolean()
This action reads the next byte from the ByteArray and converts it to a boolean.
Return
boolean: Returns the next byte in the ByteArray as a boolean value.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
boolean value = reader:NextByteAsBoolean()
NextByteAsInteger()
This action reads the next byte from the ByteArray and converts it to an integer.
Return
integer: Returns the next byte in the ByteArray as an integer.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
integer value = reader:NextByteAsInteger()
NextByteAsUnsignedInteger()
This action reads the next byte from the ByteArray and converts it to an unsigned integer.
Return
integer: Returns the next byte in the ByteArray as an unsigned integer.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
integer value = reader:NextByteAsUnsignedInteger()
NextInteger()
This action reads the next four bytes from the ByteArray and converts them to an integer.
Return
integer: Returns the next four bytes in the ByteArray as an integer.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
integer value = reader:NextInteger()
NextIntegerConvertFromUnsigned()
This action reads the next four bytes from the ByteArray and converts them to a signed integer.
Return
integer: Returns the next four bytes in the ByteArray as a signed integer.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
integer value = reader:NextIntegerConvertFromUnsigned()
NextLong()
This action reads the next eight bytes from the ByteArray and converts them to a BigInteger.
Return
Libraries.Compute.BigInteger: Returns the next eight bytes in the ByteArray as a BigInteger.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
use Libraries.Compute.BigInteger
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
BigInteger largeNumber = reader:NextLong()
NextNumber()
This action reads the next eight bytes from the ByteArray and converts them to a number.
Return
number: Returns the next eight bytes in the ByteArray as a number.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
number value = reader:NextNumber()
NextNumber4Byte()
This action reads the next four bytes from the ByteArray and converts them to a number.
Return
number: Returns the next four bytes in the ByteArray as a number.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
number value = reader:NextNumber4Byte()
NextSubArray(integer amount)
This action creates a sub-array of the ByteArray, starting from the current position, and then moves the position to read from to the next position in the array that comes after the end of this sub-array.
Parameters
- integer amount: The number of items to grab from the ByteArray and store in the new sub-array.
Return
Libraries.Containers.ByteArray: Returns a sub-array of the ByteArray.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
ByteArray small = reader:NextSubArray(1)
NextTextRead(integer amount)
This action reads the next amount of characters from the ByteArray, sets them to a text object, and then returns it.
Parameters
- integer amount: The number of characters to read from the ByteArray.
Return
text: Returns the characters read from the ByteArray as a text.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
text word = reader:NextTextRead(5)
NextTextReadUnicode(integer amount)
This action reads the next amount of characters from the ByteArray, sets them to a text object, and then returns it. Unicode encoding uses 2 bytes per character.
Parameters
- integer amount: The number of characters to read from the ByteArray
Return
text: Returns the characters read from the ByteArray as text.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
text word = reader:NextTextReadUnicode(5)
NextTextUntilCharacter(text character)
This action reads the ByteArray up until it reads the specified character. Once found, it returns all of the characters that were read as a text. For example, if you want to read up until 'g', you may read 'd', then 'o', then 'g', at which point it will stop reading the file and return 'dog'.
Parameters
- text character: The character that signifies when you want to stop reading the file.
Return
text: Returns the text of all characters read.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
text word = reader:NextTextUntilCharacter("z")
NextTwoByteInteger()
This action reads the next two bytes from the ByteArray and converts them to an integer.
Return
integer: Returns the next two bytes in the ByteArray as an integer.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
integer value = reader:NextTwoByteInteger()
NextTwoByteUnsignedInteger()
This action reads the next two bytes from the ByteArray and converts them to an unsigned integer.
Return
integer: Returns the next two bytes in the ByteArray as an unsigned integer.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
integer value = reader:NextTwoBytesUnsignedInteger()
SetByteArray(Libraries.Containers.ByteArray byteArray)
This action sets the ByteArray that the ByteReader will read from.
Parameters
- Libraries.Containers.ByteArray: The ByteArray to set as the array to read from.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
SetPosition(integer newPosition)
This action sets the current position within the ByteArray, used for moving around the array when reading various amounts of data, such as a byte, two bytes, and so on.
Parameters
- integer newPosition: The array index to set the current reading position to.
Return
boolean: Returns true if the index is valid and was set properly, or false if the index provided is illegal.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
reader:SetPosition(1)
SkipBytes(integer amount)
This action moves the current array reading position by the amount specified, either forward or backward. Useful for skipping data that you do not need to read.
Parameters
- integer amount: The number of items to skip over in the ByteArray.
Example
use Libraries.Containers.Support.ByteReader
use Libraries.System.File
use Libraries.Containers.ByteArray
File file
file:SetPath("files/Quorum.png")
ByteArray value = file:ReadBytes()
ByteReader reader
reader:SetByteArray(value)
reader:SkipBytes(10)
On this page
Variables TableAction Documentation- CheckIfTrueTypeCollection()
- Compare(Libraries.Language.Object object)
- Equals(Libraries.Language.Object object)
- GetByteArray()
- GetHashCode()
- GetPosition()
- HasNextInteger()
- NextByteAsBoolean()
- NextByteAsInteger()
- NextByteAsUnsignedInteger()
- NextInteger()
- NextIntegerConvertFromUnsigned()
- NextLong()
- NextNumber()
- NextNumber4Byte()
- NextSubArray(integer amount)
- NextTextRead(integer amount)
- NextTextReadUnicode(integer amount)
- NextTextUntilCharacter(text character)
- NextTwoByteInteger()
- NextTwoByteUnsignedInteger()
- SetByteArray(Libraries.Containers.ByteArray byteArray)
- SetPosition(integer newPosition)
- SkipBytes(integer amount)