Create a new API allowing callers to concat a serialized message field.

Test: N/A
Change-Id: I90570ea62e6c406d40c399cee6cbb8dcb5172e21
diff --git a/libs/protoutil/include/android/util/ProtoOutputStream.h b/libs/protoutil/include/android/util/ProtoOutputStream.h
index 10be649..b8415b2 100644
--- a/libs/protoutil/include/android/util/ProtoOutputStream.h
+++ b/libs/protoutil/include/android/util/ProtoOutputStream.h
@@ -66,7 +66,7 @@
     EncodedBuffer::iterator data();
     bool flush(int fd);
 
-    // Please don't use the following functions to dump protos unless you are sure about it.
+    // Please don't use the following functions to dump protos unless you are familiar with protobuf encoding.
     void writeRawVarint(uint64_t varint);
     void writeLengthDelimitedHeader(uint32_t id, size_t size);
     void writeRawByte(uint8_t byte);
@@ -94,6 +94,7 @@
     inline void writeEnumImpl(uint32_t id, int val);
     inline void writeBoolImpl(uint32_t id, bool val);
     inline void writeUtf8StringImpl(uint32_t id, const char* val, size_t size);
+    inline void writeMessageBytesImpl(uint32_t id, const char* val, size_t size);
 
     bool compact();
     size_t editEncodedSize(size_t rawSize);
diff --git a/libs/protoutil/src/ProtoOutputStream.cpp b/libs/protoutil/src/ProtoOutputStream.cpp
index 9dadf1c..b91e3db0 100644
--- a/libs/protoutil/src/ProtoOutputStream.cpp
+++ b/libs/protoutil/src/ProtoOutputStream.cpp
@@ -234,6 +234,10 @@
         case TYPE_BYTES:
             writeUtf8StringImpl(id, val, size);
             return true;
+        case TYPE_MESSAGE:
+            // can directly write valid format of message bytes into ProtoOutputStream without calling start/end
+            writeMessageBytesImpl(id, val, size);
+            return true;
         default:
             ALOGW("Field type %d is not supported when writing char[] val.",
                     (int)((fieldId & FIELD_TYPE_MASK) >> FIELD_TYPE_SHIFT));
@@ -678,6 +682,16 @@
     }
 }
 
+inline void
+ProtoOutputStream::writeMessageBytesImpl(uint32_t id, const char* val, size_t size)
+{
+    if (val == NULL) return;
+    writeLengthDelimitedHeader(id, size);
+    for (size_t i=0; i<size; i++) {
+        mBuffer.writeRawByte(val[i]);
+    }
+}
+
 } // util
 } // android