ByteBuffer buffer = ByteBuffer.wrap(body).order(ByteOrder.LITTLE_ENDIAN);
Tuple tuple = Tuple.create(buffer, ByteOrder.LITTLE_ENDIAN);
Tuple stored = null;
Space space = spaces.get(spaceNum);
if (op != Insert.OP_CODE && (stored = space.get(tuple)) == null) {
Response response = new Response(op, 4, request.getId());
response.setBody(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(0).array());
return response;
}
if (op == Insert.OP_CODE) {
stored = put(spaceNum, tuple, (flags & Flags.ADD_TUPLE) > 0, (flags & Flags.REPLACE_TUPLE) > 0);
} else if (op == Delete.OP_CODE) {
stored = delete(spaceNum, tuple);
} else if (op == Update.OP_CODE) {
int ops = buffer.getInt();
for (int i = 0; i < ops; i++) {
update(spaceNum, buffer, tuple);
}
stored = get(spaceNum, 0, new Tuple(1).setBytes(0, tuple.getBytes(0))).get(0);
}
if ((dmlRequest.getFlags() & Flags.RETURN_TUPLE) > 0) {
byte[] responseBody = stored.pack();
Response response = new Response(op, responseBody.length + 8, request.getId());
response.setBody(ByteBuffer.allocate(responseBody.length + 8).order(ByteOrder.LITTLE_ENDIAN).putInt(1).putInt(responseBody.length)
.put(responseBody).array());
return response;
} else {
Response response = new Response(op, 4, request.getId());
response.setCount(1);
return response;
}
}