ChannelCallback callback = new ChannelCallback();
byte[] utf8Bytes = query.getBytes(Charset.forName("UTF8"));
/* Create channel and buffer. */
Channel channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, callback);
ByteBuffer buffer = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + utf8Bytes.length);
/* Check offset and limit. */
if (offset < 0) {
throw new IllegalArgumentException("Offset needs to be >= 0");
}
// else if ((maxResults < 0 && maxResults != -1) || maxResults == 0) {
// throw new IllegalArgumentException("Limit needs to be either -1 for no limit or > 0");
// }
/* Append channel id, some values, query length and query. */
buffer.putShort((short) channel.getId());
buffer.putInt(offset); /* Result offset. */
buffer.putInt(maxResults); /* Reply limit. */
buffer.putShort((short) 0x0000);
buffer.put((byte) utf8Bytes.length);
buffer.put(utf8Bytes);