@Override public int encodedLength(T val) { return val.getSerializedSize(); }
private static int getDelimitedLength(Message message) { int length = message.getSerializedSize(); return length + CodedOutputStream.computeRawVarint32Size(length); }
public static void writeMessage(DataOutputStream output, Message message) throws IOException { /* * We don't use varints here because the c++ version of the protocol * buffer classes seem to be buggy requesting more data than necessary * from the underlying stream causing it to block forever */ output.writeInt(message.getSerializedSize()); CodedOutputStream codedOut = CodedOutputStream.newInstance(output); message.writeTo(codedOut); codedOut.flush(); }
@Override void writeTo(ResponseBuffer out) throws IOException { int length = message.getSerializedSize(); length += CodedOutputStream.computeRawVarint32Size(length); out.ensureCapacity(length); message.writeDelimitedTo(out); }
private ByteBuf serializeProto(Message message) throws IOException { if (GrpcSerializationFormats.isProto(serializationFormat)) { final int serializedSize = message.getSerializedSize(); if (serializedSize == 0) { return Unpooled.EMPTY_BUFFER;
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; }
outputContainer.ensureSpace(response.getSerializedSize());
@Override public int getOutputSerializedSize(Object output) throws IOException { if (output instanceof Message) { return ((Message) output).getSerializedSize(); } return 0; } }
@Override public int encodedLength(T val) { return val.getSerializedSize(); }
@Override public int getInputSerializedSize(Object input) throws IOException { if (input instanceof Message) { return ((Message) input).getSerializedSize(); } return 0; }
@Override public int getOutputSerializedSize(Object output) throws IOException { if (output instanceof Message) { return ((Message) output).getSerializedSize(); } return 0; } }
@Override public int getInputSerializedSize(Object input) throws IOException { if (input instanceof Message) { return ((Message) input).getSerializedSize(); } return 0; }
@Override public int encodedLength(T val) { return val.getSerializedSize(); }
@Override public int size() { return value.getSerializedSize(); }
@Override public long getMemorySize() { // The protobuf estimate is obviously inaccurate. return msg_.getSerializedSize() + realTuple.getMemorySize(); } }
private static int getDelimitedLength(Message message) { int length = message.getSerializedSize(); return length + CodedOutputStream.computeRawVarint32Size(length); }
@Override public int getLength() { int resLen; if (theResponse != null) { resLen = theResponse.getSerializedSize(); } else if (theResponseRead != null ) { resLen = theResponseRead.length; } else { throw new IllegalArgumentException( "getLength on uninitialized RpcWrapper"); } return CodedOutputStream.computeRawVarint32Size(resLen) + resLen; } }
public static void sendProtobuf(Message request, OutputStream os) throws IOException { os.write(Bytes.intToBytes(request.getSerializedSize())); request.writeTo(os); os.flush(); }
protected void serialize() throws IOException { out_.write(Protobufs.KNOWN_GOOD_POSITION_MARKER); Message block = SerializedBlock .newInstance(innerClass_.getCanonicalName(),protoBlobs_) .getMessage(); protoBlobs_ = new ArrayList<ByteString>(numRecordsPerBlock_); writeRawLittleEndian32(block.getSerializedSize()); block.writeTo(out_); }
@Override void writeTo(ResponseBuffer out) throws IOException { int length = message.getSerializedSize(); length += CodedOutputStream.computeRawVarint32Size(length); out.ensureCapacity(length); message.writeDelimitedTo(out); }