On 9月22日, 下午1时48分, [EMAIL PROTECTED] wrote:
> Hello Group,
>
> I was looking for a protocol for my java client/server application and
> just found protobuf. It does look very good, but I couldn't get it
> work properly, please help. Here is my setup:
>
> // *****************
> //  proto definition
> // *****************
> package myserver;
> option java_package = "com.mycom.myserver";
> option java_outer_classname = "MyProtocol";
>
> message SourceData {
>         required string source_id = 1;
>         optional float source_var1 = 2;
>         optional int32 source_size = 3;
>
>         message Incoming {
>                 optional string in_data_1 = 1;
>         }
        optional Incoming incoming = 4;
>
>         message Outgoing {
>                 optional string out_data_1 = 1;
>         }
      optional Outgoing outgoding = 5;
>
> }
>
> // ***************
> //  Writer
> // ***************
>         MyProtocol.SourceData.Builder sourceMessage =
> MyProtocol.SourceData.newBuilder();
>         sourceMessage.setSourceId("0001");
>         sourceMessage.setSourceVar1(1234.322);
>         sourceMessage.setSourceSize(1024);
>
>         MyProtocol.SourceData.Incoming.Builder inData =
> MyProtocol.SourceData.Incoming.newBuilder();
// >         inData.setIncoming1("Some In Data");
    inData.setInData1("Some In Data");
    sourceMessage.setIncoming(inData);
>
>         MyProtocol.SourceData.Outgoing.Builder outData =
> MyProtocol.SourceData.Outgoing.newBuilder();
// >         outData.setOutgoing1("Some Out Data");
    outData.setOutData1("Some Out Data");
    sourceMessage.setOutgoing1(outData);

>
// >         inData.build().writeTo(myOutputStream);
// >         outData.build().writeTo(myOutputStream);
>         sourceMessage.build().writeTo(myOutputStream);
>

similar changing in reader

> // ***************
> //  Reader
> // ***************
>         MyProtocol.SourceData sourceMessage =
> MyProtocol.SourceData.parseFrom(myInputStream);
>         MyProtocol.SourceData.Incoming inData =
  sourceMessage.getIncoming();
// > MyProtocol.SourceData.Incoming.parseFrom(myInputStream);
>         MyProtocol.SourceData.Outgoing outData =
  sourceMessage.getOutgoing();
// > MyProtocol.SourceData.Outgoing.parseFrom(myInputStream);
>
>         System.out.println("ID = " + sourceMessage.getSourceId());
>         System.out.println("Var1 = " + sourceMessage.getSourceVar1());
>         System.out.println("Size = " + sourceMessage.getSourceSize());
// >         System.out.println("Incoming = " +
inData.getIncoming1() );
// >         System.out.println("Outgoing = " +
outData.getOutgoing1());

System.out.println("Incoming = " + inData.getInData1() );
System.out.println("Outgoing = " + outData.getOutData1());


>
> - I get response for SourceData only (SourceId, SourceVar1,
> SourceSize), but I get nothing for Incoming or Outgoing.
>   How do I get Incoming and Outgoing?
>
> - If I add the following to the end of the protocol:
>         message AllData {
>                 optional SourceData all_my_data = 1;
>         }
>
> Will this help sending the entire message and how will it be parsed
> from the reader?
>
> Thank you in advance,
> John

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

  • need help john . douglas . 88
    • Re: need help Mars

Reply via email to