Core runtime library providing primitive types (Bool, Byte, Char, Int, Float, String), the Ref wrappers and array helpers, and system utilities (console, files, threads, sockets). Collections are not here: they are in gen_collect.obl. Every Objeck program links against this bundle automatically via lang.obl.
Byte
The byte class represents a 1-byte value.
Operations
- Abs
- CRC32
- Clamp
- Clear
- Compare
- CompressDeflate
- CompressGzip
- CompressZlib
- Copy
- Error
- ErrorLine
- Fill
- Find
- FindAll
- IsNeg
- Max
- Min
- PrintLine
- ToBinaryString
- ToChar
- ToFloat
- ToFloats
- ToHexDigits
- ToHexString
- ToInt
- ToInts
- ToString
- ToUnicode
- TryUncompressZlib
- UncompressDeflate
- UncompressGzip
- UncompressZlib
Abs # function
Returns the absolute value
function : Abs() ~ ByteReturn
| Type | Description |
|---|---|
| Byte | absolute value |
CRC32 # function
Calculates the signed CRC32 value for the stream
function : CRC32() ~ IntReturn
| Type | Description |
|---|---|
| Int | signed CRC32 |
Clamp # function
Returns a given value between an upper and lower bound
function : Clamp(min:Byte, value:Byte, max:Byte) ~ ByteParameters
| Name | Type | Description |
|---|---|---|
| min | Byte | minimal value |
| value | Byte | value between the min and max |
| max | Byte | maximum value |
Return
| Type | Description |
|---|---|
| Byte | min if vaule is less than main, max if max is less than value, otherwise the value |
Clear # function
Set all array elements to zero
function : Clear(b:Byte[]) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| b | Byte | byte array |
Compare # native
Compares two values
function : native : Compare(l:Byte, r:Byte) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| l | Byte | left compare object |
| r | Byte | right compare object |
Return
| Type | Description |
|---|---|
| Int | 0 if equal, -1 if types differ, 1 if equal |
CompressDeflate # function
Compresses a byte stream as raw deflate (RFC 1951): the compressed blocks alone, with no zlib header or checksum (CompressZlib) and no gzip framing (CompressGzip). This is the format of zip members and of zlib/Python with windowBits -15. It is not Brotli, and not HTTP's "deflate" content coding, which is the zlib format.
function : CompressDeflate() ~ Byte[]Return
| Type | Description |
|---|---|
| Byte | compressed bytes |
CompressGzip # function
Compresses a byte stream using gzip
function : CompressGzip() ~ Byte[]Return
| Type | Description |
|---|---|
| Byte | compressed bytes |
CompressZlib # function
Compresses a byte stream using zlib
function : CompressZlib() ~ Byte[]Return
| Type | Description |
|---|---|
| Byte | compressed bytes |
CompressZlib # function
Compresses a byte stream using zlib at a given level: 1 is fastest, 9 smallest (what CompressZlib(input) uses), 0 stores without compressing, and -1, or any value out of range, is zlib's default (6). UncompressZlib reads every level.
function : CompressZlib(input:Byte[], level:Int) ~ Byte[]Parameters
| Name | Type | Description |
|---|---|---|
| input | Byte | bytes to compress |
| level | Int | compression level, -1 to 9 |
Return
| Type | Description |
|---|---|
| Byte | compressed bytes |
Copy # function
Copies elements between two bytes arrays, or within one: overlapping ranges copy as if through a temporary array. Raises an IndexError, which a try/on or ?-> region can recover from, when a range does not fit its array; nothing is copied then.
function : Copy(dest:Byte[], dest_offset:Int, src:Byte[], src_offset:Int, count:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| dest | Byte | destination array |
| dest_offset | Int | first destination index |
| src | Byte | source array |
| src_offset | Int | first source index |
| count | Int | number of elements to copy; zero copies nothing |
Example
a := Byte->New[4]
Byte->Copy(a, 1, a, 0, 3); # shifts the first three elements right by oneFill # function
Sets every element of an array to a value
function : Fill(array:Byte[], value:Byte) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| array | Byte | array |
| value | Byte | value |
Fill # function
Sets a range of array elements to a value. Raises an IndexError, which a try/on or ?-> region can recover from, when the range does not fit the array; nothing is set then.
function : Fill(array:Byte[], value:Byte, offset:Int, count:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| array | Byte | array |
| value | Byte | value |
| offset | Int | first index |
| count | Int | number of elements to set; zero sets nothing |
Find # native
Searches for the first occurrence of a byte
function : native : Find(bytes:Byte[], search:Byte) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| bytes | Byte | byte array to search |
| search | Byte | byte to search for |
Return
| Type | Description |
|---|---|
| Int | true of found, false otherwise |
Find # native
Searches for the first occurrence of a byte
function : native : Find(bytes:Byte[], offset:Int, search:Byte) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| bytes | Byte | byte array to search |
| offset | Int | search offset |
| search | Byte | byte to search for |
Return
| Type | Description |
|---|---|
| Int | true of found, false otherwise |
Find # native
Searches for the first occurrence of a byte array
function : native : Find(bytes:Byte[], search:Byte[]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| bytes | Byte | byte array to search |
| search | Byte | byte array to search for |
Return
| Type | Description |
|---|---|
| Int | index of first occurrence, -1 otherwise |
Find # native
Searches for the first occurrence of a byte array
function : native : Find(bytes:Byte[], offset:Int, search:Byte[]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| bytes | Byte | byte array to search |
| offset | Int | search offset |
| search | Byte | byte array to search for |
Return
| Type | Description |
|---|---|
| Int | index of first occurrence, -1 otherwise |
FindAll # function
Searches for all occurrences of the byte array
function : FindAll(bytes:Byte[], search:Byte[]) ~ Int[]Parameters
| Name | Type | Description |
|---|---|---|
| bytes | Byte | byte array to search |
| search | Byte | byte array to search for |
Return
| Type | Description |
|---|---|
| Int | an array of indexes |
IsNeg # function
Checks is a number is negative
function : IsNeg() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if negative, false otherwise |
Max # function
Returns the largest byte value
function : Max(l:Byte, r:Byte) ~ ByteParameters
| Name | Type | Description |
|---|---|---|
| l | Byte | value to compare |
| r | Byte | value to compare |
Return
| Type | Description |
|---|---|
| Byte | largest byte value |
Min # function
Returns the smallest byte value
function : Min(l:Byte, r:Byte) ~ ByteParameters
| Name | Type | Description |
|---|---|---|
| l | Byte | value to compare |
| r | Byte | value to compare |
Return
| Type | Description |
|---|---|
| Byte | smallest byte value |
PrintLine # native
Prints values
function : native : PrintLine(v:Byte[]) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| v | Byte | values to print |
PrintLine # native
Prints values
function : native : PrintLine(v:Byte[,]) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| v | Byte | values to print |
ToBinaryString # native
Returns a binary string representation of the value
function : native : ToBinaryString() ~ StringReturn
| Type | Description |
|---|---|
| String | binary string representation of the value |
ToChar # function
Returns the Character value
function : ToChar() ~ CharReturn
| Type | Description |
|---|---|
| Char | value |
ToFloat # function
Returns the Float value
function : ToFloat() ~ FloatReturn
| Type | Description |
|---|---|
| Float | value |
ToFloats # function
Reads floats from raw bytes, 8 per value, little-endian (Float->ToBytes writes them). Raises a RuntimeError, which a try/on or ?-> region can recover from, when the size is not a multiple of 8.
function : ToFloats(bytes:Byte[]) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| bytes | Byte | bytes |
Return
| Type | Description |
|---|---|
| Float | bytes->Size() / 8 values |
ToFloats # function
Reads floats from raw bytes, 8 per value, little-endian, starting at a byte offset. Raises an IndexError, which a try/on or ?-> region can recover from, when count * 8 bytes from the offset do not fit.
function : ToFloats(bytes:Byte[], offset:Int, count:Int) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| bytes | Byte | bytes |
| offset | Int | first byte's index |
| count | Int | number of values |
Return
| Type | Description |
|---|---|
| Float | count values |
ToHexDigits # function
Returns the value's hex digits without the 0x prefix, padded with zeros to a minimum width (ToHexString keeps the prefix)
function : ToHexDigits() ~ StringReturn
| Type | Description |
|---|---|
| String | lower-case hex digits, at least width of them |
Example
255->As(Byte)->ToHexDigits(4)->PrintLine(); # 00ffToHexString # native
Returns a positive hexadecimal string representation of the value
function : native : ToHexString() ~ StringReturn
| Type | Description |
|---|---|
| String | hexadecimal string representation of the value |
ToHexString # native
Returns the bytes as a hex digest: two lower-case hex digits per byte, in order, with no prefix or separators. For one byte's value with a 0x prefix, see ToHexString(Byte); for its digits at a given width, ToHexDigits.
function : native : ToHexString() ~ StringReturn
| Type | Description |
|---|---|
| String | hex digits, two per byte; empty for an empty array |
Example
Cipher.Hash->SHA256("Rosetta code"->ToByteArray())->ToHexString()->PrintLine(); # 764faf5c...ToInts # function
Reads integers from raw bytes, 8 per value, little-endian (Int->ToBytes writes them). Raises a RuntimeError, which a try/on or ?-> region can recover from, when the size is not a multiple of 8.
function : ToInts(bytes:Byte[]) ~ Int[]Parameters
| Name | Type | Description |
|---|---|---|
| bytes | Byte | bytes |
Return
| Type | Description |
|---|---|
| Int | bytes->Size() / 8 values |
ToInts # function
Reads integers from raw bytes, 8 per value, little-endian, starting at a byte offset. Raises an IndexError, which a try/on or ?-> region can recover from, when count * 8 bytes from the offset do not fit.
function : ToInts(bytes:Byte[], offset:Int, count:Int) ~ Int[]Parameters
| Name | Type | Description |
|---|---|---|
| bytes | Byte | bytes |
| offset | Int | first byte's index |
| count | Int | number of values |
Return
| Type | Description |
|---|---|
| Int | count values |
ToString # native
Returns a string representation of the value
function : native : ToString() ~ StringReturn
| Type | Description |
|---|---|
| String | string representation of the value |
ToString # native
Returns a string representation of the byte array
function : native : ToString(v:Byte[]) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| v | Byte | byte array |
Return
| Type | Description |
|---|---|
| String | string representation of the byte array |
ToString # function
Returns a string representation of the byte array
function : ToString(v:Byte[,]) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| v | Byte | byte array |
Return
| Type | Description |
|---|---|
| String | string representation of the byte array |
ToUnicode # function
Converts the byte array to a character array
function : ToUnicode(b:Byte[]) ~ Char[]Parameters
| Name | Type | Description |
|---|---|---|
| b | Byte | array |
Return
| Type | Description |
|---|---|
| Char | character array |
TryUncompressZlib # function
Uncompresses a zlib byte stream without raising. Use it on data that did not come from the program itself, a file or a download that may be damaged, truncated or not zlib at all: UncompressZlib(input) ends the program for those.
function : TryUncompressZlib(input:Byte[]) ~ Byte[]Parameters
| Name | Type | Description |
|---|---|---|
| input | Byte | zlib bytes, may be Nil |
Return
| Type | Description |
|---|---|
| Byte | uncompressed bytes, Nil if the input is Nil or not a whole zlib stream |
Example
raw := Byte->TryUncompressZlib(packed);
if(raw = Nil) {
"not a zlib stream"->ErrorLine();
};UncompressDeflate # function
Uncompresses a raw deflate (RFC 1951) byte stream, as written by CompressDeflate, a zip member or zlib with windowBits -15. Raises on damaged or truncated input.
function : UncompressDeflate() ~ Byte[]Return
| Type | Description |
|---|---|
| Byte | uncompressed bytes |
UncompressDeflate # function
Uncompresses a raw deflate (RFC 1951) stream to at most 'limit' bytes. A zip member names its uncompressed size, so passing that size as the limit both bounds the memory used and catches a member that expands past what it claims (a zip bomb). Raises on damaged or truncated input, as UncompressDeflate(input) does.
function : UncompressDeflate(input:Byte[], limit:Int) ~ Byte[]Parameters
| Name | Type | Description |
|---|---|---|
| input | Byte | raw deflate bytes |
| limit | Int | most bytes the output may hold |
Return
| Type | Description |
|---|---|
| Byte | uncompressed bytes, Nil if the output would be larger than the limit |
Example
raw := Byte->UncompressDeflate(member, declared_size);
if(raw = Nil | raw->Size() <> declared_size) {
"the member does not match its stated size"->ErrorLine();
};UncompressGzip # function
Uncompresses a byte stream using gzip
function : UncompressGzip() ~ Byte[]Return
| Type | Description |
|---|---|
| Byte | uncompressed bytes |
UncompressGzip # function
Uncompresses a gzip stream to at most 'limit' bytes. Use it on data from outside the program: a few kilobytes of gzip can expand to gigabytes, and this stops at the bound instead of allocating them. Raises on damaged or truncated input, as UncompressGzip(input) does.
function : UncompressGzip(input:Byte[], limit:Int) ~ Byte[]Parameters
| Name | Type | Description |
|---|---|---|
| input | Byte | gzip bytes |
| limit | Int | most bytes the output may hold |
Return
| Type | Description |
|---|---|
| Byte | uncompressed bytes, Nil if the output would be larger than the limit |
Example
raw := Byte->UncompressGzip(packed, 64 * 1024 * 1024);
if(raw = Nil) {
"larger than 64 MB uncompressed"->ErrorLine();
};