to make it simple, here is one proto file and two jUnits tests. The first one passes through and the second one fails. See the comments for details.

Protos.proto:
================

enum Api {
    REFUND = 1;
}

message Request {
    required Api api_call = 1;
    extensions 100 to 200;
}

message RefundRequest {
    required int32 orderId = 1;
}

extend Request {
    optional RefundRequest refund_request = 100;
}


TestUnit1: (succeeds)
==============

Protos.RefundRequest rr =
       Protos.RefundRequest.newBuilder()
              .setOrderId(3)
              .build();

byte[] data = rr.toByteArray();


Protos.RefundRequest rr2 = Protos.RefundRequest.parseFrom(data);

// suceeds
Assert.isTrue( rr2.getOrderId() == 3 );


TestUnit2: (fails at the end)
==============================


Protos.RefundRequest rr =
       Protos.RefundRequest.newBuilder()
          .setOrderId(3)
          .build();

Protos.Request request =
       Protos.Request.newBuilder()
          .setApiCall(Protos.Api.REFUND)
          .setExtension(Protos.refundRequest, rr)
          .build();

// returns true
Assert.isTrue( request.hasExtension(Protos.refundRequest) );

// returns true
Assert.isTrue( request.getExtension(Protos.refundRequest).equals(rr) );

byte[] data = request.toByteArray();

ExtensionRegistry registry = ExtensionRegistry.newInstance();
registry.add(Protos.refundRequest);

Protos.RefundRequest refundRequest = Protos.RefundRequest.parseFrom(
          data, registry
      );

// it fails and returns always 1

Assert.isTrue( refundRequest.getOrderId() == 3 );



What is wrong that the orderId is always returned as 1 and not 3 as it is expected?

--
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.

Reply via email to