Use ProtoOutputStream to strip Pii sensetive fields in incidentd
The in-place algorithm in ProtoOutputStream will have at most 2 copies
of possible nested message values incidentd is getting which makes it
more ram-efficient, and minimize allocations.
Bug: 65641021
Test: the units pass
Change-Id: Ic3fe99b7e27895bd613a129ba0f12ccfca4af317
diff --git a/libs/protoutil/include/android/util/ProtoOutputStream.h b/libs/protoutil/include/android/util/ProtoOutputStream.h
index 49ec169..0f1cced 100644
--- a/libs/protoutil/include/android/util/ProtoOutputStream.h
+++ b/libs/protoutil/include/android/util/ProtoOutputStream.h
@@ -37,7 +37,7 @@
class ProtoOutputStream
{
public:
- ProtoOutputStream(int fd);
+ ProtoOutputStream();
~ProtoOutputStream();
/**
@@ -60,13 +60,19 @@
void end(long long token);
/**
- * Flushes the protobuf data out.
+ * Flushes the protobuf data out to given fd.
*/
- bool flush();
+ size_t size();
+ EncodedBuffer::iterator data();
+ bool flush(int fd);
+
+ // Please don't use the following functions to dump protos unless you are sure about it.
+ void writeRawVarint(uint64_t varint);
+ void writeLengthDelimitedHeader(uint32_t id, size_t size);
+ void writeRawByte(uint8_t byte);
private:
EncodedBuffer mBuffer;
- int mFd;
size_t mCopyBegin;
bool mCompact;
int mDepth;