[protobuf] repeated field problem with protobuf-net (other side: java protobuf)

2012-06-18 Thread 13Homer
proto file:
package nemesis;

option java_package = IQFeedServer.protobuf;
option java_outer_classname = Protos;

option optimize_for = SPEED;

message V3DDelta {
   optional int32 bid = 1;
   optional int32 bidSize = 2;
   optional int32 ask = 3;
   optional int32 askSize = 4;
}

message Request {
   optional int32 type = 1;
   optional string request = 2;
}

message Response {
   optional int32 type = 1;
   optional string response = 2;
   repeated V3DDelta v3dDelta = 3;
}


protobuf-net classes:
[ProtoContract]
public class V3DDelta {
   [ProtoMember(1)]
   public double bid { get; set; }
   [ProtoMember(2)]
   public int bidSize { get; set; }
   [ProtoMember(3)]
   public double ask { get; set; }
   [ProtoMember(4)]
   public int askSize { get; set; }
}

[ProtoContract]
public class Request {
   [ProtoMember(1)]
   public int Type { get; set; }
   [ProtoMember(2)]
   public string Rq { get; set; }
}

[ProtoContract]
public class Response {
   [ProtoMember(1)]
   public int Type { get; set; }
   [ProtoMember(2)]
   public string Rsp { get; set; }
   [ProtoMember(3)]
   public ListV3DDelta v3dDelta { get; set; }
   public Response() {
   v3dDelta = new ListV3DDelta();
   }
}

When i'm sending message with v3dDeltas (doesn't matter 1 or more) i've got 
this:
 Invalid wire-type; this usually means you have over-written a file without 
truncating or setting the length; see 
http://stackoverflow.com/q/2152978/23354

The message is:
9 8 5 26 5 8 233 98 16 1
and is exactly the same on the other side (there's no other bytes in 
buffer). I'm reading it that way:
Response rsp = Serializer.DeserializeWithLengthPrefixResponse(rcvstream, 
PrefixStyle.Base128);
(it is encoded using writeDelimitedTo on the java side).

It is right to use List for repeated fields? I tried use array (V3DDelta[]) 
but exception is the same. When there was no  v3dDelta field everything 
works great. I'm missing something?

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/jfYetWUvXiAJ.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



[protobuf] Is there any possible way bind Protocol Buffer with Hibernate,MyBatis Or JDBC

2012-06-18 Thread Jessen Gan
Recently,I used Protocol Buffer as a middleware to trans data between 
server and mobile_client.Read data from database by hibernate into java 
entities,then add into Protocol Buffer Object property one by one.It's a 
very heavy method.

But I googled many key worlds to find a shortcut to do the this.the result 
is null.


Did any one have this situation like me

How did you handle this.

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/ysFQ9w8OwV0J.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

attachment: QQ截图20120618100308.png

Re: [protobuf] Is there any possible way bind Protocol Buffer with Hibernate,MyBatis Or JDBC

2012-06-18 Thread Oliver Jowett
On Mon, Jun 18, 2012 at 3:07 AM, Jessen Gan jessen...@gmail.com wrote:
 Recently,I used Protocol Buffer as a middleware to trans data between server
 and mobile_client.Read data from database by hibernate into java
 entities,then add into Protocol Buffer Object property one by one.It's a
 very heavy method.

 But I googled many key worlds to find a shortcut to do the this.the result
 is null.

If you have a set of rules that map your Java fields/methods to
protobuf field names, then you could build the message reflectively
via DynamicMessage.Builder, perhaps?

Oliver

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] repeated field problem with protobuf-net (other side: java protobuf)

2012-06-18 Thread Marc Gravell
I answered this at stackoverflow (http://stackoverflow.com/a/11083229/23354)

The main problem was the data-types in V3DDelta not matching the contract
(note: there are tools for generating classes from a .proto definition).

The particular code for reading the data stored via writeDelimitedTo
needed a particular call:

int len = ProtoReader.DirectReadVarintInt32(source);
var resp = (Response)model.Deserialize(source , null, typeof(Response),
len);

Marc
(protobuf-net)

On 18 June 2012 10:07, 13Homer 13zzpa...@gmail.com wrote:

 proto file:
 package nemesis;

 option java_package = IQFeedServer.protobuf;
 option java_outer_classname = Protos;

 option optimize_for = SPEED;

 message V3DDelta {
optional int32 bid = 1;
optional int32 bidSize = 2;
optional int32 ask = 3;
optional int32 askSize = 4;
 }

 message Request {
optional int32 type = 1;
optional string request = 2;
 }

 message Response {
optional int32 type = 1;
optional string response = 2;
repeated V3DDelta v3dDelta = 3;
 }


 protobuf-net classes:
  [ProtoContract]
 public class V3DDelta {
[ProtoMember(1)]
public double bid { get; set; }
[ProtoMember(2)]
public int bidSize { get; set; }
[ProtoMember(3)]
public double ask { get; set; }
[ProtoMember(4)]
public int askSize { get; set; }
 }

 [ProtoContract]
 public class Request {
[ProtoMember(1)]
public int Type { get; set; }
[ProtoMember(2)]
public string Rq { get; set; }
 }

 [ProtoContract]
 public class Response {
[ProtoMember(1)]
public int Type { get; set; }
[ProtoMember(2)]
public string Rsp { get; set; }
[ProtoMember(3)]
public ListV3DDelta v3dDelta { get; set; }
public Response() {
v3dDelta = new ListV3DDelta();
}
 }

 When i'm sending message with v3dDeltas (doesn't matter 1 or more) i've
 got this:
  Invalid wire-type; this usually means you have over-written a file
 without truncating or setting the length; see
 http://stackoverflow.com/q/2152978/23354

 The message is:
 9 8 5 26 5 8 233 98 16 1
 and is exactly the same on the other side (there's no other bytes in
 buffer). I'm reading it that way:
 Response rsp = Serializer.DeserializeWithLengthPrefixResponse(rcvstream,
 PrefixStyle.Base128);
 (it is encoded using writeDelimitedTo on the java side).

 It is right to use List for repeated fields? I tried use array
 (V3DDelta[]) but exception is the same. When there was no  v3dDelta field
 everything works great. I'm missing something?

  --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/protobuf/-/jfYetWUvXiAJ.
 To post to this group, send email to protobuf@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/protobuf?hl=en.




-- 
Regards,

Marc

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



[protobuf] Best practices for proto file organization in large projects

2012-06-18 Thread Justin Muncaster
Hello,

I've been using protocol buffers for a while, and I love the library, 
however I find that when using them in large projects I generally have to 
fight with the compiler to get protoc to play nicely with my build 
system. My projects are organized as follows:

common/foo/foo.h
common/foo/foo.cpp
common/foo/foo.proto
...
common/bar/bar.h
common/bar/bar.cpp
common/bar/bar.proto

where bar.proto contains
  import common/foo/foo.proto

... and elsewhere...
app1/baz.proto
...
app1/fud.proto 

and baz.proto and fud.proto contain
  import common/bar/bar.proto
 

I'm currently changing our build system to be cmake based and I'm again 
finding myself fighting with the build system to get the .proto to be 
automatically generated in a way where they build correctly. This leads me 
to believe that I am doing something wrong or at least not organizing files 
in a way that is expected. In light of that,

How do you organize your proto files when you have many in common 
libraries? Do all .proto files live in one folder? Should one avoid import 
a/b/c/d/f.proto? Do you have any recommendations for how one ought one 
setup the cmake build system to work with proto files that are organized as 
they are above? Any general recommendations?

Thanks,

Justin 

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/S24EsiM971cJ.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.