title: How to make small changes in sub-fields
body: <p>I have met some problems about changing the value in my protobuff message.
  This is the proto file.</p>
  
  <pre><code>message Info {
    repeated InfoUnit unit = 1;  
  }
  message InfoUnit {
    optional uint64 id = 1;
    repeated DateUnit date_unit = 2;
  }
  message DateUnit {
    optional uint64 date = 1;
  }
  </code></pre>
  
  <p>My task is simple. I get an Info message, then update Info's InfoUnit list. 
  For example:</p>
  
  <ol>
  <li><p>update the first UnitInfo's first DateUnit's date = 2.</p></li>
  <li><p>add a new UnitInfo to Info with default values.  </p></li>
  </ol>
  
  <p>At first,
  I think I can just get the list and then update it.</p>
  
  <pre><code>Info.Builder builder = infoMessage.toBuilder();
  List&lt;InfoUnit&gt; list = builder.getInfoUnitList();
  //first infoUnit, first dataUnit, 2
  update(list.get(0), 0, 2);
  list.add(InfoUnit.newBuilder()...........build())
  </code></pre>
  
  <p>but finally this does not work.</p>
  
  <p>I find an explain in this website: <a href="https://stackoverflow.com/questions/29209153/making-a-small-change-to-a-java-protocol-buffers-object">Making a small change to a Java protocol buffers object</a></p>
  
  <p>I do not understand and I don't find a good way to solve this problem.</p>
  
  <p>So I change to a new plan, but this is complex.</p>
  
  <pre><code>Info.Builder builder = infoMessage.toBuilder();
  //copy the builder list
  List&lt;InfoUnit.Builder&gt; builderList = new ArrayList&lt;InfoUnit&gt;(builder.getInfoUnitBuilderList());
  
  //finish update and add
  update(....);
  
  //clear the InfoUnit list
  builder.clearInfouNIT();
  //rebuild the list
  for(InfoUnit.Builder infoUnitBuilder: builderList)
      builder.addInfoUnit(infoUnitBuilder);
  //rebuild this Info
  builder.build();
  </code></pre>
  
  <p>I copy the InfoUnit's builder list to update, then clear the former InfoUnit list and use the copy to rebuild the InfoUnit list.
  You may find that the DataUnit is also a list, so I do this work again. I don't write the DataUnit's update codes here, just use 'update' to replace briefly.</p>
  
  <p>Of course this worked. But I believe there must be a better way to update the value of repeat type in message.
  If someone has good ideas or has some questions about my situation, leave message to me.
  Expect anyone's reply :)</p>