Bytes Functions and Operators
| bytes | Byte sequence |
| bytes[i] | Bytes indexing. |
| bytes[from:to] | Bytes slicing. |
| bytes ++ bytes | Bytes concatenation. |
| = != ?= ?!= < > <= >= | Comparison operators |
| len() | Returns the number of bytes. |
| contains() | Check if the byte sequence contains a subsequence. |
| find() | Find the index of the first occurrence of a subsequence. |
| bytes_get_bit() | Get the nth bit of the bytes value. |
type
bytes

bytes
A sequence of bytes representing raw data.
There’s a special byte literal:
1. db>
1. select b'Hello, world';
1. {b'Hello, world'}
1. db>
1. select b'Hello,\x20world\x01';
1. {b'Hello, world\x01'}
There are also some generic functions that can operate on bytes:
1. db>
1. select contains(b'qwerty', b'42');
1. {false}
It is possible to cast between bytes and json. Bytes are represented as base64 encoded strings in json.:
1. db>
1. select <json>b'Hello EdgeDB!';
1. {"\"SGVsbG8gRWRnZURCIQ==\""}
1. db>
1. select <bytes>to_json("\"SGVsbG8gRWRnZURCIQ==\"");
1. {b'Hello EdgeDB!'}
operator
bytes[i]

bytes [ int64 ] -> bytes
Bytes indexing.
Examples:
1. db>
1. select b'binary \x01\x02\x03\x04 ftw!'[8];
1. {b'\x02'}
operator
bytes[from:to]

bytes [ int64 : int64 ] -> bytes
Bytes slicing.
Examples:
1. db>
1. select b'\x01\x02\x03\x04 ftw!'[2:-1];
1. {b'\x03\x04 ftw'}
1. db>
1. select b'some bytes'[2:-3];
1. {b'me by'}
operator
bytes ++ bytes

bytes ++ bytes -> bytes
Bytes concatenation.
1. db>
1. select b'\x01\x02' ++ b'\x03\x04';
1. {b'\x01\x02\x03\x04'}
function
bytes_get_bit()

std::bytes_get_bit(bytes: bytes, nth: int64) -> int64
Get the nth bit of the bytes value.
When looking for the nth bit, this function enumerates bits from least to most significant in each byte.
1. db>
2. ...
3. ...
1. for n in {0, 1, 2, 3, 4, 5, 6, 7,
2. 8, 9, 10, 11, 12, 13 ,14, 15}
3. union bytes_get_bit(b'ab', n);
1. {1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0}
