OxL Reference

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:

oxl✓ checked in CI
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

Since. 1.0.0-beta

Returns

usize

Errors

  • DecodeError @error
  • `DecodeError.Malformed` when the next value is not a list (the default does this: a format that reads collections implements it).

Effects

none declared (pure unless the body says otherwise)

Defined in: std/ser/ser.oxl:1769

See also