# Class ProtoWriter

java.lang.Object
com.codename1.io.grpc.ProtoWriter

public final class ProtoWriter extends Object

Low-level protobuf wire-format writer used by generated `ProtoCodec` implementations. Provides per-scalar-type field emitters that skip default values (proto3 default-omission behaviour) so the byte sequence matches what `protoc`-generated code would emit for the same input.

Wire types (3-bit tag suffix):

Code | Name | Used for
--- | --- | ---
0 | VARINT | int32, int64, uint32, uint64, sint*, bool, enum
1 | I64 | fixed64, sfixed64, double
2 | LEN | string, bytes, embedded messages, packed repeated
5 | I32 | fixed32, sfixed32, float

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `WIRE_I32`
  `static final int`
  `WIRE_I64`
  `static final int`
  `WIRE_LEN`
  `static final int`
  `WIRE_VARINT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ProtoWriter(OutputStream out)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `OutputStream`
  `stream()`
  Backing stream so generated codecs can stage a sub-message into a `ByteArrayOutputStream` and length-prefix the result.
  `void`
  `writeBool(int field, boolean value)`
  `void`
  `writeBytes(int field, byte[] value)`
  `void`
  `writeDouble(int field, double value)`
  `void`
  `writeFixed32(int value)`
  `void`
  `writeFixed32Field(int field, int value)`
  `void`
  `writeFixed64(long value)`
  `void`
  `writeFixed64Field(int field, long value)`
  `void`
  `writeFloat(int field, float value)`
  `void`
  `writeInt32(int field, int value)`
  `void`
  `writeInt64(int field, long value)`
  `<T> void`
  `writeMessage(int field, T value, ProtoCodec<T> codec)`
  Writes a nested `@ProtoMessage` value as a length-delimited field.
  `<T> void`
  `writeMessageList(int field, List<T> values, ProtoCodec<T> codec)`
  Writes a `repeated` field of nested messages (one tag + length prefix per element -- proto3 doesn't pack length-delimited repeated entries).
  `void`
  `writePackedInt32(int field, List<Integer> values)`
  Writes a packed `repeated int32` field (proto3 default packing for scalar lists).
  `void`
  `writePackedInt64(int field, List<Long> values)`
  Writes a packed `repeated int64` field.
  `void`
  `writeSInt32(int field, int value)`
  `void`
  `writeSInt64(int field, long value)`
  `void`
  `writeString(int field, String value)`
  `void`
  `writeStringList(int field, List<String> values)`
  Writes a `repeated` field of strings (one tag + length prefix per element).
  `void`
  `writeTag(int fieldNumber, int wireType)`
  `void`
  `writeUInt32(int field, int value)`
  `void`
  `writeUInt64(int field, long value)`
  `void`
  `writeVarint32(int value)`
  `void`
  `writeVarint64(long value)`
  `static int`
  `zigZag32(int n)`
  `static long`
  `zigZag64(long n)`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### WIRE_VARINT

    public static final int WIRE_VARINT
    See Also:
      - Constant Field Values

  - ### WIRE_I64

    public static final int WIRE_I64
    See Also:
      - Constant Field Values

  - ### WIRE_LEN

    public static final int WIRE_LEN
    See Also:
      - Constant Field Values

  - ### WIRE_I32

    public static final int WIRE_I32
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### ProtoWriter

    public ProtoWriter(OutputStream out)

- ## Method Details

  - ### stream

    public OutputStream stream()
    Backing stream so generated codecs can stage a sub-message into a `ByteArrayOutputStream` and length-prefix the result.

  - ### writeTag

    public void writeTag(int fieldNumber, int wireType) throws IOException
    Throws:
      `IOException`

  - ### writeVarint32

    public void writeVarint32(int value) throws IOException
    Throws:
      `IOException`

  - ### writeVarint64

    public void writeVarint64(long value) throws IOException
    Throws:
      `IOException`

  - ### writeFixed32

    public void writeFixed32(int value) throws IOException
    Throws:
      `IOException`

  - ### writeFixed64

    public void writeFixed64(long value) throws IOException
    Throws:
      `IOException`

  - ### zigZag32

    public static int zigZag32(int n)

  - ### zigZag64

    public static long zigZag64(long n)

  - ### writeInt32

    public void writeInt32(int field, int value) throws IOException
    Throws:
      `IOException`

  - ### writeInt64

    public void writeInt64(int field, long value) throws IOException
    Throws:
      `IOException`

  - ### writeUInt32

    public void writeUInt32(int field, int value) throws IOException
    Throws:
      `IOException`

  - ### writeUInt64

    public void writeUInt64(int field, long value) throws IOException
    Throws:
      `IOException`

  - ### writeSInt32

    public void writeSInt32(int field, int value) throws IOException
    Throws:
      `IOException`

  - ### writeSInt64

    public void writeSInt64(int field, long value) throws IOException
    Throws:
      `IOException`

  - ### writeFixed32Field

    public void writeFixed32Field(int field, int value) throws IOException
    Throws:
      `IOException`

  - ### writeFixed64Field

    public void writeFixed64Field(int field, long value) throws IOException
    Throws:
      `IOException`

  - ### writeBool

    public void writeBool(int field, boolean value) throws IOException
    Throws:
      `IOException`

  - ### writeFloat

    public void writeFloat(int field, float value) throws IOException
    Throws:
      `IOException`

  - ### writeDouble

    public void writeDouble(int field, double value) throws IOException
    Throws:
      `IOException`

  - ### writeString

    public void writeString(int field, String value) throws IOException
    Throws:
      `IOException`

  - ### writeBytes

    public void writeBytes(int field, byte[] value) throws IOException
    Throws:
      `IOException`

  - ### writeMessage

    public <T> void writeMessage(int field, T value, ProtoCodec<T> codec) throws IOException
    Writes a nested `@ProtoMessage` value as a length-delimited field. Generated codecs call into `ProtoCodecs.lookup(Class)` to find the nested codec.
    Throws:
      `IOException`

  - ### writeMessageList

    public <T> void writeMessageList(int field, List<T> values, ProtoCodec<T> codec) throws IOException
    Writes a `repeated` field of nested messages (one tag + length prefix per element -- proto3 doesn't pack length-delimited repeated entries).
    Throws:
      `IOException`

  - ### writeStringList

    public void writeStringList(int field, List<String> values) throws IOException
    Writes a `repeated` field of strings (one tag + length prefix per element).
    Throws:
      `IOException`

  - ### writePackedInt32

    public void writePackedInt32(int field, List<Integer> values) throws IOException
    Writes a packed `repeated int32` field (proto3 default packing for scalar lists).
    Throws:
      `IOException`

  - ### writePackedInt64

    public void writePackedInt64(int field, List<Long> values) throws IOException
    Writes a packed `repeated int64` field.
    Throws:
      `IOException`