Bytes Utility
Bytes value operations. No hidden external Service communication.
Contract Bytes · 1.0.0-draft.1
Functions
encode
Any AIScript data value as bytes: strings encode directly, bytes pass unchanged, all other data values serialize as JSON and encode. The charset applies to the resulting text; unencodable text fails. Handles and cycles fail.
| Argument | Type | Required | Default |
|---|---|---|---|
| value | core.data | Yes | — |
| charset | core.string | No | "UTF-8" |
Returns: core.bytes
decode
String; reject malformed sequences.
| Argument | Type | Required | Default |
|---|---|---|---|
| value | core.bytes | Yes | — |
| charset | core.string | No | "UTF-8" |
Returns: core.string
size
Integer byte count.
| Argument | Type | Required | Default |
|---|---|---|---|
| value | core.bytes | Yes | — |
Returns: core.integer
slice
New checked byte range.
| Argument | Type | Required | Default |
|---|---|---|---|
| value | core.bytes | Yes | — |
| start | core.integer | Yes | — |
| count | core.integer | Yes | — |
Returns: core.bytes
concat
New bytes from an array of byte sequences.
| Argument | Type | Required | Default |
|---|---|---|---|
| parts | Bytes.Parts | Yes | — |
Returns: core.bytes
base64
Standard padded Base64 encode/strict decode.
| Argument | Type | Required | Default |
|---|---|---|---|
| value | core.bytes | Yes | — |
Returns: core.string
fromBase64
Standard padded Base64 encode/strict decode.
| Argument | Type | Required | Default |
|---|---|---|---|
| text | core.string | Yes | — |
Returns: core.bytes
hex
Lowercase hexadecimal encode; strict even-length decode.
| Argument | Type | Required | Default |
|---|---|---|---|
| value | core.bytes | Yes | — |
Returns: core.string
fromHex
Lowercase hexadecimal encode; strict even-length decode.
| Argument | Type | Required | Default |
|---|---|---|---|
| text | core.string | Yes | — |
Returns: core.bytes
Behavior
- Bytes are immutable. Standard charsets are UTF-8, US-ASCII and ISO-8859-1. Decode is strict; malformed or unencodable data fails.
- encode passes bytes unchanged, encodes strings directly, and serializes all other data through Object.asString before encoding. Explicit null encodes the text null. Handles and cycles fail.
- Base64 is standard padded encoding with strict decoding. Hex encoding is lowercase; decoding requires an even-length valid value. Other encodings require an explicit extension contract.