Skip to content

Instantly share code, notes, and snippets.

@umeshdangat
Last active Jun 27, 2017
Embed
What would you like to do?
SerDeQueryInfo
Class QueryContextInfo {
private long queryId;
private double valueOne;
private double valueTwo;
}
public static byte[] serialize(QueryContextInfo[] queryContextInfoRecords) {
byte[] bytes = new byte[Integer.BYTES + (queryContextInfoRecords.length * (Long.BYTES + 2 * (Double.BYTES)))];
ByteBuffer.wrap(bytes, 0, Integer.BYTES).putInt(queryContextInfoRecords.length);
int offset = Integer.BYTES;
for (QueryContextInfo queryContextInfo : queryContextInfoRecords) {
ByteBuffer.wrap(bytes, offset, Long.BYTES).putLong(queryContextInfo.getQueryId());
ByteBuffer.wrap(bytes, offset + Long.BYTES, Double.BYTES).putDouble(queryContextInfo.getValueOne());
ByteBuffer.wrap(bytes, offset + Long.BYTES + Double.BYTES, Double.BYTES).putDouble(queryContextInfo.getValueTwo());
offset += Long.BYTES + 2 * (Double.BYTES);
}
return bytes;
}
List<ByteBuffer> queryContext = document.getList(ByteBuffer.class, "query_context");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment