Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/util/proto/ProtoOutputStream#constants) \| [Ctors](https://developer.android.com/reference/android/util/proto/ProtoOutputStream#pubctors) \| [Methods](https://developer.android.com/reference/android/util/proto/ProtoOutputStream#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/util/proto/ProtoOutputStream#inhmethods)

# ProtoOutputStream

*** ** * ** ***


`
public

final

class
ProtoOutputStream
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.util.proto.ProtoOutputStream |

<br />

*** ** * ** ***

Class to write to a protobuf stream.


This API is not as convenient or type safe as the standard protobuf
classes. If possible, the best recommended library is to use protobuf lite.
However, in environments (such as the Android platform itself), a
more memory efficient version is necessary.

Each write method takes an ID code from the protoc generated classes
and the value to write. To make a nested object, call `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#start(long)`
and then `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#end(long)` when you are done.

The ID codes have type information embedded into them, so if you call
the incorrect function you will get an `https://developer.android.com/reference/java/lang/IllegalArgumentException`.

To retrieve the encoded protobuf stream, call `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getBytes()`.

stream as the top-level objects are finished.

## Summary

| ### Constants ||
|---|---|
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_MASK` Bit mask for selecting the field count when reading a field id that is used with a `` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_PACKED` Repeated packed field count, encoded into a field id used with a `` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_REPEATED` Repeated field count, encoded into a field id used with a `` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SHIFT` Bit offset for building a field id to be used with a `` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) ``. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SINGLE` Single field count, encoded into a field id used with a `` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_UNKNOWN` Unknown field count, encoded into a field id used with a `` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_ID_SHIFT` Number of bits to shift the field number to form a tag. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_BOOL` Field type code for bool fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_BYTES` Field type code for bytes fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_DOUBLE` Field type code for double fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_ENUM` Field type code for enum fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_FIXED32` Field type code for fixed32 fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_FIXED64` Field type code for fixed64 fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_FLOAT` Field type code for float fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_INT32` Field type code for int32 fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_INT64` Field type code for int64 fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_MASK` Mask for the field types stored in a fieldId. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_MESSAGE` Field type code for message fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_SFIXED32` Field type code for sfixed32 fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_SFIXED64` Field type code for sfixed64 fields. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_SHIFT` Position of the field type in a (long) fieldId. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_SINT32` Field type code for sint32 fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_SINT64` Field type code for sint64 fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_STRING` Field type code for string fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_UINT32` Field type code for uint32 fields. |
| `long` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_TYPE_UINT64` Field type code for uint64 fields. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#WIRE_TYPE_END_GROUP` End group wire type code. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#WIRE_TYPE_FIXED32` Fixed32 wire type code. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#WIRE_TYPE_FIXED64` Fixed64 wire type code. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#WIRE_TYPE_LENGTH_DELIMITED` Length delimited wire type code. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#WIRE_TYPE_MASK` Mask to select the wire type from a tag. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#WIRE_TYPE_START_GROUP` Start group wire type code. |
| `int` | `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#WIRE_TYPE_VARINT` Varint wire type code. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#ProtoOutputStream()() ` Construct a `https://developer.android.com/reference/android/util/proto/ProtoOutputStream` with the default chunk size. |
| ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#ProtoOutputStream(int)(int chunkSize) ` Construct a `https://developer.android.com/reference/android/util/proto/ProtoOutputStream` with the given chunk size. |
| ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#ProtoOutputStream(java.io.OutputStream)(https://developer.android.com/reference/java/io/OutputStream stream) ` Construct a `https://developer.android.com/reference/android/util/proto/ProtoOutputStream` that sits on top of an `https://developer.android.com/reference/java/io/OutputStream`. |

| ### Public methods ||
|---|---|
| ` static int` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#checkFieldId(long,%20long)(long fieldId, long expectedFlags) ` Validates that the fieldId provided is of the type and count from expectedType. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#dump(java.lang.String)(https://developer.android.com/reference/java/lang/String tag) ` Dump debugging data about the buffers with the given log tag. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#end(long)(long token) ` End the object started by start() that returned token. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#flush()() ` Write remaining data to the output stream. |
| ` byte[]` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getBytes()() ` Finish the encoding of the data, and return a byte\[\] with the protobuf formatted data. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getFieldCountString(long)(long fieldCount) ` Get the developer-usable name of a field count. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getFieldIdString(long)(long fieldId) ` Get a debug string for a fieldId. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getFieldTypeString(long)(long fieldType) ` Get the developer-usable name of a field type. |
| ` int` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getRawSize()() ` Returns the total size of the data that has been written, after full protobuf encoding has occurred. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getWireTypeString(int)(int wireType) ` Get the developer-usable name of a wire type. |
| ` static long` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#makeFieldId(int,%20long)(int id, long fieldFlags) ` Combine a fieldId (the field keys in the proto file) and the field flags. |
| ` static long` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#makeToken(int,%20boolean,%20int,%20int,%20int)(int tagSize, boolean repeated, int depth, int objectId, int offset) ` Make a token. |
| ` long` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#start(long)(long fieldId) ` Start a sub object. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#token2String(long)(long token) ` Return a debugging string of a token. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20java.lang.String)(long fieldId, https://developer.android.com/reference/java/lang/String val) ` Write a string value for the given fieldId. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20boolean)(long fieldId, boolean val) ` Write a boolean value for the given fieldId. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20int)(long fieldId, int val) ` Write a value for the given fieldId. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20float)(long fieldId, float val) ` Write a value for the given fieldId. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20long)(long fieldId, long val) ` Write a value for the given fieldId. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20double)(long fieldId, double val) ` Write a value for the given fieldId. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20byte[])(long fieldId, byte[] val) ` Write a byte\[\] value for the given fieldId. |
| ` void` | ` https://developer.android.com/reference/android/util/proto/ProtoOutputStream#writeTag(int,%20int)(int id, int wireType) ` Write an individual field tag by hand. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### FIELD_COUNT_MASK

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_COUNT_MASK
```

Bit mask for selecting the field count when reading a field id that
is used with a `` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method.

<br />

**See also:**

- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SHIFT`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_MASK`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_UNKNOWN`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SINGLE`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_REPEATED`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_PACKED`
- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

16492674416640
(0x00000f0000000000)


### FIELD_COUNT_PACKED

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_COUNT_PACKED
```

Repeated packed field count, encoded into a field id used with a
`` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method.

<br />

**See also:**

- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SHIFT`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_MASK`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_UNKNOWN`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SINGLE`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_REPEATED`
- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

5497558138880
(0x0000050000000000)


### FIELD_COUNT_REPEATED

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_COUNT_REPEATED
```

Repeated field count, encoded into a field id used with a
`` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method.

<br />

**See also:**

- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SHIFT`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_MASK`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_UNKNOWN`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SINGLE`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_PACKED`
- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

2199023255552
(0x0000020000000000)


### FIELD_COUNT_SHIFT

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FIELD_COUNT_SHIFT
```

Bit offset for building a field id to be used with a
`` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) ``.

<br />

**See also:**

- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_MASK`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_UNKNOWN`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SINGLE`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_REPEATED`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_PACKED`

Constant Value:

40
(0x00000028)


### FIELD_COUNT_SINGLE

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_COUNT_SINGLE
```

Single field count, encoded into a field id used with a
`` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method.

<br />

**See also:**

- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SHIFT`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_MASK`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_UNKNOWN`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_REPEATED`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_PACKED`
- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

1099511627776
(0x0000010000000000)


### FIELD_COUNT_UNKNOWN

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_COUNT_UNKNOWN
```

Unknown field count, encoded into a field id used with a
`` `https://developer.android.com/reference/android/util/proto/ProtoOutputStream`.write(...) `` method.

<br />

**See also:**

- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SHIFT`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_MASK`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_SINGLE`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_REPEATED`
- `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#FIELD_COUNT_PACKED`
- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

0
(0x0000000000000000)


### FIELD_ID_SHIFT

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FIELD_ID_SHIFT
```

Number of bits to shift the field number to form a tag.

```
// 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;
```

<br />

<br />

**See also:**

- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

3
(0x00000003)


### FIELD_TYPE_BOOL

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_BOOL
```

Field type code for bool fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20boolean)` method.

<br />

Constant Value:

34359738368
(0x0000000800000000)


### FIELD_TYPE_BYTES

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_BYTES
```

Field type code for bytes fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20byte[])` method.

<br />

Constant Value:

51539607552
(0x0000000c00000000)


### FIELD_TYPE_DOUBLE

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_DOUBLE
```

Field type code for double fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20double)` method.

<br />

Constant Value:

4294967296
(0x0000000100000000)


### FIELD_TYPE_ENUM

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_ENUM
```

Field type code for enum fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20int)` method.

<br />

Constant Value:

60129542144
(0x0000000e00000000)


### FIELD_TYPE_FIXED32

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_FIXED32
```

Field type code for fixed32 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20int)` method.

<br />

Constant Value:

30064771072
(0x0000000700000000)


### FIELD_TYPE_FIXED64

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_FIXED64
```

Field type code for fixed64 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20long)` method.

<br />

Constant Value:

25769803776
(0x0000000600000000)


### FIELD_TYPE_FLOAT

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_FLOAT
```

Field type code for float fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20float)` method.

<br />

Constant Value:

8589934592
(0x0000000200000000)


### FIELD_TYPE_INT32

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_INT32
```

Field type code for int32 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20int)` method.

<br />

Constant Value:

21474836480
(0x0000000500000000)


### FIELD_TYPE_INT64

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_INT64
```

Field type code for int64 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20long)` method.

<br />

Constant Value:

12884901888
(0x0000000300000000)


### FIELD_TYPE_MASK

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_MASK
```

Mask for the field types stored in a fieldId. Leaves a whole
byte for future expansion, even though there are currently only 17 types.

<br />

Constant Value:

1095216660480
(0x000000ff00000000)


### FIELD_TYPE_MESSAGE

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_MESSAGE
```

Field type code for message fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#start(long)` method.

<br />

Constant Value:

47244640256
(0x0000000b00000000)


### FIELD_TYPE_SFIXED32

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_SFIXED32
```

Field type code for sfixed32 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20int)` method.

<br />

Constant Value:

64424509440
(0x0000000f00000000)


### FIELD_TYPE_SFIXED64

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_SFIXED64
```

Field type code for sfixed64 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20long)` method.

<br />

Constant Value:

68719476736
(0x0000001000000000)


### FIELD_TYPE_SHIFT

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FIELD_TYPE_SHIFT
```

Position of the field type in a (long) fieldId.

<br />

Constant Value:

32
(0x00000020)


### FIELD_TYPE_SINT32

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_SINT32
```

Field type code for sint32 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20int)` method.

<br />

Constant Value:

73014444032
(0x0000001100000000)


### FIELD_TYPE_SINT64

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_SINT64
```

Field type code for sint64 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20long)` method.

<br />

Constant Value:

77309411328
(0x0000001200000000)


### FIELD_TYPE_STRING

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_STRING
```

Field type code for string fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20java.lang.String)` method.

<br />

Constant Value:

38654705664
(0x0000000900000000)


### FIELD_TYPE_UINT32

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_UINT32
```

Field type code for uint32 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20int)` method.

<br />

Constant Value:

55834574848
(0x0000000d00000000)


### FIELD_TYPE_UINT64

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final long FIELD_TYPE_UINT64
```

Field type code for uint64 fields. Used to build constants in generated
code for use with the `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#write(long,%20long)` method.

<br />

Constant Value:

17179869184
(0x0000000400000000)


### WIRE_TYPE_END_GROUP

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int WIRE_TYPE_END_GROUP
```

End group wire type code.

<br />

**See also:**

- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

4
(0x00000004)


### WIRE_TYPE_FIXED32

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int WIRE_TYPE_FIXED32
```

Fixed32 wire type code.

<br />

**See also:**

- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

5
(0x00000005)


### WIRE_TYPE_FIXED64

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int WIRE_TYPE_FIXED64
```

Fixed64 wire type code.

<br />

**See also:**

- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

1
(0x00000001)


### WIRE_TYPE_LENGTH_DELIMITED

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int WIRE_TYPE_LENGTH_DELIMITED
```

Length delimited wire type code.

<br />

**See also:**

- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

2
(0x00000002)


### WIRE_TYPE_MASK

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int WIRE_TYPE_MASK
```

Mask to select the wire type from a tag.

```
// 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;
```

<br />

<br />

**See also:**

- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

7
(0x00000007)


### WIRE_TYPE_START_GROUP

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int WIRE_TYPE_START_GROUP
```

Start group wire type code.

<br />

**See also:**

- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

3
(0x00000003)


### WIRE_TYPE_VARINT

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int WIRE_TYPE_VARINT
```

Varint wire type code.

<br />

**See also:**

- [Protobuf
  Encoding](https://developers.google.com/protocol-buffers/docs/encoding)

Constant Value:

0
(0x00000000)


## Public constructors

### ProtoOutputStream

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ProtoOutputStream ()
```

Construct a `https://developer.android.com/reference/android/util/proto/ProtoOutputStream` with the default chunk size.

This is for an in-memory proto. The caller should use `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getBytes()` for the result.

<br />

### ProtoOutputStream

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ProtoOutputStream (int chunkSize)
```

Construct a `https://developer.android.com/reference/android/util/proto/ProtoOutputStream` with the given chunk size.

This is for an in-memory proto. The caller should use `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getBytes()` for the result.

<br />

| Parameters ||
|---|---|
| `chunkSize` | `int` <br /> |

### ProtoOutputStream

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ProtoOutputStream (OutputStream stream)
```

Construct a `https://developer.android.com/reference/android/util/proto/ProtoOutputStream` that sits on top of an `https://developer.android.com/reference/java/io/OutputStream`.

The `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#flush()` method must be called when done writing
to flush any remaining data, although data \*may\* be written at intermediate
points within the writing as well.

<br />

| Parameters ||
|---|---|
| `stream` | `OutputStream`: This value cannot be `null`. <br /> |

## Public methods

### checkFieldId

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int checkFieldId (long fieldId, 
                long expectedFlags)
```

Validates that the fieldId provided is of the type and count from expectedType.

The type must match exactly to pass this check.

The count must match according to this truth table to pass the check:

expectedFlags
UNKNOWN SINGLE REPEATED PACKED
fieldId
UNKNOWN true false false false
SINGLE x true false false
REPEATED x false true false
PACKED x false true true

<br />

| Parameters ||
|---|---|
| `fieldId` | `long` <br /> |
| `expectedFlags` | `long` <br /> |

| Returns ||
|---|---|
| `int` | The raw ID of that field. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if it is not. |

### dump

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void dump (String tag)
```

Dump debugging data about the buffers with the given log tag.

<br />

| Parameters ||
|---|---|
| `tag` | `String`: This value cannot be `null`. <br /> |

### end

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void end (long token)
```

End the object started by start() that returned token.

<br />

| Parameters ||
|---|---|
| `token` | `long`: The token returned from `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#start(long)` <br /> |

### flush

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void flush ()
```

Write remaining data to the output stream. If there is no output stream,
this function does nothing. Any currently open objects (i.e. ones that
have not had `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#end(long)` called for them will not be written). Whether this
writes objects that are closed if there are remaining open objects is
undefined (current implementation does not write it, future ones will).
For now, can either call `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#getBytes()` or `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#flush()`, but not both.

<br />

### getBytes

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] getBytes ()
```

Finish the encoding of the data, and return a byte\[\] with
the protobuf formatted data.

After this call, do not call any of the write\* functions. The
behavior is undefined.

<br />

| Returns ||
|---|---|
| `byte[]` | This value cannot be `null`. <br /> |

### getFieldCountString

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String getFieldCountString (long fieldCount)
```

Get the developer-usable name of a field count.

<br />

| Parameters ||
|---|---|
| `fieldCount` | `long` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value may be `null`. <br /> |

### getFieldIdString

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String getFieldIdString (long fieldId)
```

Get a debug string for a fieldId.

<br />

| Parameters ||
|---|---|
| `fieldId` | `long` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value cannot be `null`. <br /> |

### getFieldTypeString

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String getFieldTypeString (long fieldType)
```

Get the developer-usable name of a field type.

<br />

| Parameters ||
|---|---|
| `fieldType` | `long`: Value is one of the following: |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value may be `null`. <br /> |

### getRawSize

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getRawSize ()
```

Returns the total size of the data that has been written, after full
protobuf encoding has occurred.

<br />

| Returns ||
|---|---|
| `int` | the uncompressed buffer size <br /> |

### getWireTypeString

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String getWireTypeString (int wireType)
```

Get the developer-usable name of a wire type.

<br />

| Parameters ||
|---|---|
| `wireType` | `int`: Value is one of the following: |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value may be `null`. <br /> |

### makeFieldId

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long makeFieldId (int id, 
                long fieldFlags)
```

Combine a fieldId (the field keys in the proto file) and the field flags.
Mostly useful for testing because the generated code contains the fieldId
constants.

<br />

| Parameters ||
|---|---|
| `id` | `int` <br /> |
| `fieldFlags` | `long` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

### makeToken

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static long makeToken (int tagSize, 
                boolean repeated, 
                int depth, 
                int objectId, 
                int offset)
```

Make a token.
Bits 61-63 - tag size (So we can go backwards later if the object had not data)
- 3 bits, max value 7, max value needed 5
Bit 60 - true if the object is repeated (lets us require endObject or endRepeatedObject)
Bits 59-51 - depth (For error checking)
- 9 bits, max value 512, when checking, value is masked (if we really
are more than 512 levels deep)
Bits 32-50 - objectId (For error checking)
- 19 bits, max value 524,288. that's a lot of objects. IDs will wrap
because of the overflow, and only the tokens are compared.
Bits 0-31 - offset of interest for the object.

<br />

| Parameters ||
|---|---|
| `tagSize` | `int` <br /> |
| `repeated` | `boolean` <br /> |
| `depth` | `int` <br /> |
| `objectId` | `int` <br /> |
| `offset` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

### start

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long start (long fieldId)
```

Start a sub object.

<br />

| Parameters ||
|---|---|
| `fieldId` | `long`: The field identifier constant from the generated class. <br /> |

| Returns ||
|---|---|
| `long` | The token to call `https://developer.android.com/reference/android/util/proto/ProtoOutputStream#end(long)` with. <br /> |

### token2String

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String token2String (long token)
```

Return a debugging string of a token.

<br />

| Parameters ||
|---|---|
| `token` | `long` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value cannot be `null`. <br /> |

### write

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void write (long fieldId, 
                String val)
```

Write a string value for the given fieldId.

If the field is not a string field, an exception will be thrown.

<br />

| Parameters ||
|---|---|
| `fieldId` | `long`: The field identifier constant from the generated class. <br /> |
| `val` | `String`: The value. This value may be `null`. <br /> |

### write

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void write (long fieldId, 
                boolean val)
```

Write a boolean value for the given fieldId.

If the field is not a bool field, an `https://developer.android.com/reference/java/lang/IllegalStateException` will be thrown.

<br />

| Parameters ||
|---|---|
| `fieldId` | `long`: The field identifier constant from the generated class. <br /> |
| `val` | `boolean`: The value. <br /> |

### write

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void write (long fieldId, 
                int val)
```

Write a value for the given fieldId.

Will automatically convert for the following field types, and
throw an exception for others: double, float, int32, int64, uint32, uint64,
sint32, sint64, fixed32, fixed64, sfixed32, sfixed64, bool, enum.

<br />

| Parameters ||
|---|---|
| `fieldId` | `long`: The field identifier constant from the generated class. <br /> |
| `val` | `int`: The value. <br /> |

### write

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void write (long fieldId, 
                float val)
```

Write a value for the given fieldId.

Will automatically convert for the following field types, and
throw an exception for others: double, float, int32, int64, uint32, uint64,
sint32, sint64, fixed32, fixed64, sfixed32, sfixed64, bool, enum.

<br />

| Parameters ||
|---|---|
| `fieldId` | `long`: The field identifier constant from the generated class. <br /> |
| `val` | `float`: The value. <br /> |

### write

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void write (long fieldId, 
                long val)
```

Write a value for the given fieldId.

Will automatically convert for the following field types, and
throw an exception for others: double, float, int32, int64, uint32, uint64,
sint32, sint64, fixed32, fixed64, sfixed32, sfixed64, bool, enum.

<br />

| Parameters ||
|---|---|
| `fieldId` | `long`: The field identifier constant from the generated class. <br /> |
| `val` | `long`: The value. <br /> |

### write

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void write (long fieldId, 
                double val)
```

Write a value for the given fieldId.

Will automatically convert for the following field types, and
throw an exception for others: double, float, int32, int64, uint32, uint64,
sint32, sint64, fixed32, fixed64, sfixed32, sfixed64, bool, enum.

<br />

| Parameters ||
|---|---|
| `fieldId` | `long`: The field identifier constant from the generated class. <br /> |
| `val` | `double`: The value. <br /> |

### write

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void write (long fieldId, 
                byte[] val)
```

Write a byte\[\] value for the given fieldId.

If the field is not a bytes or object field, an exception will be thrown.

<br />

| Parameters ||
|---|---|
| `fieldId` | `long`: The field identifier constant from the generated class. <br /> |
| `val` | `byte`: The value. This value may be `null`. <br /> |

### writeTag

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void writeTag (int id, 
                int wireType)
```

Write an individual field tag by hand.

See [Protobuf
Encoding](https://developers.google.com/protocol-buffers/docs/encoding) for details on the structure of how tags and data are written.

<br />

| Parameters ||
|---|---|
| `id` | `int` <br /> |
| `wireType` | `int`: Value is one of the following: |