Serializes a PBuf response with a frame length for upstream processing @param header The header to encode @param response The response to encode @return The buffer to pass upstream
(final ResponseHeader header,
final GeneratedMessageLite response)
| 81 | * @return The buffer to pass upstream |
| 82 | */ |
| 83 | static ChannelBuffer writeToBuffer(final ResponseHeader header, |
| 84 | final GeneratedMessageLite response) throws Exception { |
| 85 | final int hlen = header.getSerializedSize(); |
| 86 | final int vhlen = CodedOutputStream.computeRawVarint32Size(hlen); |
| 87 | final int pblen = response != null ? response.getSerializedSize() : 0; |
| 88 | final int vlen = CodedOutputStream.computeRawVarint32Size(pblen); |
| 89 | final byte[] buf = new byte[hlen + vhlen + vlen + pblen + 4]; |
| 90 | final CodedOutputStream out = CodedOutputStream.newInstance(buf, 4, |
| 91 | hlen + vhlen + vlen + pblen); |
| 92 | |
| 93 | out.writeMessageNoTag(header); |
| 94 | if (response != null) { |
| 95 | out.writeMessageNoTag(response); |
| 96 | } |
| 97 | |
| 98 | Bytes.setInt(buf, buf.length - 4); |
| 99 | return ChannelBuffers.wrappedBuffer(buf); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Convert a key value pair to a cell for responses |
no test coverage detected