Hi, See below for more information.
On Fri, 2009-08-07 at 16:58 +0200, Brice Figureau wrote: > Hi, > > Using Protobuf 2.1 with the following proto file: > > message Message { > enum Type { > AUTH = 100; > } > > required Type type = 1; > optional int32 id = 2; > > extensions 100 to max; > } > > message AuthRequest { > > extend Message { > optional AuthRequest auth_request = 100; > } > > required string name = 1; > required string pass = 2; > optional string nonce = 3; > optional string hmac = 4; > } > > When setting name and pass to arbitray values, I get the following > bytes: > {8, 100, 16, 0, -94, 6, 40, 10, 4, 116, 101, 115, 116, 18, 32, 48, 57, > 56, 70, 54, 66, 67, 68, 52, 54, 50, 49, 68, 51, 55, 51, 67, 65, 68, 69, > 52, 69, 56, 51, 50, 54, 50, 55, 66, 52, 70, 54}. > > If I print to text the corresponding message: > type: AUTH > id: 0 > [game.req.AuthRequest.auth_request] { > name: "test" > pass: "098F6BCD4621D373CADE4E832627B4F6" > } > > Feeding back this byte array to Message whit this code: > byte[] out = {8, 100, 16, 0, -94, 6, 40, 10, 4, 116, 101, 115, 116, 18, > 32, 48, 57, 56, 70, 54, 66, 67, 68, 52, 54, 50, 49, 68, 51, 55, 51, 67, > 65, 68, 69, 52, 69, 56, 51, 50, 54, 50, 55, 66, 52, 70, 54}; > Message m = Message.parseFrom(out); > assertTrue(m.hasExtension(AuthRequest.auth_request)); > > I don't get any extension number 100 (getExtension returns null, > hasExtension is false and when I debug the program, there's nothing in > the extension FieldSet). > > It all looks like the field 100 is parsed as an Unknown field. > When I text print the message, I get: > > type: AUTH > id: 0 > 100: "\n\004test\022 098F6BCD4621D373CADE4E832627B4F6" > > So yes, the data is here, but it isn't parsed as a known or valid > extension. > > So simplifying the code, I end-up with the following non passing unit > test: > > AuthRequest req = > AuthRequest.newBuilder().setName("test").setPass("test").build(); > > Message src = > Message.newBuilder().setType(Type.AUTH).setExtension(AuthRequest.authRequest, > req).build(); > Message m = Message.parseFrom(src.toByteArray()); > > assertTrue(m.hasExtension(AuthRequest.authRequest)); I used protoc to encode the correct textual representation, and I get the exact same byte array as was produced by my java code, so serialization seems to be OK. Using protoc --decode from the same binary content, then it prints the correct content, so the C version seems to work fine, which means only the Java version has some issues with deserialization. -- Brice Figureau My Blog: http://www.masterzen.fr/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---