Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ad19387 authored by Yi Jin's avatar Yi Jin
Browse files

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

Test: N/A
Change-Id: I90570ea62e6c406d40c399cee6cbb8dcb5172e21
parent 7d3fcb43
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public:
    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 @@ private:
    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);
+14 −0
Original line number Diff line number Diff line
@@ -234,6 +234,10 @@ ProtoOutputStream::write(uint64_t fieldId, const char* val, size_t size)
        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 @@ ProtoOutputStream::writeUtf8StringImpl(uint32_t id, const char* val, size_t size
    }
}

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