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()}")
}Вывод
3
var fn readBytes() -> bytes | DecodeErrorС версии. 1.0.0-beta
Возвращает
bytes
Ошибки
DecodeError@error- `DecodeError.Malformed` when the next value is not a byte string.
Эффекты
не объявлены (чистая, пока тело не говорит иное)
Определено в: std/ser/ser.oxl:1669