Bytes
Module bytes
import bytes
| Module | bytes |
| Source | bytes/bytes.zirr, bytes/module-docs.zirr |
Raw byte sequences and the conversions into them.
bytes works on prelude.Binary, the type that carries raw bytes. Most functions accept Like, so a single prelude.Byte can be passed anywhere a Binary is expected.
Text crosses the boundary explicitly: fromString and toString convert through UTF-8, and toHex and fromHex through hexadecimal. Indexing a Binary yields a Byte and iterating one yields bytes, never characters — for characters, convert to String and use strings.
Dependencies
Contents
- Unions —
Like - Functions —
concat,contains,firstIndexOf,from,fromChar,fromHex,fromString,hasPrefix,hasSuffix,lastIndexOf,range,repeat,slice,toHex,toString
Unions
Like
`bytes/bytes.zirr:6`
union Like {
Byte
Binary
}
A single byte or a sequence of bytes.
Cases
| Case | Interpretation |
|---|---|
Byte |
A single byte. |
Binary |
A sequence of raw bytes. Can be indexed and iterates over Byte. |
Functions
concat
`bytes/bytes.zirr:93`
fn concat(parts: [Like]) -> Binary
Concatenates every part into a single Binary, in order.
contains
`bytes/bytes.zirr:68`
fn contains(v: Like, needle: Like) -> Bool
Returns whether needle occurs anywhere in v.
firstIndexOf
`bytes/bytes.zirr:48`
fn firstIndexOf(v: Like, needle: Like) -> Option
Returns the index of needle’s first occurrence in v, or None if absent.
from
`bytes/bytes.zirr:12`
extern fn from(v: Like) -> Binary
Normalizes a Byte or Binary to Binary.
fromChar
`bytes/bytes.zirr:18`
extern fn fromChar(c: Char) -> Binary
Returns the UTF-8 byte representation of c. A Char can be 1-4 bytes.
fromHex
`bytes/bytes.zirr:27`
extern fn fromHex(str: String) -> Binary
Decodes a hex string (two digits per byte, either case) into Binary.
fromString
`bytes/bytes.zirr:15`
extern fn fromString(str: String) -> Binary
Returns the UTF-8 byte representation of str.
hasPrefix
`bytes/bytes.zirr:73`
fn hasPrefix(v: Like, prefix: Like) -> Bool
Returns whether v starts with prefix.
hasSuffix
`bytes/bytes.zirr:83`
fn hasSuffix(v: Like, suffix: Like) -> Bool
Returns whether v ends with suffix.
lastIndexOf
`bytes/bytes.zirr:58`
fn lastIndexOf(v: Like, needle: Like) -> Option
Returns the index of needle’s last occurrence in v, or None if absent.
range
`bytes/bytes.zirr:33`
fn range(v: Like, r: ranges.Like) -> Binary
Returns the bytes of v selected by r.
repeat
`bytes/bytes.zirr:102`
fn repeat(v: Like, n: Int) -> Binary
Returns v repeated n times.
slice
`bytes/bytes.zirr:30`
extern fn slice(v: Like, start: Int, end: Int) -> Binary
Returns the bytes of v from start (inclusive) to end (exclusive).
toHex
`bytes/bytes.zirr:24`
extern fn toHex(v: Like) -> String
Returns v’s hex representation, two lowercase digits per byte.
toString
`bytes/bytes.zirr:21`
extern fn toString(v: Like) -> String
Reinterprets v’s bytes as a String.