Loading api/current.txt +65 −0 Original line number Diff line number Diff line Loading @@ -49568,6 +49568,71 @@ package android.util { } package android.util.proto { public final class ProtoOutputStream { ctor public ProtoOutputStream(); ctor public ProtoOutputStream(int); ctor public ProtoOutputStream(@NonNull java.io.OutputStream); method public static int checkFieldId(long, long); method public void dump(@NonNull String); method public void end(long); method public void flush(); method @NonNull public byte[] getBytes(); method @Nullable public static String getFieldCountString(long); method @NonNull public static String getFieldIdString(long); method @Nullable public static String getFieldTypeString(long); method public int getRawSize(); method @Nullable public static String getWireTypeString(int); method public static long makeFieldId(int, long); method public static long makeToken(int, boolean, int, int, int); method public long start(long); method @NonNull public static String token2String(long); method public void write(long, double); method public void write(long, float); method public void write(long, int); method public void write(long, long); method public void write(long, boolean); method public void write(long, @Nullable String); method public void write(long, @Nullable byte[]); method public void writeTag(int, int); field public static final long FIELD_COUNT_MASK = 16492674416640L; // 0xf0000000000L field public static final long FIELD_COUNT_PACKED = 5497558138880L; // 0x50000000000L field public static final long FIELD_COUNT_REPEATED = 2199023255552L; // 0x20000000000L field public static final int FIELD_COUNT_SHIFT = 40; // 0x28 field public static final long FIELD_COUNT_SINGLE = 1099511627776L; // 0x10000000000L field public static final long FIELD_COUNT_UNKNOWN = 0L; // 0x0L field public static final int FIELD_ID_SHIFT = 3; // 0x3 field public static final long FIELD_TYPE_BOOL = 34359738368L; // 0x800000000L field public static final long FIELD_TYPE_BYTES = 51539607552L; // 0xc00000000L field public static final long FIELD_TYPE_DOUBLE = 4294967296L; // 0x100000000L field public static final long FIELD_TYPE_ENUM = 60129542144L; // 0xe00000000L field public static final long FIELD_TYPE_FIXED32 = 30064771072L; // 0x700000000L field public static final long FIELD_TYPE_FIXED64 = 25769803776L; // 0x600000000L field public static final long FIELD_TYPE_FLOAT = 8589934592L; // 0x200000000L field public static final long FIELD_TYPE_INT32 = 21474836480L; // 0x500000000L field public static final long FIELD_TYPE_INT64 = 12884901888L; // 0x300000000L field public static final long FIELD_TYPE_MASK = 1095216660480L; // 0xff00000000L field public static final long FIELD_TYPE_MESSAGE = 47244640256L; // 0xb00000000L field public static final long FIELD_TYPE_SFIXED32 = 64424509440L; // 0xf00000000L field public static final long FIELD_TYPE_SFIXED64 = 68719476736L; // 0x1000000000L field public static final int FIELD_TYPE_SHIFT = 32; // 0x20 field public static final long FIELD_TYPE_SINT32 = 73014444032L; // 0x1100000000L field public static final long FIELD_TYPE_SINT64 = 77309411328L; // 0x1200000000L field public static final long FIELD_TYPE_STRING = 38654705664L; // 0x900000000L field public static final long FIELD_TYPE_UINT32 = 55834574848L; // 0xd00000000L field public static final long FIELD_TYPE_UINT64 = 17179869184L; // 0x400000000L field public static final int WIRE_TYPE_END_GROUP = 4; // 0x4 field public static final int WIRE_TYPE_FIXED32 = 5; // 0x5 field public static final int WIRE_TYPE_FIXED64 = 1; // 0x1 field public static final int WIRE_TYPE_LENGTH_DELIMITED = 2; // 0x2 field public static final int WIRE_TYPE_MASK = 7; // 0x7 field public static final int WIRE_TYPE_START_GROUP = 3; // 0x3 field public static final int WIRE_TYPE_VARINT = 0; // 0x0 } } package android.view { public abstract class AbsSavedState implements android.os.Parcelable { api/test-current.txt +0 −128 Original line number Diff line number Diff line Loading @@ -4129,138 +4129,10 @@ package android.util.proto { method public void writeRawZigZag64(long); } public final class ProtoOutputStream extends android.util.proto.ProtoStream { ctor public ProtoOutputStream(); ctor public ProtoOutputStream(int); ctor public ProtoOutputStream(java.io.OutputStream); ctor public ProtoOutputStream(java.io.FileDescriptor); method public static int checkFieldId(long, long); method public void dump(String); method public void end(long); method @Deprecated public void endObject(long); 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); method @Deprecated public long startRepeatedObject(long); method public void write(long, double); method public void write(long, float); method public void write(long, int); method public void write(long, long); method public void write(long, boolean); method public void write(long, String); method public void write(long, byte[]); method @Deprecated public void writeBool(long, boolean); method @Deprecated public void writeBytes(long, byte[]); method @Deprecated public void writeDouble(long, double); method @Deprecated public void writeEnum(long, int); method @Deprecated public void writeFixed32(long, int); method @Deprecated public void writeFixed64(long, long); method @Deprecated public void writeFloat(long, float); method @Deprecated public void writeInt32(long, int); method @Deprecated public void writeInt64(long, long); method @Deprecated public void writeObject(long, byte[]); method @Deprecated public void writePackedBool(long, boolean[]); method @Deprecated public void writePackedDouble(long, double[]); method @Deprecated public void writePackedEnum(long, int[]); method @Deprecated public void writePackedFixed32(long, int[]); method @Deprecated public void writePackedFixed64(long, long[]); method @Deprecated public void writePackedFloat(long, float[]); method @Deprecated public void writePackedInt32(long, int[]); method @Deprecated public void writePackedInt64(long, long[]); method @Deprecated public void writePackedSFixed32(long, int[]); method @Deprecated public void writePackedSFixed64(long, long[]); method @Deprecated public void writePackedSInt32(long, int[]); method @Deprecated public void writePackedSInt64(long, long[]); method @Deprecated public void writePackedUInt32(long, int[]); method @Deprecated public void writePackedUInt64(long, long[]); method @Deprecated public void writeRepeatedBool(long, boolean); method @Deprecated public void writeRepeatedBytes(long, byte[]); method @Deprecated public void writeRepeatedDouble(long, double); method @Deprecated public void writeRepeatedEnum(long, int); method @Deprecated public void writeRepeatedFixed32(long, int); method @Deprecated public void writeRepeatedFixed64(long, long); method @Deprecated public void writeRepeatedFloat(long, float); method @Deprecated public void writeRepeatedInt32(long, int); method @Deprecated public void writeRepeatedInt64(long, long); method @Deprecated public void writeRepeatedObject(long, byte[]); method @Deprecated public void writeRepeatedSFixed32(long, int); method @Deprecated public void writeRepeatedSFixed64(long, long); method @Deprecated public void writeRepeatedSInt32(long, int); method @Deprecated public void writeRepeatedSInt64(long, long); method @Deprecated public void writeRepeatedString(long, String); method @Deprecated public void writeRepeatedUInt32(long, int); method @Deprecated public void writeRepeatedUInt64(long, long); method @Deprecated public void writeSFixed32(long, int); method @Deprecated public void writeSFixed64(long, long); method @Deprecated public void writeSInt32(long, int); method @Deprecated public void writeSInt64(long, long); method @Deprecated public void writeString(long, String); method public void writeTag(int, int); method @Deprecated public void writeUInt32(long, int); method @Deprecated public void writeUInt64(long, long); } public class ProtoParseException extends java.lang.RuntimeException { ctor public ProtoParseException(String); } public abstract class ProtoStream { ctor public ProtoStream(); method public static int convertObjectIdToOrdinal(int); method public static int getDepthFromToken(long); method public static String getFieldCountString(long); method public static String getFieldIdString(long); method public static String getFieldTypeString(long); method public static int getObjectIdFromToken(long); method public static int getOffsetFromToken(long); method public static boolean getRepeatedFromToken(long); method public static int getTagSizeFromToken(long); method public static String getWireTypeString(int); method public static long makeFieldId(int, long); method public static long makeToken(int, boolean, int, int, int); method public static String token2String(long); field public static final long FIELD_COUNT_MASK = 16492674416640L; // 0xf0000000000L field public static final long FIELD_COUNT_PACKED = 5497558138880L; // 0x50000000000L field public static final long FIELD_COUNT_REPEATED = 2199023255552L; // 0x20000000000L field public static final int FIELD_COUNT_SHIFT = 40; // 0x28 field public static final long FIELD_COUNT_SINGLE = 1099511627776L; // 0x10000000000L field public static final long FIELD_COUNT_UNKNOWN = 0L; // 0x0L field public static final int FIELD_ID_MASK = -8; // 0xfffffff8 field public static final int FIELD_ID_SHIFT = 3; // 0x3 field public static final long FIELD_TYPE_BOOL = 34359738368L; // 0x800000000L field public static final long FIELD_TYPE_BYTES = 51539607552L; // 0xc00000000L field public static final long FIELD_TYPE_DOUBLE = 4294967296L; // 0x100000000L field public static final long FIELD_TYPE_ENUM = 60129542144L; // 0xe00000000L field public static final long FIELD_TYPE_FIXED32 = 30064771072L; // 0x700000000L field public static final long FIELD_TYPE_FIXED64 = 25769803776L; // 0x600000000L field public static final long FIELD_TYPE_FLOAT = 8589934592L; // 0x200000000L field public static final long FIELD_TYPE_INT32 = 21474836480L; // 0x500000000L field public static final long FIELD_TYPE_INT64 = 12884901888L; // 0x300000000L field public static final long FIELD_TYPE_MASK = 1095216660480L; // 0xff00000000L field public static final long FIELD_TYPE_MESSAGE = 47244640256L; // 0xb00000000L field protected static final String[] FIELD_TYPE_NAMES; field public static final long FIELD_TYPE_SFIXED32 = 64424509440L; // 0xf00000000L field public static final long FIELD_TYPE_SFIXED64 = 68719476736L; // 0x1000000000L field public static final int FIELD_TYPE_SHIFT = 32; // 0x20 field public static final long FIELD_TYPE_SINT32 = 73014444032L; // 0x1100000000L field public static final long FIELD_TYPE_SINT64 = 77309411328L; // 0x1200000000L field public static final long FIELD_TYPE_STRING = 38654705664L; // 0x900000000L field public static final long FIELD_TYPE_UINT32 = 55834574848L; // 0xd00000000L field public static final long FIELD_TYPE_UINT64 = 17179869184L; // 0x400000000L field public static final long FIELD_TYPE_UNKNOWN = 0L; // 0x0L field public static final int WIRE_TYPE_END_GROUP = 4; // 0x4 field public static final int WIRE_TYPE_FIXED32 = 5; // 0x5 field public static final int WIRE_TYPE_FIXED64 = 1; // 0x1 field public static final int WIRE_TYPE_LENGTH_DELIMITED = 2; // 0x2 field public static final int WIRE_TYPE_MASK = 7; // 0x7 field public static final int WIRE_TYPE_START_GROUP = 3; // 0x3 field public static final int WIRE_TYPE_VARINT = 0; // 0x0 } public class WireTypeMismatchException extends android.util.proto.ProtoParseException { ctor public WireTypeMismatchException(String); } Loading core/java/android/util/proto/ProtoOutputStream.java +193 −123 File changed.Preview size limit exceeded, changes collapsed. Show changes core/java/android/util/proto/ProtoStream.java +304 −18 Original line number Diff line number Diff line Loading @@ -16,28 +16,104 @@ package android.util.proto; import android.annotation.TestApi; import android.annotation.NonNull; import android.annotation.Nullable; /** * Abstract base class for both protobuf streams. * Base utility class for protobuf streams. * * Contains a set of useful constants and methods used by both * ProtoOutputStream and ProtoInputStream * Contains a set of constants and methods used in generated code for * {@link ProtoOutputStream}. * * @hide */ @TestApi public abstract class ProtoStream { public class ProtoStream { /** * Number of bits to shift the field number to form a tag. * * <pre> * // Reading a field number from a tag. * int fieldNumber = tag >>> FIELD_ID_SHIFT; * * // Building a tag from a field number and a wire type. * int tag = (fieldNumber << FIELD_ID_SHIFT) | wireType; * </pre> * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int FIELD_ID_SHIFT = 3; /** * Mask to select the wire type from a tag. * * <pre> * // Reading a wire type from a tag. * int wireType = tag & WIRE_TYPE_MASK; * * // Building a tag from a field number and a wire type. * int tag = (fieldNumber << FIELD_ID_SHIFT) | wireType; * </pre> * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_MASK = (1 << FIELD_ID_SHIFT) - 1; /** * Mask to select the field id from a tag. * @hide (not used by anything, and not actually useful, because you also want * to shift when you mask the field id). */ public static final int FIELD_ID_MASK = ~WIRE_TYPE_MASK; /** * Varint wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_VARINT = 0; /** * Fixed64 wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_FIXED64 = 1; /** * Length delimited wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_LENGTH_DELIMITED = 2; /** * Start group wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_START_GROUP = 3; /** * End group wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_END_GROUP = 4; /** * Fixed32 wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_FIXED32 = 5; /** Loading @@ -51,32 +127,147 @@ public abstract class ProtoStream { */ public static final long FIELD_TYPE_MASK = 0x0ffL << FIELD_TYPE_SHIFT; /** * Not a real wire type. * @hide */ public static final long FIELD_TYPE_UNKNOWN = 0; /* * The FIELD_TYPE_ constants are copied from * external/protobuf/src/google/protobuf/descriptor.h directly, so no * extra mapping needs to be maintained in this case. */ /** * The types are copied from external/protobuf/src/google/protobuf/descriptor.h directly, * so no extra mapping needs to be maintained in this case. * Field type code for double fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, double) * ProtoOutputStream.write(long, double)} method. */ public static final long FIELD_TYPE_DOUBLE = 1L << FIELD_TYPE_SHIFT; /** * Field type code for float fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, float) * ProtoOutputStream.write(long, float)} method. */ public static final long FIELD_TYPE_FLOAT = 2L << FIELD_TYPE_SHIFT; /** * Field type code for int64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_INT64 = 3L << FIELD_TYPE_SHIFT; /** * Field type code for uint64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_UINT64 = 4L << FIELD_TYPE_SHIFT; /** * Field type code for int32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_INT32 = 5L << FIELD_TYPE_SHIFT; /** * Field type code for fixed64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_FIXED64 = 6L << FIELD_TYPE_SHIFT; /** * Field type code for fixed32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ /** * Field type code for fixed32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_FIXED32 = 7L << FIELD_TYPE_SHIFT; /** * Field type code for bool fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, boolean) * ProtoOutputStream.write(long, boolean)} method. */ public static final long FIELD_TYPE_BOOL = 8L << FIELD_TYPE_SHIFT; /** * Field type code for string fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, String) * ProtoOutputStream.write(long, String)} method. */ public static final long FIELD_TYPE_STRING = 9L << FIELD_TYPE_SHIFT; // public static final long FIELD_TYPE_GROUP = 10L << FIELD_TYPE_SHIFT; // Deprecated. /** * Field type code for message fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#start(long) * ProtoOutputStream.start(long)} method. */ public static final long FIELD_TYPE_MESSAGE = 11L << FIELD_TYPE_SHIFT; /** * Field type code for bytes fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, byte[]) * ProtoOutputStream.write(long, byte[])} method. */ public static final long FIELD_TYPE_BYTES = 12L << FIELD_TYPE_SHIFT; /** * Field type code for uint32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_UINT32 = 13L << FIELD_TYPE_SHIFT; /** * Field type code for enum fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_ENUM = 14L << FIELD_TYPE_SHIFT; /** * Field type code for sfixed32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_SFIXED32 = 15L << FIELD_TYPE_SHIFT; /** * Field type code for sfixed64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_SFIXED64 = 16L << FIELD_TYPE_SHIFT; /** * Field type code for sint32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_SINT32 = 17L << FIELD_TYPE_SHIFT; /** * Field type code for sint64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_SINT64 = 18L << FIELD_TYPE_SHIFT; protected static final String[] FIELD_TYPE_NAMES = new String[]{ private static final @NonNull String[] FIELD_TYPE_NAMES = new String[]{ "Double", "Float", "Int64", Loading @@ -100,19 +291,94 @@ public abstract class ProtoStream { // // FieldId flags for whether the field is single, repeated or packed. // /** * Bit offset for building a field id to be used with a * <code>{@link ProtoOutputStream}.write(...)</code>. * * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_REPEATED * @see #FIELD_COUNT_PACKED */ public static final int FIELD_COUNT_SHIFT = 40; /** * Bit mask for selecting the field count when reading a field id that * is used with a <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_REPEATED * @see #FIELD_COUNT_PACKED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_MASK = 0x0fL << FIELD_COUNT_SHIFT; /** * Unknown field count, encoded into a field id used with a * <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_REPEATED * @see #FIELD_COUNT_PACKED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_UNKNOWN = 0; /** * Single field count, encoded into a field id used with a * <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_REPEATED * @see #FIELD_COUNT_PACKED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_SINGLE = 1L << FIELD_COUNT_SHIFT; /** * Repeated field count, encoded into a field id used with a * <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_PACKED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_REPEATED = 2L << FIELD_COUNT_SHIFT; /** * Repeated packed field count, encoded into a field id used with a * <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_REPEATED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_PACKED = 5L << FIELD_COUNT_SHIFT; /** * Get the developer-usable name of a field type. */ public static String getFieldTypeString(long fieldType) { public static @Nullable String getFieldTypeString(long fieldType) { int index = ((int) ((fieldType & FIELD_TYPE_MASK) >>> FIELD_TYPE_SHIFT)) - 1; if (index >= 0 && index < FIELD_TYPE_NAMES.length) { return FIELD_TYPE_NAMES[index]; Loading @@ -124,7 +390,7 @@ public abstract class ProtoStream { /** * Get the developer-usable name of a field count. */ public static String getFieldCountString(long fieldCount) { public static @Nullable String getFieldCountString(long fieldCount) { if (fieldCount == FIELD_COUNT_SINGLE) { return ""; } else if (fieldCount == FIELD_COUNT_REPEATED) { Loading @@ -139,7 +405,7 @@ public abstract class ProtoStream { /** * Get the developer-usable name of a wire type. */ public static String getWireTypeString(int wireType) { public static @Nullable String getWireTypeString(int wireType) { switch (wireType) { case WIRE_TYPE_VARINT: return "Varint"; Loading @@ -161,7 +427,7 @@ public abstract class ProtoStream { /** * Get a debug string for a fieldId. */ public static String getFieldIdString(long fieldId) { public static @NonNull String getFieldIdString(long fieldId) { final long fieldCount = fieldId & FIELD_COUNT_MASK; String countString = getFieldCountString(fieldCount); if (countString == null) { Loading Loading @@ -218,29 +484,39 @@ public abstract class ProtoStream { /** * Get the encoded tag size from the token. * * @hide */ public static int getTagSizeFromToken(long token) { return (int) (0x7 & (token >> 61)); } /** * Get whether this is a call to startObject (false) or startRepeatedObject (true). * Get whether the token has the repeated bit set to true or false * * @hide */ public static boolean getRepeatedFromToken(long token) { return (0x1 & (token >> 60)) != 0; } /** * Get the nesting depth of startObject calls from the token. * Get the nesting depth from the token. * * @hide */ public static int getDepthFromToken(long token) { return (int) (0x01ff & (token >> 51)); } /** * Get the object ID from the token. The object ID is a serial number for the * Get the object ID from the token. * * <p>The object ID is a serial number for the * startObject calls that have happened on this object. The values are truncated * to 9 bits, but that is sufficient for error checking. * * @hide */ public static int getObjectIdFromToken(long token) { return (int) (0x07ffff & (token >> 32)); Loading @@ -248,6 +524,8 @@ public abstract class ProtoStream { /** * Get the location of the offset recorded in the token. * * @hide */ public static int getOffsetFromToken(long token) { return (int) token; Loading @@ -255,8 +533,11 @@ public abstract class ProtoStream { /** * Convert the object ID to the ordinal value -- the n-th call to startObject. * The object IDs start at -1 and count backwards, so that the value is unlikely * * <p>The object IDs start at -1 and count backwards, so that the value is unlikely * to alias with an actual size field that had been written. * * @hide */ public static int convertObjectIdToOrdinal(int objectId) { return (-1 & 0x07ffff) - objectId; Loading @@ -265,7 +546,7 @@ public abstract class ProtoStream { /** * Return a debugging string of a token. */ public static String token2String(long token) { public static @NonNull String token2String(long token) { if (token == 0L) { return "Token(0)"; } else { Loading @@ -277,4 +558,9 @@ public abstract class ProtoStream { + ')'; } } /** * @hide */ protected ProtoStream() {} } core/java/android/util/proto/ProtoUtils.java +1 −3 Original line number Diff line number Diff line Loading @@ -24,12 +24,12 @@ import java.io.IOException; /** * This class contains a list of helper functions to write common proto in * //frameworks/base/core/proto/android/base directory * @hide */ public class ProtoUtils { /** * Dump AggStats to ProtoOutputStream * @hide */ public static void toAggStatsProto(ProtoOutputStream proto, long fieldId, long min, long average, long max) { Loading @@ -42,7 +42,6 @@ public class ProtoUtils { /** * Dump Duration to ProtoOutputStream * @hide */ public static void toDuration(ProtoOutputStream proto, long fieldId, long startMs, long endMs) { final long token = proto.start(fieldId); Loading @@ -53,7 +52,6 @@ public class ProtoUtils { /** * Helper function to write bit-wise flags to proto as repeated enums * @hide */ public static void writeBitWiseFlagsToProtoEnum(ProtoOutputStream proto, long fieldId, int flags, int[] origEnums, int[] protoEnums) { Loading Loading
api/current.txt +65 −0 Original line number Diff line number Diff line Loading @@ -49568,6 +49568,71 @@ package android.util { } package android.util.proto { public final class ProtoOutputStream { ctor public ProtoOutputStream(); ctor public ProtoOutputStream(int); ctor public ProtoOutputStream(@NonNull java.io.OutputStream); method public static int checkFieldId(long, long); method public void dump(@NonNull String); method public void end(long); method public void flush(); method @NonNull public byte[] getBytes(); method @Nullable public static String getFieldCountString(long); method @NonNull public static String getFieldIdString(long); method @Nullable public static String getFieldTypeString(long); method public int getRawSize(); method @Nullable public static String getWireTypeString(int); method public static long makeFieldId(int, long); method public static long makeToken(int, boolean, int, int, int); method public long start(long); method @NonNull public static String token2String(long); method public void write(long, double); method public void write(long, float); method public void write(long, int); method public void write(long, long); method public void write(long, boolean); method public void write(long, @Nullable String); method public void write(long, @Nullable byte[]); method public void writeTag(int, int); field public static final long FIELD_COUNT_MASK = 16492674416640L; // 0xf0000000000L field public static final long FIELD_COUNT_PACKED = 5497558138880L; // 0x50000000000L field public static final long FIELD_COUNT_REPEATED = 2199023255552L; // 0x20000000000L field public static final int FIELD_COUNT_SHIFT = 40; // 0x28 field public static final long FIELD_COUNT_SINGLE = 1099511627776L; // 0x10000000000L field public static final long FIELD_COUNT_UNKNOWN = 0L; // 0x0L field public static final int FIELD_ID_SHIFT = 3; // 0x3 field public static final long FIELD_TYPE_BOOL = 34359738368L; // 0x800000000L field public static final long FIELD_TYPE_BYTES = 51539607552L; // 0xc00000000L field public static final long FIELD_TYPE_DOUBLE = 4294967296L; // 0x100000000L field public static final long FIELD_TYPE_ENUM = 60129542144L; // 0xe00000000L field public static final long FIELD_TYPE_FIXED32 = 30064771072L; // 0x700000000L field public static final long FIELD_TYPE_FIXED64 = 25769803776L; // 0x600000000L field public static final long FIELD_TYPE_FLOAT = 8589934592L; // 0x200000000L field public static final long FIELD_TYPE_INT32 = 21474836480L; // 0x500000000L field public static final long FIELD_TYPE_INT64 = 12884901888L; // 0x300000000L field public static final long FIELD_TYPE_MASK = 1095216660480L; // 0xff00000000L field public static final long FIELD_TYPE_MESSAGE = 47244640256L; // 0xb00000000L field public static final long FIELD_TYPE_SFIXED32 = 64424509440L; // 0xf00000000L field public static final long FIELD_TYPE_SFIXED64 = 68719476736L; // 0x1000000000L field public static final int FIELD_TYPE_SHIFT = 32; // 0x20 field public static final long FIELD_TYPE_SINT32 = 73014444032L; // 0x1100000000L field public static final long FIELD_TYPE_SINT64 = 77309411328L; // 0x1200000000L field public static final long FIELD_TYPE_STRING = 38654705664L; // 0x900000000L field public static final long FIELD_TYPE_UINT32 = 55834574848L; // 0xd00000000L field public static final long FIELD_TYPE_UINT64 = 17179869184L; // 0x400000000L field public static final int WIRE_TYPE_END_GROUP = 4; // 0x4 field public static final int WIRE_TYPE_FIXED32 = 5; // 0x5 field public static final int WIRE_TYPE_FIXED64 = 1; // 0x1 field public static final int WIRE_TYPE_LENGTH_DELIMITED = 2; // 0x2 field public static final int WIRE_TYPE_MASK = 7; // 0x7 field public static final int WIRE_TYPE_START_GROUP = 3; // 0x3 field public static final int WIRE_TYPE_VARINT = 0; // 0x0 } } package android.view { public abstract class AbsSavedState implements android.os.Parcelable {
api/test-current.txt +0 −128 Original line number Diff line number Diff line Loading @@ -4129,138 +4129,10 @@ package android.util.proto { method public void writeRawZigZag64(long); } public final class ProtoOutputStream extends android.util.proto.ProtoStream { ctor public ProtoOutputStream(); ctor public ProtoOutputStream(int); ctor public ProtoOutputStream(java.io.OutputStream); ctor public ProtoOutputStream(java.io.FileDescriptor); method public static int checkFieldId(long, long); method public void dump(String); method public void end(long); method @Deprecated public void endObject(long); 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); method @Deprecated public long startRepeatedObject(long); method public void write(long, double); method public void write(long, float); method public void write(long, int); method public void write(long, long); method public void write(long, boolean); method public void write(long, String); method public void write(long, byte[]); method @Deprecated public void writeBool(long, boolean); method @Deprecated public void writeBytes(long, byte[]); method @Deprecated public void writeDouble(long, double); method @Deprecated public void writeEnum(long, int); method @Deprecated public void writeFixed32(long, int); method @Deprecated public void writeFixed64(long, long); method @Deprecated public void writeFloat(long, float); method @Deprecated public void writeInt32(long, int); method @Deprecated public void writeInt64(long, long); method @Deprecated public void writeObject(long, byte[]); method @Deprecated public void writePackedBool(long, boolean[]); method @Deprecated public void writePackedDouble(long, double[]); method @Deprecated public void writePackedEnum(long, int[]); method @Deprecated public void writePackedFixed32(long, int[]); method @Deprecated public void writePackedFixed64(long, long[]); method @Deprecated public void writePackedFloat(long, float[]); method @Deprecated public void writePackedInt32(long, int[]); method @Deprecated public void writePackedInt64(long, long[]); method @Deprecated public void writePackedSFixed32(long, int[]); method @Deprecated public void writePackedSFixed64(long, long[]); method @Deprecated public void writePackedSInt32(long, int[]); method @Deprecated public void writePackedSInt64(long, long[]); method @Deprecated public void writePackedUInt32(long, int[]); method @Deprecated public void writePackedUInt64(long, long[]); method @Deprecated public void writeRepeatedBool(long, boolean); method @Deprecated public void writeRepeatedBytes(long, byte[]); method @Deprecated public void writeRepeatedDouble(long, double); method @Deprecated public void writeRepeatedEnum(long, int); method @Deprecated public void writeRepeatedFixed32(long, int); method @Deprecated public void writeRepeatedFixed64(long, long); method @Deprecated public void writeRepeatedFloat(long, float); method @Deprecated public void writeRepeatedInt32(long, int); method @Deprecated public void writeRepeatedInt64(long, long); method @Deprecated public void writeRepeatedObject(long, byte[]); method @Deprecated public void writeRepeatedSFixed32(long, int); method @Deprecated public void writeRepeatedSFixed64(long, long); method @Deprecated public void writeRepeatedSInt32(long, int); method @Deprecated public void writeRepeatedSInt64(long, long); method @Deprecated public void writeRepeatedString(long, String); method @Deprecated public void writeRepeatedUInt32(long, int); method @Deprecated public void writeRepeatedUInt64(long, long); method @Deprecated public void writeSFixed32(long, int); method @Deprecated public void writeSFixed64(long, long); method @Deprecated public void writeSInt32(long, int); method @Deprecated public void writeSInt64(long, long); method @Deprecated public void writeString(long, String); method public void writeTag(int, int); method @Deprecated public void writeUInt32(long, int); method @Deprecated public void writeUInt64(long, long); } public class ProtoParseException extends java.lang.RuntimeException { ctor public ProtoParseException(String); } public abstract class ProtoStream { ctor public ProtoStream(); method public static int convertObjectIdToOrdinal(int); method public static int getDepthFromToken(long); method public static String getFieldCountString(long); method public static String getFieldIdString(long); method public static String getFieldTypeString(long); method public static int getObjectIdFromToken(long); method public static int getOffsetFromToken(long); method public static boolean getRepeatedFromToken(long); method public static int getTagSizeFromToken(long); method public static String getWireTypeString(int); method public static long makeFieldId(int, long); method public static long makeToken(int, boolean, int, int, int); method public static String token2String(long); field public static final long FIELD_COUNT_MASK = 16492674416640L; // 0xf0000000000L field public static final long FIELD_COUNT_PACKED = 5497558138880L; // 0x50000000000L field public static final long FIELD_COUNT_REPEATED = 2199023255552L; // 0x20000000000L field public static final int FIELD_COUNT_SHIFT = 40; // 0x28 field public static final long FIELD_COUNT_SINGLE = 1099511627776L; // 0x10000000000L field public static final long FIELD_COUNT_UNKNOWN = 0L; // 0x0L field public static final int FIELD_ID_MASK = -8; // 0xfffffff8 field public static final int FIELD_ID_SHIFT = 3; // 0x3 field public static final long FIELD_TYPE_BOOL = 34359738368L; // 0x800000000L field public static final long FIELD_TYPE_BYTES = 51539607552L; // 0xc00000000L field public static final long FIELD_TYPE_DOUBLE = 4294967296L; // 0x100000000L field public static final long FIELD_TYPE_ENUM = 60129542144L; // 0xe00000000L field public static final long FIELD_TYPE_FIXED32 = 30064771072L; // 0x700000000L field public static final long FIELD_TYPE_FIXED64 = 25769803776L; // 0x600000000L field public static final long FIELD_TYPE_FLOAT = 8589934592L; // 0x200000000L field public static final long FIELD_TYPE_INT32 = 21474836480L; // 0x500000000L field public static final long FIELD_TYPE_INT64 = 12884901888L; // 0x300000000L field public static final long FIELD_TYPE_MASK = 1095216660480L; // 0xff00000000L field public static final long FIELD_TYPE_MESSAGE = 47244640256L; // 0xb00000000L field protected static final String[] FIELD_TYPE_NAMES; field public static final long FIELD_TYPE_SFIXED32 = 64424509440L; // 0xf00000000L field public static final long FIELD_TYPE_SFIXED64 = 68719476736L; // 0x1000000000L field public static final int FIELD_TYPE_SHIFT = 32; // 0x20 field public static final long FIELD_TYPE_SINT32 = 73014444032L; // 0x1100000000L field public static final long FIELD_TYPE_SINT64 = 77309411328L; // 0x1200000000L field public static final long FIELD_TYPE_STRING = 38654705664L; // 0x900000000L field public static final long FIELD_TYPE_UINT32 = 55834574848L; // 0xd00000000L field public static final long FIELD_TYPE_UINT64 = 17179869184L; // 0x400000000L field public static final long FIELD_TYPE_UNKNOWN = 0L; // 0x0L field public static final int WIRE_TYPE_END_GROUP = 4; // 0x4 field public static final int WIRE_TYPE_FIXED32 = 5; // 0x5 field public static final int WIRE_TYPE_FIXED64 = 1; // 0x1 field public static final int WIRE_TYPE_LENGTH_DELIMITED = 2; // 0x2 field public static final int WIRE_TYPE_MASK = 7; // 0x7 field public static final int WIRE_TYPE_START_GROUP = 3; // 0x3 field public static final int WIRE_TYPE_VARINT = 0; // 0x0 } public class WireTypeMismatchException extends android.util.proto.ProtoParseException { ctor public WireTypeMismatchException(String); } Loading
core/java/android/util/proto/ProtoOutputStream.java +193 −123 File changed.Preview size limit exceeded, changes collapsed. Show changes
core/java/android/util/proto/ProtoStream.java +304 −18 Original line number Diff line number Diff line Loading @@ -16,28 +16,104 @@ package android.util.proto; import android.annotation.TestApi; import android.annotation.NonNull; import android.annotation.Nullable; /** * Abstract base class for both protobuf streams. * Base utility class for protobuf streams. * * Contains a set of useful constants and methods used by both * ProtoOutputStream and ProtoInputStream * Contains a set of constants and methods used in generated code for * {@link ProtoOutputStream}. * * @hide */ @TestApi public abstract class ProtoStream { public class ProtoStream { /** * Number of bits to shift the field number to form a tag. * * <pre> * // Reading a field number from a tag. * int fieldNumber = tag >>> FIELD_ID_SHIFT; * * // Building a tag from a field number and a wire type. * int tag = (fieldNumber << FIELD_ID_SHIFT) | wireType; * </pre> * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int FIELD_ID_SHIFT = 3; /** * Mask to select the wire type from a tag. * * <pre> * // Reading a wire type from a tag. * int wireType = tag & WIRE_TYPE_MASK; * * // Building a tag from a field number and a wire type. * int tag = (fieldNumber << FIELD_ID_SHIFT) | wireType; * </pre> * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_MASK = (1 << FIELD_ID_SHIFT) - 1; /** * Mask to select the field id from a tag. * @hide (not used by anything, and not actually useful, because you also want * to shift when you mask the field id). */ public static final int FIELD_ID_MASK = ~WIRE_TYPE_MASK; /** * Varint wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_VARINT = 0; /** * Fixed64 wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_FIXED64 = 1; /** * Length delimited wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_LENGTH_DELIMITED = 2; /** * Start group wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_START_GROUP = 3; /** * End group wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_END_GROUP = 4; /** * Fixed32 wire type code. * * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final int WIRE_TYPE_FIXED32 = 5; /** Loading @@ -51,32 +127,147 @@ public abstract class ProtoStream { */ public static final long FIELD_TYPE_MASK = 0x0ffL << FIELD_TYPE_SHIFT; /** * Not a real wire type. * @hide */ public static final long FIELD_TYPE_UNKNOWN = 0; /* * The FIELD_TYPE_ constants are copied from * external/protobuf/src/google/protobuf/descriptor.h directly, so no * extra mapping needs to be maintained in this case. */ /** * The types are copied from external/protobuf/src/google/protobuf/descriptor.h directly, * so no extra mapping needs to be maintained in this case. * Field type code for double fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, double) * ProtoOutputStream.write(long, double)} method. */ public static final long FIELD_TYPE_DOUBLE = 1L << FIELD_TYPE_SHIFT; /** * Field type code for float fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, float) * ProtoOutputStream.write(long, float)} method. */ public static final long FIELD_TYPE_FLOAT = 2L << FIELD_TYPE_SHIFT; /** * Field type code for int64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_INT64 = 3L << FIELD_TYPE_SHIFT; /** * Field type code for uint64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_UINT64 = 4L << FIELD_TYPE_SHIFT; /** * Field type code for int32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_INT32 = 5L << FIELD_TYPE_SHIFT; /** * Field type code for fixed64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_FIXED64 = 6L << FIELD_TYPE_SHIFT; /** * Field type code for fixed32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ /** * Field type code for fixed32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_FIXED32 = 7L << FIELD_TYPE_SHIFT; /** * Field type code for bool fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, boolean) * ProtoOutputStream.write(long, boolean)} method. */ public static final long FIELD_TYPE_BOOL = 8L << FIELD_TYPE_SHIFT; /** * Field type code for string fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, String) * ProtoOutputStream.write(long, String)} method. */ public static final long FIELD_TYPE_STRING = 9L << FIELD_TYPE_SHIFT; // public static final long FIELD_TYPE_GROUP = 10L << FIELD_TYPE_SHIFT; // Deprecated. /** * Field type code for message fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#start(long) * ProtoOutputStream.start(long)} method. */ public static final long FIELD_TYPE_MESSAGE = 11L << FIELD_TYPE_SHIFT; /** * Field type code for bytes fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, byte[]) * ProtoOutputStream.write(long, byte[])} method. */ public static final long FIELD_TYPE_BYTES = 12L << FIELD_TYPE_SHIFT; /** * Field type code for uint32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_UINT32 = 13L << FIELD_TYPE_SHIFT; /** * Field type code for enum fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_ENUM = 14L << FIELD_TYPE_SHIFT; /** * Field type code for sfixed32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_SFIXED32 = 15L << FIELD_TYPE_SHIFT; /** * Field type code for sfixed64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_SFIXED64 = 16L << FIELD_TYPE_SHIFT; /** * Field type code for sint32 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, int) * ProtoOutputStream.write(long, int)} method. */ public static final long FIELD_TYPE_SINT32 = 17L << FIELD_TYPE_SHIFT; /** * Field type code for sint64 fields. Used to build constants in generated * code for use with the {@link ProtoOutputStream#write(long, long) * ProtoOutputStream.write(long, long)} method. */ public static final long FIELD_TYPE_SINT64 = 18L << FIELD_TYPE_SHIFT; protected static final String[] FIELD_TYPE_NAMES = new String[]{ private static final @NonNull String[] FIELD_TYPE_NAMES = new String[]{ "Double", "Float", "Int64", Loading @@ -100,19 +291,94 @@ public abstract class ProtoStream { // // FieldId flags for whether the field is single, repeated or packed. // /** * Bit offset for building a field id to be used with a * <code>{@link ProtoOutputStream}.write(...)</code>. * * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_REPEATED * @see #FIELD_COUNT_PACKED */ public static final int FIELD_COUNT_SHIFT = 40; /** * Bit mask for selecting the field count when reading a field id that * is used with a <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_REPEATED * @see #FIELD_COUNT_PACKED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_MASK = 0x0fL << FIELD_COUNT_SHIFT; /** * Unknown field count, encoded into a field id used with a * <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_REPEATED * @see #FIELD_COUNT_PACKED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_UNKNOWN = 0; /** * Single field count, encoded into a field id used with a * <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_REPEATED * @see #FIELD_COUNT_PACKED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_SINGLE = 1L << FIELD_COUNT_SHIFT; /** * Repeated field count, encoded into a field id used with a * <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_PACKED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_REPEATED = 2L << FIELD_COUNT_SHIFT; /** * Repeated packed field count, encoded into a field id used with a * <code>{@link ProtoOutputStream}.write(...)</code> method. * * @see #FIELD_COUNT_SHIFT * @see #FIELD_COUNT_MASK * @see #FIELD_COUNT_UNKNOWN * @see #FIELD_COUNT_SINGLE * @see #FIELD_COUNT_REPEATED * @see <a href="https://developers.google.com/protocol-buffers/docs/encoding">Protobuf * Encoding</a> */ public static final long FIELD_COUNT_PACKED = 5L << FIELD_COUNT_SHIFT; /** * Get the developer-usable name of a field type. */ public static String getFieldTypeString(long fieldType) { public static @Nullable String getFieldTypeString(long fieldType) { int index = ((int) ((fieldType & FIELD_TYPE_MASK) >>> FIELD_TYPE_SHIFT)) - 1; if (index >= 0 && index < FIELD_TYPE_NAMES.length) { return FIELD_TYPE_NAMES[index]; Loading @@ -124,7 +390,7 @@ public abstract class ProtoStream { /** * Get the developer-usable name of a field count. */ public static String getFieldCountString(long fieldCount) { public static @Nullable String getFieldCountString(long fieldCount) { if (fieldCount == FIELD_COUNT_SINGLE) { return ""; } else if (fieldCount == FIELD_COUNT_REPEATED) { Loading @@ -139,7 +405,7 @@ public abstract class ProtoStream { /** * Get the developer-usable name of a wire type. */ public static String getWireTypeString(int wireType) { public static @Nullable String getWireTypeString(int wireType) { switch (wireType) { case WIRE_TYPE_VARINT: return "Varint"; Loading @@ -161,7 +427,7 @@ public abstract class ProtoStream { /** * Get a debug string for a fieldId. */ public static String getFieldIdString(long fieldId) { public static @NonNull String getFieldIdString(long fieldId) { final long fieldCount = fieldId & FIELD_COUNT_MASK; String countString = getFieldCountString(fieldCount); if (countString == null) { Loading Loading @@ -218,29 +484,39 @@ public abstract class ProtoStream { /** * Get the encoded tag size from the token. * * @hide */ public static int getTagSizeFromToken(long token) { return (int) (0x7 & (token >> 61)); } /** * Get whether this is a call to startObject (false) or startRepeatedObject (true). * Get whether the token has the repeated bit set to true or false * * @hide */ public static boolean getRepeatedFromToken(long token) { return (0x1 & (token >> 60)) != 0; } /** * Get the nesting depth of startObject calls from the token. * Get the nesting depth from the token. * * @hide */ public static int getDepthFromToken(long token) { return (int) (0x01ff & (token >> 51)); } /** * Get the object ID from the token. The object ID is a serial number for the * Get the object ID from the token. * * <p>The object ID is a serial number for the * startObject calls that have happened on this object. The values are truncated * to 9 bits, but that is sufficient for error checking. * * @hide */ public static int getObjectIdFromToken(long token) { return (int) (0x07ffff & (token >> 32)); Loading @@ -248,6 +524,8 @@ public abstract class ProtoStream { /** * Get the location of the offset recorded in the token. * * @hide */ public static int getOffsetFromToken(long token) { return (int) token; Loading @@ -255,8 +533,11 @@ public abstract class ProtoStream { /** * Convert the object ID to the ordinal value -- the n-th call to startObject. * The object IDs start at -1 and count backwards, so that the value is unlikely * * <p>The object IDs start at -1 and count backwards, so that the value is unlikely * to alias with an actual size field that had been written. * * @hide */ public static int convertObjectIdToOrdinal(int objectId) { return (-1 & 0x07ffff) - objectId; Loading @@ -265,7 +546,7 @@ public abstract class ProtoStream { /** * Return a debugging string of a token. */ public static String token2String(long token) { public static @NonNull String token2String(long token) { if (token == 0L) { return "Token(0)"; } else { Loading @@ -277,4 +558,9 @@ public abstract class ProtoStream { + ')'; } } /** * @hide */ protected ProtoStream() {} }
core/java/android/util/proto/ProtoUtils.java +1 −3 Original line number Diff line number Diff line Loading @@ -24,12 +24,12 @@ import java.io.IOException; /** * This class contains a list of helper functions to write common proto in * //frameworks/base/core/proto/android/base directory * @hide */ public class ProtoUtils { /** * Dump AggStats to ProtoOutputStream * @hide */ public static void toAggStatsProto(ProtoOutputStream proto, long fieldId, long min, long average, long max) { Loading @@ -42,7 +42,6 @@ public class ProtoUtils { /** * Dump Duration to ProtoOutputStream * @hide */ public static void toDuration(ProtoOutputStream proto, long fieldId, long startMs, long endMs) { final long token = proto.start(fieldId); Loading @@ -53,7 +52,6 @@ public class ProtoUtils { /** * Helper function to write bit-wise flags to proto as repeated enums * @hide */ public static void writeBitWiseFlagsToProtoEnum(ProtoOutputStream proto, long fieldId, int flags, int[] origEnums, int[] protoEnums) { Loading