/** * Writes a {@link GeneratedMessageV3} to the socket output stream * * @param message * @throws IOException */ public void writeMessage(GeneratedMessageV3 message) throws IOException { if (message != null) { HANDLER_LOG.debug("writing message " + message.getAllFields().keySet()); long length = message.getSerializedSize(); // HEADER: first byte(s) is varint encoded length of the message // also, see writeMessage for the other way round outputStream.writeUInt64NoTag(CodedOutputStream.encodeZigZag64(length)); message.writeTo(outputStream); outputStream.flush(); } } }