Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Perspective 1</strong></p> <p>You write a .proto file and give it to protoc that generates the Builder code. They are suggesting not to add any methods to the generated code. If at all you want some custom behavior to be added to the generated code then WRITE YOUR OWN CLASS WRAPPING the generated code. </p> <p>For e.g let us say the protoc generated class is MyMessageBuilder. And you wanted to add a method that can take XML input and spitout the protobuff specific message out. You would write a XmlToMyMessageBuilder as below. Here XmlToMyMessageBuilder, your class is wrapping the generated code and adding custom behavior fromXml().</p> <pre><code>public class XmlToMyMessageBuilder { private final MyMessageBuilder protoBuilder; public MyMessage fromXml(byte[] input() { protoBuilder.setXXX(); } } </code></pre> <p>This is a general good programming principle. </p> <p><strong>Perspective 2</strong></p> <p>By providing a intermediary you can also DECOUPLE your code from the underlying serialization mechanism. This allows you to switch the serializer implementations (say you want to serialize a payload where all the data is in string format...where JSON seriazation with compression is a better alternative) with low impact. You could do something like this</p> <pre><code>public interface MySerializer { boolean serialize(MyDomainObject input); } public PBBasedSerializer implements MySerializer { private final MyMessageBuilder protoBuilder; ... } public JsonBasedSerializer implements MySerializer { private final JSONSerializer jsonSerializer; ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload