knopp / msgpack_dart

MsgPack implementation for dart / msgpack.org[Dart]
MIT License
56 stars 13 forks source link

Make offset available publicly in Decoder #6

Open aliafshar opened 3 years ago

aliafshar commented 3 years ago

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 commented 3 years ago

I mean Deserializer, sorry.

aliafshar commented 3 years ago

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;
}