Bytes
Edit on GitHubUtilities for working with byte sequences.
Added in 0.3.2
No other changes yet.
Values
Functions and constants included in the Bytes module.
Bytes.make
Added in 0.3.2
No other changes yet.
Creates a new byte sequence of the input size.
Parameters:
param | type | description |
---|---|---|
size |
Number |
The number of bytes to store |
Returns:
type | description |
---|---|
Bytes |
The new byte sequence |
Examples:
Bytes.empty
Added in 0.3.2
No other changes yet.
An empty byte sequence.
Examples:
Bytes.fromString
Added in 0.3.2
No other changes yet.
Creates a new byte sequence from the input string.
Parameters:
param | type | description |
---|---|---|
string |
String |
The string to copy into a byte sequence |
Returns:
type | description |
---|---|
Bytes |
The new byte sequence |
Examples:
Bytes.toString
Added in 0.3.2
No other changes yet.
Creates a new string from the input bytes.
Parameters:
param | type | description |
---|---|---|
bytes |
Bytes |
The source byte sequence |
Returns:
type | description |
---|---|
String |
The string representation of the bytes |
Examples:
Bytes.length
Added in 0.3.2
No other changes yet.
Returns the length of a byte sequence.
Parameters:
param | type | description |
---|---|---|
bytes |
Bytes |
The byte sequence to inspect |
Returns:
type | description |
---|---|
Number |
The number of bytes |
Examples:
Bytes.copy
Added in 0.3.2
No other changes yet.
Creates a new byte sequence that contains the same bytes as the input byte sequence.
Parameters:
param | type | description |
---|---|---|
bytes |
Bytes |
The byte sequence to copy |
Returns:
type | description |
---|---|
Bytes |
The new byte sequence |
Examples:
Bytes.slice
Added in 0.3.2
No other changes yet.
Returns a copy of a subset of the input byte sequence.
Parameters:
param | type | description |
---|---|---|
start |
Number |
The start index |
length |
Number |
The number of bytes to include after the starting index |
bytes |
Bytes |
The byte sequence to copy from |
Returns:
type | description |
---|---|
Bytes |
A byte sequence with of the copied bytes |
Throws:
InvalidArgument(String)
- When
start + length
is greater than the bytes size
Examples:
1 | assert Bytes.toString( |
Bytes.resize
Added in 0.3.2
No other changes yet.
Returns a copy of a byte sequence with bytes added or removed from the beginning and/or end.
A positive number represents bytes to add, while a negative number represents bytes to remove.
Parameters:
param | type | description |
---|---|---|
left |
Number |
The number of uninitialized bytes to prepend |
right |
Number |
The number of uninitialized bytes to append |
bytes |
Bytes |
The byte sequence get a subset of bytes from |
Returns:
type | description |
---|---|
Bytes |
A resized byte sequence |
Throws:
InvalidArgument(String)
- When the new size is negative
Examples:
Bytes.move
Added in 0.3.2
No other changes yet.
Copies a range of bytes from a source byte sequence to a given location in a destination byte sequence.
Parameters:
param | type | description |
---|---|---|
srcIndex |
Number |
The starting index to copy bytes from |
dstIndex |
Number |
The starting index to copy bytes into |
length |
Number |
The amount of bytes to copy from the source byte sequence |
src |
Bytes |
The source byte sequence |
dst |
Bytes |
The destination byte sequence |
Throws:
InvalidArgument(String)
- When
srcIndex + length
is greater than thesrc
bytes size - When the
dstIndex + length
is greater than thedst
bytes size
Examples:
1 | let bytes = Bytes.make(5) |
Bytes.concat
Added in 0.3.2
No other changes yet.
Creates a new byte sequence that contains the bytes of both byte sequences.
Parameters:
param | type | description |
---|---|---|
bytes1 |
Bytes |
The beginning byte sequence |
bytes2 |
Bytes |
The ending byte sequence |
Returns:
type | description |
---|---|
Bytes |
The new byte sequence |
Examples:
1 | let helloBytes = Bytes.fromString("Hello ") |
Bytes.fill
Added in 0.3.2
version | changes |
---|---|
0.6.0 | `value` argument type changed to `Uint8` |
Replaces all bytes in a byte sequnce with the new value provided.
Parameters:
param | type | description |
---|---|---|
value |
Uint8 |
The value replacing each byte |
bytes |
Bytes |
The byte sequence to update |
Examples:
Bytes.clear
Added in 0.5.0
No other changes yet.
Replaces all bytes in a byte sequence with zeroes.
Parameters:
param | type | description |
---|---|---|
bytes |
Bytes |
The byte sequence to clear |
Examples:
1 | let bytes = Bytes.make(5) |
Bytes.getInt8
Added in 0.6.0
version | changes |
---|---|
0.3.2 | Originally called `getInt8S`, returning an `Int32` |
Gets a signed 8-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Int8 |
A signed 8-bit integer that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 1
is greater than the bytes size
Examples:
Bytes.setInt8
Added in 0.3.2
version | changes |
---|---|
0.6.0 | `value` argument type changed to `Int8` |
Sets a signed 8-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Int8 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 1
is greater than the bytes size
Examples:
Bytes.getUint8
Added in 0.6.0
version | changes |
---|---|
0.3.2 | Originally called `getInt8U`, returning an `Int32` |
Gets an unsigned 8-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Uint8 |
An unsigned 8-bit integer that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 1
is greater than the bytes size
Examples:
Bytes.setUint8
Added in 0.6.0
No other changes yet.
Sets an unsigned 8-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Uint8 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 1
is greater than the bytes size
Examples:
Bytes.getInt16
Added in 0.6.0
version | changes |
---|---|
0.3.2 | Originally called `getInt16S`, returning an `Int32` |
Gets a signed 16-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Int16 |
A signed 16-bit integer that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 2
is greater than the bytes size
Examples:
Bytes.setInt16
Added in 0.3.2
version | changes |
---|---|
0.6.0 | `value` argument type changed to `Int16` |
Sets a signed 16-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Int16 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 2
is greater than the bytes size
Examples:
Bytes.getUint16
Added in 0.6.0
version | changes |
---|---|
0.3.2 | Originally called `getInt16U`, returning an `Int32` |
Gets an unsigned 16-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Uint16 |
An unsigned 16-bit integer that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 2
is greater than the bytes size
Examples:
Bytes.setUint16
Added in 0.6.0
No other changes yet.
Sets an unsigned 16-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Uint16 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 2
is greater than the bytes size
Examples:
Bytes.getInt32
Added in 0.3.2
No other changes yet.
Gets a signed 32-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Int32 |
A signed 32-bit integer that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 4
is greater than the bytes size
Examples:
Bytes.setInt32
Added in 0.3.2
No other changes yet.
Sets a signed 32-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Int32 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 4
is greater than the bytes size
Examples:
Bytes.getUint32
Added in 0.6.0
No other changes yet.
Gets an unsigned 32-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Uint32 |
An unsigned 32-bit integer that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 4
is greater than the bytes size
Examples:
Bytes.setUint32
Added in 0.6.0
No other changes yet.
Sets an unsigned 32-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Uint32 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 4
is greater than the bytes size
Examples:
Bytes.getFloat32
Added in 0.3.2
No other changes yet.
Gets a 32-bit float starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Float32 |
A 32-bit float that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 4
is greater than the bytes size
Examples:
1 | let bytes = Bytes.make(4) |
Bytes.setFloat32
Added in 0.3.2
No other changes yet.
Sets a 32-bit float starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Float32 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 4
is greater than the bytes size
Examples:
1 | let bytes = Bytes.make(4) |
Bytes.getInt64
Added in 0.3.2
No other changes yet.
Gets a signed 64-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Int64 |
A signed 64-bit integer that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 8
is greater than the bytes size
Examples:
Bytes.setInt64
Added in 0.3.2
No other changes yet.
Sets a signed 64-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Int64 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 8
is greater than the bytes size
Examples:
Bytes.getUint64
Added in 0.6.0
No other changes yet.
Gets an unsigned 64-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Uint64 |
An unsigned 64-bit integer that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 8
is greater than the bytes size
Examples:
Bytes.setUint64
Added in 0.6.0
No other changes yet.
Sets an unsigned 64-bit integer starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Uint64 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 8
is greater than the bytes size
Examples:
Bytes.getFloat64
Added in 0.3.2
No other changes yet.
Gets a 64-bit float starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to access |
bytes |
Bytes |
The byte sequence to access |
Returns:
type | description |
---|---|
Float64 |
A 64-bit float that starts at the given index |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 8
is greater than the bytes size
Examples:
1 | let bytes = Bytes.make(8) |
Bytes.setFloat64
Added in 0.3.2
No other changes yet.
Sets a 64-bit float starting at the given byte index.
Parameters:
param | type | description |
---|---|---|
index |
Number |
The byte index to update |
value |
Float64 |
The value to set |
bytes |
Bytes |
The byte sequence to mutate |
Throws:
IndexOutOfBounds
- When
index
is negative - When
index + 8
is greater than the bytes size
Examples: