Class ProtoWriter
java.lang.Object
com.codename1.io.grpc.ProtoWriter
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
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstream()Backing stream so generated codecs can stage a sub-message into aByteArrayOutputStreamand length-prefix the result.voidwriteBool(int field, boolean value) voidwriteBytes(int field, byte[] value) voidwriteDouble(int field, double value) voidwriteFixed32(int value) voidwriteFixed32Field(int field, int value) voidwriteFixed64(long value) voidwriteFixed64Field(int field, long value) voidwriteFloat(int field, float value) voidwriteInt32(int field, int value) voidwriteInt64(int field, long value) <T> voidwriteMessage(int field, T value, ProtoCodec<T> codec) Writes a nested@ProtoMessagevalue as a length-delimited field.<T> voidwriteMessageList(int field, List<T> values, ProtoCodec<T> codec) Writes arepeatedfield of nested messages (one tag + length prefix per element -- proto3 doesn't pack length-delimited repeated entries).voidwritePackedInt32(int field, List<Integer> values) Writes a packedrepeated int32field (proto3 default packing for scalar lists).voidwritePackedInt64(int field, List<Long> values) Writes a packedrepeated int64field.voidwriteSInt32(int field, int value) voidwriteSInt64(int field, long value) voidwriteString(int field, String value) voidwriteStringList(int field, List<String> values) Writes arepeatedfield of strings (one tag + length prefix per element).voidwriteTag(int fieldNumber, int wireType) voidwriteUInt32(int field, int value) voidwriteUInt64(int field, long value) voidwriteVarint32(int value) voidwriteVarint64(long value) static intzigZag32(int n) static longzigZag64(long n)
-
Field Details
-
WIRE_VARINT
public static final int WIRE_VARINT- See Also:
-
WIRE_I64
public static final int WIRE_I64- See Also:
-
WIRE_LEN
public static final int WIRE_LEN- See Also:
-
WIRE_I32
public static final int WIRE_I32- See Also:
-
-
Constructor Details
-
ProtoWriter
-
-
Method Details
-
stream
Backing stream so generated codecs can stage a sub-message into aByteArrayOutputStreamand length-prefix the result. -
writeTag
- Throws:
IOException
-
writeVarint32
- Throws:
IOException
-
writeVarint64
- Throws:
IOException
-
writeFixed32
- Throws:
IOException
-
writeFixed64
- Throws:
IOException
-
zigZag32
public static int zigZag32(int n) -
zigZag64
public static long zigZag64(long n) -
writeInt32
- Throws:
IOException
-
writeInt64
- Throws:
IOException
-
writeUInt32
- Throws:
IOException
-
writeUInt64
- Throws:
IOException
-
writeSInt32
- Throws:
IOException
-
writeSInt64
- Throws:
IOException
-
writeFixed32Field
- Throws:
IOException
-
writeFixed64Field
- Throws:
IOException
-
writeBool
- Throws:
IOException
-
writeFloat
- Throws:
IOException
-
writeDouble
- Throws:
IOException
-
writeString
- Throws:
IOException
-
writeBytes
- Throws:
IOException
-
writeMessage
Writes a nested@ProtoMessagevalue as a length-delimited field. Generated codecs call intoProtoCodecs.lookup(Class)to find the nested codec.- Throws:
IOException
-
writeMessageList
Writes arepeatedfield of nested messages (one tag + length prefix per element -- proto3 doesn't pack length-delimited repeated entries).- Throws:
IOException
-
writeStringList
Writes arepeatedfield of strings (one tag + length prefix per element).- Throws:
IOException
-
writePackedInt32
Writes a packedrepeated int32field (proto3 default packing for scalar lists).- Throws:
IOException
-
writePackedInt64
Writes a packedrepeated int64field.- Throws:
IOException
-