Removing Protobuf-Net Object Deserialization Using a Filter

I use protobuf-net in one of our projects to serialize / deserialize a large set of homogeneous objects. It works quite well and the speed is fantastic. Just one question. Although deserialization allows you to use linq (or any other mechanism) to specify filter criteria so that objects that satisfy only these criteria are loaded? It is trivial to deserialize ALL objects and then apply the linq filter, but I want to reduce the number of objects loaded into memory. Filter criteria can be quite dynamic, so the string type of the mechanism will be fantastic (something like dlinq?).

+3
source share
2 answers

There is nothing built-in, but if you have a well-defined precedent, I can certainly see (I am the author).

Currently, I would suggest using some option:

var found = Serializer.DeserializeItems<A>(source, PrefixStyle.Base128,
         Serializer.ListItemTag).FirstOrDefault(obj => obj.Foo = "bar");

if(found != null) {...}

which will close when a match is found and will immediately release objects for collection (hopefully in gen-0). Or for several elements, perhaps:

var list = Serializer.DeserializeItems<A>(source, PrefixStyle.Base128,
         Serializer.ListItemTag).Where(obj => obj.Foo = "bar").ToList();

(which quickly releases inappropriate elements)

To do this in the general case (especially for more complex queries), I can't think of a reasonable way to do this without materializing the object, so this is probably as close as you can get if there is no very specific (and simple) scenario , which goes well with the underlying data store (for example, the filter is always on "tag 1").

+2
source

, , , , . , , , .

, , , .

( ) , , - , .

+1

Source: https://habr.com/ru/post/1788949/


All Articles