2010-03-29 32 views
1

我想谈谈使用protobuf网使用http://code.google.com/p/metasyntactic/wiki/ProtocolBuffersprotobuf网 - 反引号,字典和.proto文件

不幸的是我一直在考虑的.proto文件的iphone C#程序(产生从C#源代码)包括其protoc被拒绝的行:

repeated Pair_Guid_List`1 Local = 6; 

看来,这是因为源数据是一个C#词典,使用GUID键和类作为值。有办法更好地处理这个问题吗?

使用的protobuf-net版本是r278.zip。

(C#的发送和接收这些protobufs一切工作正常,只是当我们添加了iPhone混进去,这成为一个问题。)

UPDATE:现在所有的工作感谢马克!

在C#侧的对象竟然是:

[ProtoMember(7)] 
public Dictionary<Guid, List<Pages>> ReceivedPages { get; set; } 

其工作得很好利用在.proto以下:

message PagesDict { 
    required bcl.Guid guid = 1; 
    repeated Pages Pages = 2; 
} 
问题

与消息含有:

repeated PagesDict ReceivedPages = 7; 

回答

1

首先 - 你是否试图在上使用protobuf-net 的iPhone? v1预计不会通过单点触摸工作; v2 确实工作(这是v2工作的重要驱动因素),但尚未发布(目前可用但不完整)。让我知道,如果你想做到这一点,因为这将关系;-p

我希望他们已经通过调用​​,这是不幸的是没有防呆,像Dictionary<,>参与尤其是当获得的.proto (我会添加一个TODO来试图解决这个问题)。

好消息是,它的模型Dictionary<TKey,TValue>repeated someType,其中someType应该是:

message someType { 
    required keyType key = 1; 
    required valueType value = 2; 
} 

而且Guid建模为bcl.Guid(bcl.proto),它是:

message Guid { 
    optional fixed64 lo = 1; // the first 8 bytes of the guid 
    optional fixed64 hi = 2; // the second 8 bytes of the guid 
} 

注,但是,不需要“原始”根本不需要如果工作.NET到.NET;只是兼容的类型。

+0

谢谢你的回答马克! 我在iPhone上使用http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers - 这会从.proto文件生成本机Objective C代码。 他们的确在使用Serializer.GetProto 。 感谢您对建模的描述 - 我会尝试定义这样的消息。 – JosephH 2010-03-29 05:30:24

+0

只是说,我确实得到了这一切工作。 C#端的对象竟然是: [ProtoMember(7)] public Dictionary > ReceivedPages {get;组; } 在.proto中使用以下内容可以很好地工作: message PagesDict { required bcl.Guid guid = 1; 重复Pages Pages = 2; } 重复PagesDict ReceivedPages = 6; – JosephH 2010-05-19 10:21:42