Skip to content

Instantly share code, notes, and snippets.

@umeshdangat
Last active June 27, 2017 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umeshdangat/702d6b38f7395f857b3bf936cb1eeed0 to your computer and use it in GitHub Desktop.
Save umeshdangat/702d6b38f7395f857b3bf936cb1eeed0 to your computer and use it in GitHub Desktop.
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