/** Write a {@code bool} field, including tag, to the stream. */ public void writeBool(int fieldNumber, boolean value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); writeRawByte(value ? 1 : 0); }
/** Write a {@code float} field, including tag, to the stream. */ public void writeFloat(int fieldNumber, float value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); writeRawLittleEndian32(Float.floatToRawIntBits(value)); }
/** Write a {@code fixed32} field, including tag, to the stream. */ public void writeFixed32(int fieldNumber, int value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); writeRawLittleEndian32(value); }
/** Write an {@code sfixed32} field, including tag, to the stream. */ public void writeSFixed32(int fieldNumber, int value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); writeRawLittleEndian32(value); }
/** Write a {@code uint64} field, including tag, to the stream. */ public void writeUInt64(int fieldNumber, long value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); writeRawVarint64(value); }
/** Write an {@code int64} field, including tag, to the stream. */ public void writeInt64(int fieldNumber, long value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); writeRawVarint64(value); }
/** Write an {@code sfixed64} field, including tag, to the stream. */ public void writeSFixed64(int fieldNumber, long value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); writeRawLittleEndian64(value); }
public static void writeMessage(CodedOutputStream output, int tag, MessageBuffer message) throws IOException { output.writeTag(tag, WireFormat.WIRETYPE_LENGTH_DELIMITED); message.writeFramed(output); }
static protected void writeMessage(CodedOutputStream output, int tag, BaseMessage message) throws IOException { output.writeTag(tag, WireFormat.WIRETYPE_LENGTH_DELIMITED); message.writeFramed(output); }
/** Write a {@code double} field, including tag, to the stream. */ public void writeDouble(int fieldNumber, double value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); writeRawLittleEndian64(Double.doubleToRawLongBits(value)); }
/** Write a {@code fixed64} field, including tag, to the stream. */ public void writeFixed64(int fieldNumber, long value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); writeRawLittleEndian64(value); }
/** Write a {@code uint32} field, including tag, to the stream. */ public void writeUInt32(int fieldNumber, int value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); writeRawVarint32(value); }
/** * Write an enum field, including tag, to the stream. Caller is responsible * for converting the enum value to its numeric value. */ public void writeEnum(int fieldNumber, int value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); writeRawVarint32(value); }
/** Write a {@code string} field, including tag, to the stream. */ public void writeString(int fieldNumber, String value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); // Unfortunately there does not appear to be any way to tell Java to // encode // UTF-8 directly into our buffer, so we have to let it create its own // byte // array and then copy. byte[] bytes = value.getBytes("UTF-8"); writeRawVarint32(bytes.length); writeRawBytes(bytes); }
/** Write an {@code sint64} field, including tag, to the stream. */ public void writeSInt64(int fieldNumber, long value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); writeRawVarint64(encodeZigZag64(value)); }
/** Write an {@code int32} field, including tag, to the stream. */ public void writeInt32(int fieldNumber, int value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); if (value >= 0) { writeRawVarint32(value); } else { // Must sign-extend. writeRawVarint64(value); } }
/** Write a {@code bytes} field, including tag, to the stream. */ public void writeBytes(int fieldNumber, Buffer value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); writeRawVarint32(value.length); writeRawBytes(value.data, value.offset, value.length); }
/** Write an {@code sint32} field, including tag, to the stream. */ public void writeSInt32(int fieldNumber, int value) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); writeRawVarint32(encodeZigZag32(value)); }