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

Commit 5f1cca65 authored by Nataniel Borges's avatar Nataniel Borges
Browse files

Get ProtoOutputStream size without compressing it

The current implementation of the ProtoOutputStream compresses the
buffer in order to return its correct size.

For some use cases the compression is too expensive and it is more
useful to have a faster but overestimated size to a precise but slower
one.

This implementation adds a `getRawSize` method which returns the buffer
size without compressing it. If the buffer has already been compressed
the returned size is the same as the one from the `getSize`. If the
buffer is not yet compressed the size may diverge.

This implementation will be used to support a ring buffer for window
transitions on the Window Manager.

Bug: 123535780
Test: Check the getSize method from the EncodedBuffer and the getRawSize
from the ProtoOutputStream.
Change-Id: Ied24742a14b76980afdf6d6d22d67ade15ba7aad
parent 98d92aa5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2077,6 +2077,7 @@ package android.util.proto {
    method public static int getRawZigZag64Size(long);
    method public int getReadPos();
    method public int getReadableSize();
    method public int getSize();
    method public int getWriteBufIndex();
    method public int getWriteIndex();
    method public int getWritePos();
@@ -2136,6 +2137,7 @@ package android.util.proto {
    method @Deprecated public void endRepeatedObject(long);
    method public void flush();
    method public byte[] getBytes();
    method public int getRawSize();
    method public static long makeFieldId(int, long);
    method public long start(long);
    method @Deprecated public long startObject(long);
+8 −0
Original line number Diff line number Diff line
@@ -147,6 +147,14 @@ public final class EncodedBuffer {
        return mReadableSize;
    }

    /**
     * Returns the buffer size
     * @return the buffer size
     */
    public int getSize() {
        return ((mBufferCount - 1) * mChunkSize) + mWriteIndex;
    }

    //
    // Reading from the read position.
    //
+12 −0
Original line number Diff line number Diff line
@@ -187,6 +187,18 @@ public final class ProtoOutputStream extends ProtoStream {
        this(new FileOutputStream(fd));
    }

    /**
     * Returns the uncompressed buffer size
     * @return the uncompressed buffer size
     */
    public int getRawSize() {
        if (mCompacted) {
            return getBytes().length;
        } else {
            return mBuffer.getSize();
        }
    }

    /**
     * Write a value for the given fieldId.
     *