/** Write a {@code uint32} field to the stream. */ public void writeUInt32NoTag(final int value) throws IOException { writeRawVarint32(value); }
/** Write a {@code string} field to the stream. */ public void writeStringNoTag(final String value) throws IOException { // 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. final byte[] bytes = value.getBytes("UTF-8"); writeRawVarint32(bytes.length); writeRawBytes(bytes); }
/** Encode and write a tag. */ public void writeTag(final int fieldNumber, final int wireType) throws IOException { writeRawVarint32(WireFormat.makeTag(fieldNumber, wireType)); }
/** Write an {@code int32} field to the stream. */ public void writeInt32NoTag(final int value) throws IOException { if (value >= 0) { writeRawVarint32(value); } else { // Must sign-extend. writeRawVarint64(value); } }
/** Write an {@code sint32} field to the stream. */ public void writeSInt32NoTag(final int value) throws IOException { writeRawVarint32(encodeZigZag32(value)); }
public void writeDelimitedTo(OutputStream output) throws IOException { final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); codedOutput.writeRawVarint32(getSerializedSize()); writeTo(codedOutput); codedOutput.flush(); }
@Override public void writeDelimitedTo(OutputStream output) throws IOException { final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); codedOutput.writeRawVarint32(getSerializedSize()); writeTo(codedOutput); codedOutput.flush(); }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); if (getTimestampsList().size() > 0) { output.writeRawVarint32(10); output.writeRawVarint32(timestampsMemoizedSerializedSize); } for (int i = 0; i < timestamps_.size(); i++) { output.writeInt64NoTag(timestamps_.get(i)); } if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeBool(2, canHint_); } getUnknownFields().writeTo(output); }
/** Write an embedded message field to the stream. */ public void writeMessageNoTag(final MessageLite value) throws IOException { writeRawVarint32(value.getSerializedSize()); value.writeTo(this); }
/** Write a {@code bytes} field to the stream. */ public void writeBytesNoTag(final ByteString value) throws IOException { writeRawVarint32(value.size()); writeRawBytes(value); }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeInt32(1, oppositeMajorFragmentId_); } if (getIncomingMinorFragmentList().size() > 0) { output.writeRawVarint32(18); output.writeRawVarint32(incomingMinorFragmentMemoizedSerializedSize); } for (int i = 0; i < incomingMinorFragment_.size(); i++) { output.writeInt32NoTag(incomingMinorFragment_.get(i)); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeBool(3, supportsOutOfOrder_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeBool(4, isSpooling_); } getUnknownFields().writeTo(output); }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); com.google.protobuf.GeneratedMessage .ExtendableMessage<org.terasology.protobuf.EntityData.RunLengthEncoding16>.ExtensionWriter extensionWriter = newExtensionWriter(); if (getRunLengthsList().size() > 0) { output.writeRawVarint32(10); output.writeRawVarint32(runLengthsMemoizedSerializedSize); } for (int i = 0; i < runLengths_.size(); i++) { output.writeSInt32NoTag(runLengths_.get(i)); } if (getValuesList().size() > 0) { output.writeRawVarint32(18); output.writeRawVarint32(valuesMemoizedSerializedSize); } for (int i = 0; i < values_.size(); i++) { output.writeSInt32NoTag(values_.get(i)); } extensionWriter.writeUntil(536870912, output); getUnknownFields().writeTo(output); }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); com.google.protobuf.GeneratedMessage .ExtendableMessage<org.terasology.protobuf.EntityData.EntityStore>.ExtensionWriter extensionWriter = newExtensionWriter(); for (int i = 0; i < entity_.size(); i++) { output.writeMessage(1, entity_.get(i)); } for (int i = 0; i < entityName_.size(); i++) { output.writeBytes(2, entityName_.getByteString(i)); } for (int i = 0; i < componentClass_.size(); i++) { output.writeBytes(3, componentClass_.getByteString(i)); } if (getEntityNamedList().size() > 0) { output.writeRawVarint32(34); output.writeRawVarint32(entityNamedMemoizedSerializedSize); } for (int i = 0; i < entityNamed_.size(); i++) { output.writeInt64NoTag(entityNamed_.get(i)); } extensionWriter.writeUntil(536870912, output); getUnknownFields().writeTo(output); }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); if (getPathList().size() > 0) { output.writeRawVarint32(10); output.writeRawVarint32(pathMemoizedSerializedSize); } for (int i = 0; i < path_.size(); i++) { output.writeInt32NoTag(path_.get(i)); } if (getSpanList().size() > 0) { output.writeRawVarint32(18); output.writeRawVarint32(spanMemoizedSerializedSize); } for (int i = 0; i < span_.size(); i++) { output.writeInt32NoTag(span_.get(i)); } if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeBytes(3, getLeadingCommentsBytes()); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeBytes(4, getTrailingCommentsBytes()); } getUnknownFields().writeTo(output); }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); com.google.protobuf.GeneratedMessage .ExtendableMessage<org.terasology.protobuf.EntityData.RunLengthEncoding8>.ExtensionWriter extensionWriter = newExtensionWriter(); if (getRunLengthsList().size() > 0) { output.writeRawVarint32(10); output.writeRawVarint32(runLengthsMemoizedSerializedSize); } for (int i = 0; i < runLengths_.size(); i++) { output.writeSInt32NoTag(runLengths_.get(i)); } if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeBytes(2, values_); } extensionWriter.writeUntil(536870912, output); getUnknownFields().writeTo(output); }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeUInt64(1, id_); } if (getTagsList().size() > 0) { output.writeRawVarint32(18); output.writeRawVarint32(tagsMemoizedSerializedSize); } for (int i = 0; i < tags_.size(); i++) { output.writeUInt32NoTag(tags_.get(i)); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeEnum(3, type_.getNumber()); } if (getGeometryList().size() > 0) { output.writeRawVarint32(34); output.writeRawVarint32(geometryMemoizedSerializedSize); } for (int i = 0; i < geometry_.size(); i++) { output.writeUInt32NoTag(geometry_.get(i)); } getUnknownFields().writeTo(output); }
public void writeDelimitedTo(final OutputStream output) throws IOException { final int serialized = getSerializedSize(); final int bufferSize = CodedOutputStream.computePreferredBufferSize( CodedOutputStream.computeRawVarint32Size(serialized) + serialized); final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, bufferSize); codedOutput.writeRawVarint32(serialized); writeTo(codedOutput); codedOutput.flush(); }
@Override public void writeDelimitedTo(final OutputStream output) throws IOException { final int serialized = getSerializedSize(); final int bufferSize = CodedOutputStream.computePreferredBufferSize( CodedOutputStream.computeRawVarint32Size(serialized) + serialized); final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, bufferSize); codedOutput.writeRawVarint32(serialized); writeTo(codedOutput); codedOutput.flush(); }
private byte[] setupResponseForProtobuf( RpcResponseHeaderProto header, Writable rv) throws IOException { Message payload = (rv != null) ? ((RpcWritable.ProtobufWrapper)rv).getMessage() : null; int length = getDelimitedLength(header); if (payload != null) { length += getDelimitedLength(payload); } byte[] buf = new byte[length + 4]; CodedOutputStream cos = CodedOutputStream.newInstance(buf); // the stream only supports little endian ints cos.writeRawByte((byte)((length >>> 24) & 0xFF)); cos.writeRawByte((byte)((length >>> 16) & 0xFF)); cos.writeRawByte((byte)((length >>> 8) & 0xFF)); cos.writeRawByte((byte)((length >>> 0) & 0xFF)); cos.writeRawVarint32(header.getSerializedSize()); header.writeTo(cos); if (payload != null) { cos.writeRawVarint32(payload.getSerializedSize()); payload.writeTo(cos); } return buf; }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer body = (ChannelBuffer) msg; int length = body.readableBytes(); ChannelBuffer header = channel.getConfig().getBufferFactory().getBuffer( body.order(), CodedOutputStream.computeRawVarint32Size(length)); CodedOutputStream codedOutputStream = CodedOutputStream .newInstance(new ChannelBufferOutputStream(header)); codedOutputStream.writeRawVarint32(length); codedOutputStream.flush(); return wrappedBuffer(header, body); }