与protobuf网质量过滤 [英] Mass filtering with protobuf-net

查看:184
本文介绍了与protobuf网质量过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经系列化与protobuf网对象的列表。

I have serialized a list of objects with protobuf-net.

从理论上讲,.bin文件可以包含对象的数以百万计。

Theoretically, the .bin file can contain millions of objects.

让我们假设对象是含有以下一类的:

Let's assume the objects are of a class containing the following:

public string EventName;

我必须采取一个查询并创建包含匹配查询的对象列表。 什么是提取序列化的文件中使用LINQ的匹配对象的正确方法?

I have to take a query and create a list containing the objects matching the query. What is the correct way to extract the matching objects from the serialized file using LINQ?

推荐答案

在protobuf的格式是项目的线性序列;任何索引等你的方法只能是单独适用。然而,的IEnumerable< T> 可用;你可能会发现:

The protobuf format is a linear sequence of items; any indexing etc you way can only be applies separately. However, IEnumerable<T> is available; you might find that:

var item = Serializer.DeserializeItems<YourType>(source)
       .First(item => item.Id == id);

做这项工作很好;这样的:

does the job nicely; this:

  • 是懒洋洋地缠绕;每个项目都是单独产生,因此你不需要的内存供过于求
  • 被短路;如果该项目启动不久发现,它会立即退出

或者多个项目:

var list = Serializer.DeserializeItems<YourType>(source)
    .Where(item => item.Foo == foo);

(添加了ToList以上的TE结束时,如果你想在内存中缓冲匹配的项目,或者使用不带了ToList如果你只是想在一个前锋,唯一方法解析)

(add a ToList to te end of the above if you want to buffer the matching items in memory, or use without a ToList if you just want to parse it once in a forwards-only way)

这篇关于与protobuf网质量过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆