本文介绍了我怎么能串在实习protobuf网?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用V2转421。当我救了protobuf网制作并把它通过琴弦工具流,它发现了许多重复的字符串。我说的是由应用程序生成的字符串,可以拘留,但该字符串实习似乎并不在默认情况下打开。

I am using v2 rev 421.When I saved the stream produced by protobuf-net and put it through the strings utility, it discovered many duplicate strings. I am talking about the strings produced by the application, which can be interned, but the string interning does not seem to be on by default.

我如何使它?

感谢。

推荐答案

有两个不同的类型在这里实习的;还有的实习反序列化的 的 - 这是始终处于启用状态,所以如果重复是在数据的,你应该只看到一个.NET 字符串比如在你的托管类,再用来作为根据需要多次。

There are two separate types of interning here; there's interning while deserializing - this is always enabled, so if duplicates are in the data, you should only see a single .NET string instance in your managed classes, re-used as many times as needed.

还有实习的 的,避免重复的数据到流,同时序列化。这是没有在默认情况下,对于没有这样的行为是在protobuf的规范中定义的理由很简单; protobuf网试图留在规范默认情况下在里面,只能通过扩展上一个选择的依据。

There is also interning while serializing, to avoid duplicating data into the stream while serializing. This is not on by default, for the simple reason that no such behaviour is defined in the protobuf spec; protobuf-net tries to stay inside the spec by default, only using extensions on an opt-in basis.

如果您想要启用此为protobuf网=来= protobuf网的使用情况,然后启用 AsReference 选项对于任何给定的字符串:

If you want to enable this for protobuf-net=to=protobuf-net usage, then enable the AsReference option for any given string:

[ProtoMember(13, AsReference = true)]
public string Foo { get; set; }

此使用protobuf网的实现特定的的再presentation。它不会起到非常漂亮互操作的目的,但是。如果您需要这一个可互操作的方式,唯一要做的就是存储列表的单独的(或许在名单,其中,串> 的地方),和使用在数据列表中的位置,即

This uses a protobuf-net implementation-specific representation. It won't play very nicely for interop purposes, however. If you need this in an interoperable way, the only thing to do is store the lists separately (perhaps in a List<string> somewhere), and use the position in the list in your data, i.e.

// this is .... uglier, but probably easier if you need cross-platform
public int FooOffset {
    get { return Foos.IndexOf(Foo); }
    set { Foo = Foos[value]; }
}

这篇关于我怎么能串在实习protobuf网?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 09:41