method Decoder.readBytes
Reads a byte string.
Example:
use std.ser { Codec, Encoder, Decoder, Schema, encode, decode, hex, EncodeError, DecodeError }
data Raw {}
impl Codec<bytes> for Raw {
static fn encode(x: &bytes, w: &var Encoder) -> () | EncodeError { w.writeBytes(x) }
static fn decode(r: &var Decoder) -> bytes | DecodeError { r.readBytes() }
static fn schema() -> Schema => Schema.of("bytes")
}
data Wrap {
@codec(Raw) blob: bytes
}
fn main() io {
let b = encode(&Wrap{ blob: b"\x01\x02\x03" })!
print("{decode<Wrap>(&b)!.blob.len()}")
}Output
3
var fn readBytes() -> bytes | DecodeErrorSince. 1.0.0-beta
Returns
bytes
Errors
DecodeError@error- `DecodeError.Malformed` when the next value is not a byte string.
Effects
none declared (pure unless the body says otherwise)
Defined in: std/ser/ser.oxl:1669