this.maxResults = maxResults;
}
public Result send(Connection connection) throws DespotifyException {
/* Create channel callback */
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);
buffer.flip();
/* Register channel. */
Channel.register(channel);
/* Send packet. */
connection.getProtocol().sendPacket(PacketType.search, buffer, "search");
/* Get data and inflate it. */
byte[] data = GZIP.inflate(callback.getData("gzipped search response"));
if (log.isInfoEnabled()) {
log.info("received search response packet, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log));
}