You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@knopp Would you entertain a change that would let a user of the library have more control over how deserialized Arrays and Maps are built?
I'm working on an implementation of Cognitect's transit for Dart and in order to support MessagePack I need some guarantees about map entry orders. If such a hook was available in this API, I would be able to intercept the keys and values as they are being deserialized and be able to preserve their insertion order.
import'dart:collection';
abstractclassMapBuilder<G, M, K, V> {
// Initialize a new (gestational) mapGinit();
// Add key and val to the gestational map, return new gestational map, which// must be used for the next invocation.Gadd(G m, K key, V val);
// Convert gestational map into final map and return it.Mcomplete(G m);
}
// This is the default builder if the user does not provide a custom one.classMapBuilderImplimplementsMapBuilder<Map, Map, dynamic, dynamic> {
@overrideinit() =>Map();
@overrideadd(m, key, val) {
m[key] = val;
return m;
}
@overridecomplete(m) => m;
}
classDeserializer {
finalExtDecoder? _extDecoder;
finalMapBuilder _mapBuilder; //<-- this is newfinal codec =Utf8Codec();
finalUint8List _list;
finalByteData _data;
int _offset =0;
Deserializer(
Uint8List list, {
ExtDecoder? extDecoder,
this.copyBinaryData =false,
MapBuilder? mapBuilder //<-- this is new
}) : _list = list,
_data =ByteData.view(list.buffer, list.offsetInBytes),
_extDecoder = extDecoder,
_mapBuilder = mapBuilder ??MapBuilderImpl(); //<-- this is new// ... SKIPPING ...// Delegates to `mapBuilder` for actual map construction, always passing in// the result of the previous call as input to the next call.Map_readMap(int length) {
var mr = _mapBuilder.init();
while (length >0) {
mr = _mapBuilder.add(mr, decode(), decode());
--length;
}
return _mapBuilder.complete(mr);
}
}
In my case, I would register a MapBuilder that initialized a LinkHashMap in order to preserve insertion order.
If this is something you'd consider, I'll create a PR. If not, I'll just create a fork.
The text was updated successfully, but these errors were encountered:
@knopp Would you entertain a change that would let a user of the library have more control over how deserialized Arrays and Maps are built?
I'm working on an implementation of Cognitect's transit for Dart and in order to support MessagePack I need some guarantees about map entry orders. If such a hook was available in this API, I would be able to intercept the keys and values as they are being deserialized and be able to preserve their insertion order.
In my case, I would register a MapBuilder that initialized a LinkHashMap in order to preserve insertion order.
If this is something you'd consider, I'll create a PR. If not, I'll just create a fork.
The text was updated successfully, but these errors were encountered: