method Decoder.beginList
D-8344. The reader of Encoder.beginList(len) / endList(): a List, Set or array. Returns the number of elements; the
caller reads that many values and calls endList().
Example:
use std.ser { Codec, Encoder, Decoder, Schema, encode, decode, hex, EncodeError, DecodeError }
data Ids {}
impl Codec<List<i64>> for Ids {
static fn encode(x: &List<i64>, w: &var Encoder) -> () | EncodeError {
w.beginList(x.len())
for v in x { w.writeI64(v) }
w.endList()
}
static fn decode(r: &var Decoder) -> List<i64> | DecodeError {
let n = r.beginList()?
var out: List<i64> = []
var i = 0
while i < n {
out.push(r.readI64()?)
i += 1
}
r.endList()
out
}
static fn schema() -> Schema => Schema.of("repeated int64")
}var fn beginList() -> usize | DecodeErrorС версии. 1.0.0-beta
Возвращает
usize
Ошибки
DecodeError@error- `DecodeError.Malformed` when the next value is not a list (the default does this: a format that reads collections implements it).
Эффекты
не объявлены (чистая, пока тело не говорит иное)
Определено в: std/ser/ser.oxl:1769