msgpack_dart icon indicating copy to clipboard operation
msgpack_dart copied to clipboard

Make offset available publicly in Decoder

Open aliafshar opened this issue 5 years ago • 2 comments
trafficstars

I think that if the offset was available publicly I could parse messages that have become concatenated on a stream like:

[1, 2, 3][4, 5, 6]

By using the offset to split the original byte array. Otherwise I can't think of a sensible way of parsing that. If you are ok with that, and the concept is correct, I am happy to make a PR. For now I will just copy-paste and modify the code.

aliafshar avatar Oct 10 '20 07:10 aliafshar

I mean Deserializer, sorry.

aliafshar avatar Oct 10 '20 07:10 aliafshar

I've just tested and it works fine, quick hack example once _offset is offset

List<dynamic> deserializeMany(List<int> data) {
  final d = Deserializer(data);
  final List<dynamic> results = [];
  var keepDecoding = true;
  while (keepDecoding) {
    results.add(d.decode());
    keepDecoding = d.offset < data.length;
  }
  return results;
}

aliafshar avatar Oct 10 '20 07:10 aliafshar