浏览代码

auto import from //depot/cupcake/@137055

The Android Open Source Project 16 年之前
父节点
当前提交
bb7bbd7c9c
共有 1 个文件被更改,包括 38 次插入4 次删除
  1. 38 4
      src/com/google/common/io/protocol/ProtoBuf.java

+ 38 - 4
src/com/google/common/io/protocol/ProtoBuf.java

@@ -144,6 +144,28 @@ public class ProtoBuf {
     insertProtoBuf(tag, getCount(tag), value);
   }
 
+  /**
+   * Adds a new protobuf for the specified tag, setting the child protobuf's
+   * type correctly for the tag.
+   * @param tag the tag for which to create a new protobuf
+   * @return the newly created protobuf
+   */
+  public ProtoBuf addNewProtoBuf(int tag) {
+    ProtoBuf child = newProtoBufForTag(tag);
+    addProtoBuf(tag, child);
+    return child;
+  }
+
+  /**
+   * Creates and returns a new protobuf for the specified tag, setting the new
+   * protobuf's type correctly for the tag.
+   * @param tag the tag for which to create a new protobuf
+   * @return the newly created protobuf
+   */
+  public ProtoBuf newProtoBufForTag(int tag) {
+      return new ProtoBuf((ProtoBufType) msgType.getData(tag));
+  }
+
   /**
    * Appends the given (repeated) tag with the given String value.
    */
@@ -181,7 +203,7 @@ public class ProtoBuf {
     return (byte[]) getObject(tag, index, ProtoBufType.TYPE_DATA);
   }
 
-  /** 
+  /**
    * Returns the integer value for the given tag. 
    */
   public int getInt(int tag) {
@@ -196,7 +218,7 @@ public class ProtoBuf {
         ProtoBufType.TYPE_INT32)).longValue();
   }
 
-  /** 
+  /**
    * Returns the long value for the given tag. 
    */
   public long getLong(int tag) {
@@ -238,7 +260,7 @@ public class ProtoBuf {
     return Double.longBitsToDouble(getLong(tag, index));
   }
 
-  /** 
+  /**
    * Returns the group or nested message for the given tag.
    */
   public ProtoBuf getProtoBuf(int tag) {
@@ -269,7 +291,7 @@ public class ProtoBuf {
     return (String) getObject(tag, index, ProtoBufType.TYPE_TEXT);
   }
 
-  /** 
+  /**
    * Returns the type definition of this protocol buffer or group -- if set. 
    */
   public ProtoBufType getType() {
@@ -729,6 +751,18 @@ public class ProtoBuf {
     setObject(tag, pb);
   }
 
+  /**
+   * Sets a new protobuf for the specified tag, setting the child protobuf's
+   * type correctly for the tag.
+   * @param tag the tag for which to create a new protobuf
+   * @return the newly created protobuf
+   */
+  public ProtoBuf setNewProtoBuf(int tag) {
+    ProtoBuf child = newProtoBufForTag(tag);
+    setProtoBuf(tag, child);
+    return child;
+  }
+
   /** 
    * Sets the given tag to the given String value. 
    */