Search Results

Search found 73 results on 3 pages for 'protobuf'.

Page 1/3 | 1 2 3  | Next Page >

  • How to process a .proto file using protobuf-net

    - by JustSmith
    I have stated using the protobuf-net lib to communication between some of the programs I'm maintaining. I have also been able to decode messages from C# to Ruby. My ruby ProtoBuf lib is using a .proto file to generate the ruby code. In the interest of having to make changes in as few places as possible I would like to have protobuf-net use the same .proto file. Looking though the protobuf-net folders there is a Dll named ProtoBufGenerator and the protobuf exe but I cant find any instructions on if I can make protobuf-net work this way. Is this possible?

    Read the article

  • How to choose between protobuf-csharp-port and protobuf-net

    - by PierrOz
    Hi Folks, I've recently had to look for a C# porting of the Protocole Buffer library originally developped by Google. And guess what, I found two projects owned both by two very well known persons here: protobuf-csharp-port, written by Jon Skeet and protobuf-net, written by Mark Gravell. My question is simple: which one do I have to choose ? I quite like Mark's solution as it seems to me closer to C# philisophy (for instance, you can just add attributes to the properties of existing class) and it looks like it can support .NET built-in types such as System.Guid. I am sure both of them are really great projects but what's your oppinion?

    Read the article

  • Serialization of non-required fields in protobuf-net

    - by David Hedlund
    I have a working java client that is communicating with Google, through ProtoBuf serialized messages. I am currently trying to translate that client into C#. I have a .proto file where the parameter appId is an optional string. Its default value in the C# representation as generated by the protobuf-net library is an empty string, just as it is in the java representation of the same file. message AppsRequest { optional AppType appType = 1; optional string query = 2; optional string categoryId = 3; optional string appId = 4; optional bool withExtendedInfo = 6; } I find that when I explicitly set appId to "" in the java client, the client stops working (403 Bad Request from Google). When I explicitly set appId to null in the java client, everything works, but only because hasAppId is being set to false (I'm uncertain as to how that affects the serialization). In the C# client, I always get 403 responses. I don't see any logic behind the distinction between not setting a value, and setting the default value, that seems to make all the difference in the java client. Since the output is always a binary stream, I am not sure if the successful java messages are being serialized with an empty string, or not serialized at all. In the C# client, I've tried setting IsRequired to true on the ProtoMember attribute, to force them to serialize, and I've tried setting the default value to null, and explicitly set "", so I'm quite sure I've tried some configuration where the value is being serialized. I've also played around with ProtoBuf.ProtoIgnore and at some point, removing the appId parameter altogether, but I haven't been able to avoid the 403 errors in C#. I've tried manually copying the serialized string from java, and that resolved my issues, so I'm certain that the rest of the HTTP Request is working, and the error can be traced to the serialized object. My serialization is simply this: var clone = ProtoBuf.Serializer.DeepClone(request); MemoryStream ms = new MemoryStream(2000); ProtoBuf.Serializer.Serialize(ms, clone); var bytearr = ms.ToArray(); string encodedData = Convert.ToBase64String(bytearr); I'll admit to not being quite sure about what DeepClone does. I've tried both with and without it...

    Read the article

  • Program hangs when calling parseFrom for java implementation of protobuf

    - by cornerback84
    I have a message (say its called OuterMessage) message OuterMessage { optional int64 id = 1; optional InnerMessage inner = 2; } and an inner message message InnerMessage { optional string type = 1; optioanl int64 id = 2; } Now when I call parseFrom on OuterMessage like OuterMessage.parseFrom(buffer) the method never returns and nor does it throw any exception. But if I do InnerMessage.parseFrom(buffer) it returns an empty InnerMessage instance. I am serializing the message using protobuf-net. Any idea what might be causing the issue?

    Read the article

  • protobuf-net: Issues deserializing DataMember fields in lieu of read-only property

    - by Paul Smith
    I'm having issues deserializing certain properties of ORM-generated entities using protobuf-net. I suspect something in the way the ORM manages serialization attributes on read-only properties (uses public backing fields with DataMember attributes & [de]serializes) those instead of the corresponding read-only property, which has an IgnoreDataMember attribute). Guid properties might have issues of their own, but the field vs. property thing is my working theory now. Here's a simplified example of the code. Say I have a class, Account with an AccountID read-only guid, and an AccountName read-write string. I serialize & immediately deserialize a clone. In this scenario I get one of two results (depending on the entity, haven't isolated the specific commonality yet). The deserialized clone either: ...has a different AccountID from the original, or ...throws an Incorrect wire-type deserializing Guid exception while deserializing. Here's example usage... Account acct = new Account() { AccountName = "Bob's Checking" }; Debug.WriteLine(acct.AccountID.ToString()); using (MemoryStream ms = new MemoryStream()) { ProtoBuf.Serializer.Serialize<Account>(ms, acct); Debug.WriteLine(Encoding.UTF8.GetString(ms.GetBuffer())); ms.Position = 0; Account clone = ProtoBuf.Serializer.Deserialize<Account>(ms); Debug.WriteLine(clone.AccountID.ToString()); } And here's an example ORM'd class (simplified; hopefully haven't removed the cause of the issue in the process). Uses a shell game to deserialize read-only properties by exposing the backing field ("can't write" essentially becomes "shouldn't write," but we can scan code for instances of assigning to these fields, so the hack works for our purposes): [DataContract()] [Serializable()] public partial class Account { public Account() { _accountID = Guid.NewGuid(); } [XmlAttribute("AccountID")] [DataMember(Name = "AccountID", Order = 0)] public Guid _accountID; /// <summary> /// A read-only property; XML, JSON and DataContract serializers all seem /// to correctly recognize the public backing field when deserializing: /// </summary> [IgnoreDataMember] [XmlIgnore] public Guid AccountID { get { return this._accountID; } } [IgnoreDataMember] protected string _accountName; [DataMember(Name = "AccountName", Order = 1)] [XmlAttribute] public string AccountName { get { return this._accountName; } set { this._accountName = value; } } } XML, JSON and DataContract serializers all seem to serialize / deserialize matching object graphs here, so this attribute arrangement apparently causes those serializers to correctly assign to the public backing field when deserializing. I've tried protobuf-net with lists vs. single instances, different prefix styles, etc., but always either get the 'incorrect wire type ... Guid' exception, or the Guid property (field) not deserializing correctly. So the specific questions are, is there a quick workaround for this, and/or is there an explanation for both of outcomes 1 & 2 above, and/or can protobuf-net somehow be corralled into behaving like WCF in cases like this (i.e. follow the same DataMember/IgnoreDataMember semantics)? We hope not to have to create a protobuf dependency directly in the entity layer; if that's the case, we'll probably create proxy DTO entities with all public properties having protobuf attributes. (This is a subjective issue I have with all declarative serialization models; it's a ubiquitous pattern, but IMO, "normal" should be to have objects and serialization contracts decoupled.) Thanks!

    Read the article

  • Deserializing a type at the current stream position with protobuf-net

    - by Arne Claassen
    I'm serializing several objects into a single stream, but when i try to read them back, i can't seem to get anything but the last object: ProtoBuf.Serializer.Serialize(stream, postA1); ProtoBuf.Serializer.Serialize(stream, postB2); stream.Position = 0; var postA2 = ProtoBuf.Serializer.Deserialize<Post>(stream); var postB2 = ProtoBuf.Serializer.Deserialize<Post>(stream); The first deserialize moves the stream to the end and postA2 contains the value of postB2, while postB2 is just an uninitialized instance. Is this expected behavior, and if so, how do you deserialize an object from a random position in a stream?

    Read the article

  • Protobuf-net Deserialize Open Street Maps

    - by jonperl
    For the life of me I cannot deserialize the protobuf file from Open Street Maps. I am trying to deserialize the following extract: http://download.geofabrik.de/osm/north-america/us-northeast.osm.pbf to get Nodes and I am using http://code.google.com/p/protobuf-net/ as the library. I have tried to deserialize a bunch of different objects but they all come up null. The proto files can be found here: http://trac.openstreetmap.org/browser/applications/utils/export/osm2pgsql/protobuf Any suggestions?

    Read the article

  • protobuf-net: incorrect wire-type exception deserializing Guid properties

    - by Paul Smith
    I'm having issues deserializing certain Guid properties of ORM-generated entities using protobuf-net. Here's a simplified example of the code (reproduces most elements of the scenario, but doesn't reproduce the behavior; I can't expose our internal entities, so I'm looking for clues to account for the exception). Say I have a class, Account with an AccountID read-only guid, and an AccountName read-write string. I serialize & immediately deserialize a clone. Deserializing throws an Incorrect wire-type deserializing Guid exception while deserializing. Here's example usage... Account acct = new Account() { AccountName = "Bob's Checking" }; Debug.WriteLine(acct.AccountID.ToString()); using (MemoryStream ms = new MemoryStream()) { ProtoBuf.Serializer.Serialize<Account>(ms, acct); Debug.WriteLine(Encoding.UTF8.GetString(ms.GetBuffer())); ms.Position = 0; Account clone = ProtoBuf.Serializer.Deserialize<Account>(ms); Debug.WriteLine(clone.AccountID.ToString()); } And here's an example ORM'd class (simplified, but demonstrates the relevant semantics I can think of). Uses a shell game to deserialize read-only properties by exposing the backing field ("can't write" essentially becomes "shouldn't write," but we can scan code for instances of assigning to these fields, so the hack works for our purposes). Again, this does not reproduce the exception behavior; I'm looking for clues as to what could: [DataContract()] [Serializable()] public partial class Account { public Account() { _accountID = Guid.NewGuid(); } [XmlAttribute("AccountID")] [DataMember(Name = "AccountID", Order = 1)] public Guid _accountID; /// <summary> /// A read-only property; XML, JSON and DataContract serializers all seem /// to correctly recognize the public backing field when deserializing: /// </summary> [IgnoreDataMember] [XmlIgnore] public Guid AccountID { get { return this._accountID; } } [IgnoreDataMember] protected string _accountName; [DataMember(Name = "AccountName", Order = 2)] [XmlAttribute] public string AccountName { get { return this._accountName; } set { this._accountName = value; } } } XML, JSON and DataContract serializers all seem to serialize / deserialize these object graphs just fine, so the attribute arrangement basically works. I've tried protobuf-net with lists vs. single instances, different prefix styles, etc., but still always get the 'incorrect wire-type ... Guid' exception when deserializing. So the specific questions is, is there any known explanation / workaround for this? I'm at a loss trying to trace what circumstances (in the real code but not the example) could be causing it. We hope not to have to create a protobuf dependency directly in the entity layer; if that's the case, we'll probably create proxy DTO entities with all public properties having protobuf attributes. (This is a subjective issue I have with all declarative serialization models; it's a ubiquitous pattern & I understand why it arose, but IMO, if we can put a man on the moon, then "normal" should be to have objects and serialization contracts decoupled. ;-) ) Thanks!

    Read the article

  • protobuf-net NOT faster than binary serialization?

    - by Ashish Gupta
    I wrote a program to serialize a 'Person' class using XMLSerializer, BinaryFormatter and ProtoBuf. I thought protobuf-net should be faster than the other two. Protobuf serialization was faster than XMLSerialization but much slower than the binary serialization. Is my understanding incorrect? Please make me understand this. Thank you for the help. Following is the output:- Person got created using protocol buffer in 347 milliseconds Person got created using XML in 1462 milliseconds Person got created using binary in 2 milliseconds Code below using System; using System.Collections.Generic; using System.Linq; using System.Text; using ProtoBuf; using System.IO; using System.Diagnostics; using System.Runtime.Serialization.Formatters.Binary; namespace ProtocolBuffers { class Program { static void Main(string[] args) { string XMLSerializedFileName = "PersonXMLSerialized.xml"; string ProtocolBufferFileName = "PersonProtocalBuffer.bin"; string BinarySerializedFileName = "PersonBinary.bin"; var person = new Person { Id = 12345, Name = "Fred", Address = new Address { Line1 = "Flat 1", Line2 = "The Meadows" } }; Stopwatch watch = Stopwatch.StartNew(); watch.Start(); using (var file = File.Create(ProtocolBufferFileName)) { Serializer.Serialize(file, person); } watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds.ToString()); Console.WriteLine("Person got created using protocol buffer in " + watch.ElapsedMilliseconds.ToString() + " milliseconds " ); watch.Reset(); watch.Start(); System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(person.GetType()); using (TextWriter w = new StreamWriter(XMLSerializedFileName)) { x.Serialize(w, person); } watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds.ToString()); Console.WriteLine("Person got created using XML in " + watch.ElapsedMilliseconds.ToString() + " milliseconds"); watch.Reset(); watch.Start(); using (Stream stream = File.Open(BinarySerializedFileName, FileMode.Create)) { BinaryFormatter bformatter = new BinaryFormatter(); //Console.WriteLine("Writing Employee Information"); bformatter.Serialize(stream, person); } watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds.ToString()); Console.WriteLine("Person got created using binary in " + watch.ElapsedMilliseconds.ToString() + " milliseconds"); Console.ReadLine(); } } [ProtoContract] [Serializable] public class Person { [ProtoMember(1)] public int Id {get;set;} [ProtoMember(2)] public string Name { get; set; } [ProtoMember(3)] public Address Address {get;set;} } [ProtoContract] [Serializable] public class Address { [ProtoMember(1)] public string Line1 {get;set;} [ProtoMember(2)] public string Line2 {get;set;} } }

    Read the article

  • protobuf-net - backticks, Dictionaries & .proto files

    - by JosephH
    I'm trying to talk to a C# program that uses protobuf-net from an iphone using http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers Unfortunately the .proto file I've been given (generated from the C# source code) includes an a line that protoc is rejecting: repeated Pair_Guid_List`1 Local = 6; It appears that this is because the source data is a C# Dictionary, with a Guid key and a class as the value. Is there a way to cope with this better? The protobuf-net version in use is r278.zip. (The C# sending and receiving these protobufs all works fine, it's just when we add the iphone into the mix that this becomes an issue.)

    Read the article

  • protobuf-net: Incorrect wire-type deserializing TimeSpan

    - by balinisteanu
    I get this exception when my client application is trying to deserialize a message comming from WCF service ("Incorrect wire-type deserializing TimeSpan"). I'm using .NET 3.5 SP1 and latest version of protobuf-net (1.0.0.275). I have no idea what could be the issue comming from. I don't undersand the reason of this error message. Anyone?

    Read the article

  • RESTful .NET and protobuf-net

    - by rxm0203
    Is it possible to use protobuf-net in RESTful webservices using WCF RESTful starter kit or OpenRasta? If it possible, are there any examples or code snippets available? I am creating a .NET Web Service which will be consumed by Java client.

    Read the article

  • Google protobuf in Linux

    - by Ockonal
    Hello guys, I'm working with protobuf and Linux. Where is it's compiler protoc. I've downloaded package from main site, compiled and installed it successfully but I can't find protoc to build my own format file. Where is it?

    Read the article

  • Protobuf compiler for several languages

    - by Stipa
    Hi, In my project I have components written on Python, ObjectiveC and J2ME. I want to use protobuf as data interchange format. However, there are one issue I need to resolve. Google implementation doesn't support ObjC and J2ME. There are 3rd party implementations that supports those languages. But I really don't want to be depended of several protoc implementations. What is the best way for me to have protobufs for several languages? Do I need to use different compilers or there is other option? Thanks, -Lev

    Read the article

  • How can I send multiple types of objects across Protobuf?

    - by cyclotis04
    I'm implementing a client-server application, and am looking into various ways to serialize and transmit data. I began working with Xml Serializers, which worked rather well, but generate data slowly, and make large objects, especially when they need to be sent over the net. So I started looking into Protobuf, and protobuf-net. My problem lies in the fact that protobuf doesn't sent type information with it. With Xml Serializers, I was able to build a wrapper which would send and receive any various (serializable) object over the same stream, since object serialized into Xml contain the type name of the object. ObjectSocket socket = new ObjectSocket(); socket.AddTypeHandler(typeof(string)); // Tells the socket the types socket.AddTypeHandler(typeof(int)); // of objects we will want socket.AddTypeHandler(typeof(bool)); // to send and receive. socket.AddTypeHandler(typeof(Person)); // When it gets data, it looks for socket.AddTypeHandler(typeof(Address)); // these types in the Xml, then uses // the appropriate serializer. socket.Connect(_host, _port); socket.Send(new Person() { ... }); socket.Send(new Address() { ... }); ... Object o = socket.Read(); Type oType = o.GetType(); if (oType == typeof(Person)) HandlePerson(o as Person); else if (oType == typeof(Address)) HandleAddress(o as Address); ... I've considered a few solutions to this, including creating a master "state" type class, which is the only type of object sent over my socket. This moves away from the functionality I've worked out with Xml Serializers, though, so I'd like to avoid that direction. The second option would be to wrap protobuf objects in some type of wrapper, which defines the type of object. (This wrapper would also include information such as packet ID, and destination.) It seems silly to use protobuf-net to serialize an object, then stick that stream between Xml tags, but I've considered it. Is there an easy way to get this functionality out of protobuf or protobuf-net? I've come up with a third solution, and posted it below, but if you have a better one, please post it too!

    Read the article

  • Does protobuf-net generated binary compatible with Google specs

    - by cornerback84
    Actually I want to serialize my data using Google's java implementation and then deserialize using C# implementation? I have chosen portobuf-net as it seems to be more stable (porto# is still v0.9 or I would have gone for it). Before I start working on it I wanted to be sure that I can achieve this (serializing data using java implementation and deserializing it using potobuf-net). Or is there any list of methods that are specific to portobuf-net implementation?

    Read the article

  • Protobuf design patterns

    - by Monster Truck
    I am evaluating Google Protocol Buffers for a Java based service (but am expecting language agnostic patterns). I have two questions: The first is a broad general question: What patterns are we seeing people use? Said patterns being related to class organization (e.g., messages per .proto file, packaging, and distribution) and message definition (e.g., repeated fields vs. repeated encapsulated fields*) etc. There is very little information of this sort on the Google Protobuf Help pages and public blogs while there is a ton of information for established protocols such as XML. I also have specific questions over the following two different patterns: Represent messages in .proto files, package them as a separate jar, and ship it to target consumers of the service --which is basically the default approach I guess. Do the same but also include hand crafted wrappers (not sub-classes!) around each message that implement a contract supporting at least these two methods (T is the wrapper class, V is the message class (using generics but simplified syntax for brevity): public V toProtobufMessage() { V.Builder builder = V.newBuilder(); for (Item item : getItemList()) { builder.addItem(item); } return builder.setAmountPayable(getAmountPayable()). setShippingAddress(getShippingAddress()). build(); } public static T fromProtobufMessage(V message_) { return new T(message_.getShippingAddress(), message_.getItemList(), message_.getAmountPayable()); } One advantage I see with (2) is that I can hide away the complexities introduced by V.newBuilder().addField().build() and add some meaningful methods such as isOpenForTrade() or isAddressInFreeDeliveryZone() etc. in my wrappers. The second advantage I see with (2) is that my clients deal with immutable objects (something I can enforce in the wrapper class). One disadvantage I see with (2) is that I duplicate code and have to sync up my wrapper classes with .proto files. Does anyone have better techniques or further critiques on any of the two approaches? *By encapsulating a repeated field I mean messages such as this one: message ItemList { repeated item = 1; } message CustomerInvoice { required ShippingAddress address = 1; required ItemList = 2; required double amountPayable = 3; } instead of messages such as this one: message CustomerInvoice { required ShippingAddress address = 1; repeated Item item = 2; required double amountPayable = 3; } I like the latter but am happy to hear arguments against it.

    Read the article

  • Can protobuf-net serialize this combination of interface and generic collection?

    - by tsupe
    I am trying to serialize a ItemTransaction and protobuf-net (r282) is having a problem. ItemTransaction : IEnumerable<KeyValuePair<Type, IItemCollection>></code> and ItemCollection is like this: FooCollection : ItemCollection<Foo> ItemCollection<T> : BindingList<T>, IItemCollection IItemCollection : IList<Item> where T is a derived type of Item. ItemCollection also has a property of type IItemCollection. I am serializing like this: IItemCollection itemCol = someService.Blah(...); ... SerializeWithLengthPrefix<IItemCollection>(stream, itemCol, PrefixStyle.Base128); My eventual goal is to serialize ItemTransaction, but am snagged with IItemCollection. Item and it's derived types can be [de]serialized with no issues, see [1], but deserializing an IItemCollection fails (serializing works). ItemCollection has a ItemExpression property and when deserializing protobuf can't create an abstract class. This makes sense to me, but I'm not sure how to get through it. ItemExpression<T> : ItemExpression, IItemExpression ItemExpression : Expression ItemExpression is abstract as is Expression How do I get this to work properly? Also, I am concerned that ItemTransaction will fail since the IItemCollections are going to be differing and unknown at compile time (an ItemTransaction will have FooCollection, BarCollection, FlimCollection, FlamCollection, etc). What am I missing (Marc) ? [1] http://stackoverflow.com/questions/2276104/protobuf-net-deserializing-across-assembly-boundaries

    Read the article

  • In Protobuf-net how can I pass an array of type object with objects of different types inside, knowi

    - by cloudraven
    I am trying to migrate existing code that uses XmlSerializer to protobuf-net due to the increased performance it offers, however I am having problems with this specific case. I have an object[] that includes parameters that are going to be sent to a remote host (sort of a custom mini rpc facility). I know the set of types from which these parameters can be, but I cannot tell in advance in which order they are going to be sent. I have three constraints. The first is that I am running in Compact Framework, so I need something that works there. Second, as I mentioned performance is a big concern (on the serializing side) so I would rather avoid using a lot of reflection there if possible. And the most important is that I care about the order in which this parameters were sent. Using XmlSerializer it was easy just adding XmlInclude, but for fields there is nothing equivalent as far as I know in Protobuf-net. So, is there a way to do this? Here is a simplified example. [Serializable] [XmlInclude(typeof(MyType1)), XmlInclude(typeof(MyType2)), XmlInclude(typeof(MyType3)) public class Message() { public object[] parameters; public Message(object[] parms) { parameters = parms; } } Message m = new Message(new object[] {MyType1(), 33, "test", new MyType3(), new MyType3()}); MemoryStream ms = new MemoryStream(); XmlSerializer xml = new XmlSerializer(typeof(Message)); xml.Serialize(ms,xml); That will just work with XmlSerializer, but if I try to convert it to protobuf-net I will get a "No default encoding for Object" message. The best I came up with is to use generics and [ProtoInclude] as seen in this example. Since I can have different object types within the array this doesn't quite make it. I added a generic List for each potential type and a property with [ProtoIgnore] with type object[] to add them and get them. I have to use reflection when adding them (to know in which array to put each item) which is not desirable and I still can't preserve the ordering as I just extract all the items on each list one by one and put them into a new object[] array on the property get. I wonder if there is a way to accomplish this?

    Read the article

  • protobuf-net v2 alpha - problems with Dictionary<string,string>?

    - by Steve
    I was using a version of v2 of protobuf-net from a few weeks ago quite successfully. (I want to use V2 due to the speed of the pre-compiled serializer running on the Compact Framework.) Everything worked great until I tried to serialize an object with a property of type Dictionary. I received the following error: {"No serializer defined for type: System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"} It looked like there were recent changes made to improve Dictionary support, so I grabbed the latest code from today. After building the CF3.5 and FF3.5 dlls, I tried again. Now I get a different error "The model cannot be changed once frozen." If I remove the ProtoMember attribute from the Dictionary property all seems to work well. Has anyone succcessfully used a Dictionary in v2 of protobuf-net? Is this still too early of a release to be using? My speed tests showed v2 being twice as fast, does that seem accurate (validating my desire to use the less stable v2 pre-alpha bits.)

    Read the article

  • With Protobuf-net, does it allow deserialization reuse existing instances if they are the same?

    - by Stecy
    I'm using Protobuf-net. Suppose I have a list of Gizmo objects serialized and that each gizmo object reference a Gazoo object. The Gazoo object might be the same object referred by several Gizmo objects. How would deserialization work in this situation? Would I get more than one copies of Gazoos for the same referred one in the gizmo objects? What I would expect would be one copy of Gazoo for all the duplicates in the serialized data.

    Read the article

  • How do I read binary C++ protobuf data using Python protobuf?

    - by nbolton
    The Python version of Google protobuf gives us only: SerializeAsString() Where as the C++ version gives us both: SerializeToArray(...) SerializeAsString() We're writing to our C++ file in binary format, and we'd like to keep it this way. That said, is there a way of reading the binary data into Python and parsing it as if it were a string? Is this the correct way of doing it? binary = get_binary_data() binary_size = get_binary_size() string = None for i in range(len(binary_size)): string += i message = new MyMessage() message.ParseFromString(string) Update: Here's a new example, and a problem: message_length = 512 file = open('foobars.bin', 'rb') eof = False while not eof: data = file.read(message_length) eof = not data if not eof: foo_bar = FooBar() foo_bar.ParseFromString(data) When we get to the foo_bar.ParseFromString(data) line, I get this error: Exception Type: DecodeError Exception Value: Too many bytes when decoding varint. Update 2: It turns out, that the padding on the binary data was throwing protobuf off; too many bytes were being sent in, as the message suggests (in this case it was referring to the padding). This padding comes from using the C++ protobuf function, SerializeToArray on a fixed-length buffer. To eliminate this, I have used this temproary code: message_length = 512 file = open('foobars.bin', 'rb') eof = False while not eof: data = file.read(message_length) eof = not data string = '' for i in range(0, len(data)): byte = data[i] if byte != '\xcc': # yuck! string += data[i] if not eof: foo_bar = FooBar() foo_bar.ParseFromString(string) There is a design flaw here I think. I will re-implement my C++ code so that it writes variable length arrays to the binary file. As advised by the protobuf documentation, I will prefix each message with it's binary size so that I know how much to read when I'm opening the file with Python.

    Read the article

  • What's the .proto equivalent of List<T> in protobuf-net?

    - by Marc Bollinger
    To keep some consistency, we use code generation for a lot of our object models, and one of the offshoots of that has been generating the .proto files for ProtocolBuffers via a separate generation module. At this point though, I'm stumped at how to implement the generation for when it happens upon a List<T> object. It looks like this is possible via contracts: [ProtoMember(1)] public List<SomeType> MyList {get; set;} but outside of that, I'm not sure how or if it's possible to do this only from creating the .proto file/using the VS custom tool. Any thoughts?

    Read the article

1 2 3  | Next Page >