in tablestore/src/main/java/com/alicloud/openservices/tablestore/core/protocol/ResponseFactory.java [349:395]
public static GetRangeResponse createGetRangeResponse(ResponseContentWithMeta response,
OtsInternalApi.GetRangeResponse getRangeResponse) {
try {
ConsumedCapacity consumedCapacity = new ConsumedCapacity(
OTSProtocolParser.parseCapacityUnit(getRangeResponse.getConsumed().getCapacityUnit()));
GetRangeResponse result = new GetRangeResponse(response.getMeta(), consumedCapacity);
result.setBodyBytes(getRangeResponse.getSerializedSize());
if (!getRangeResponse.hasNextStartPrimaryKey()) {
// has no next primary key
result.setNextStartPrimaryKey(null);
} else {
PlainBufferCodedInputStream inputStream = new PlainBufferCodedInputStream(
new PlainBufferInputStream(getRangeResponse.getNextStartPrimaryKey().asReadOnlyByteBuffer()));
List<PlainBufferRow> rows = inputStream.readRowsWithHeader();
if (rows.size() != 1) {
throw new IOException("Expect only returns one row. Row count: " + rows.size());
}
PlainBufferRow row = rows.get(0);
if (row.hasDeleteMarker() || row.hasCells()) {
throw new IOException("The next primary key should only have primary key: " + row);
}
result.setNextStartPrimaryKey(PlainBufferConversion.toPrimaryKey(row.getPrimaryKey()));
}
if (!getRangeResponse.getRows().isEmpty()) {
List<Row> rows = new ArrayList<Row>();
PlainBufferCodedInputStream inputStream = new PlainBufferCodedInputStream(
new PlainBufferInputStream(getRangeResponse.getRows().asReadOnlyByteBuffer()));
List<PlainBufferRow> pbRows = inputStream.readRowsWithHeader();
for (PlainBufferRow pbRow : pbRows) {
rows.add(PlainBufferConversion.toRow(pbRow));
}
result.setRows(rows);
} else {
result.setRows(new ArrayList<Row>());
}
if (getRangeResponse.hasNextToken()) {
result.setNextToken(getRangeResponse.getNextToken().toByteArray());
}
return result;
} catch (Exception e) {
throw new ClientException("Failed to parse get range response.", e);
}
}