Transforms a protobuf Cell message into a KeyValue (HBase 0.95+). @param buf The buffer to de-serialize from. @param prev Another KeyValue previously de-serialized from the same buffer. Can be null. The idea here is that KeyValues often come in a sorted batch, and often share a num
(final CellPB.Cell cell, final KeyValue prev)
| 308 | * @return a new instance (guaranteed non-{@code null}). |
| 309 | */ |
| 310 | static KeyValue fromCell(final CellPB.Cell cell, final KeyValue prev) { |
| 311 | final byte[] key = Bytes.get(cell.getRow()); |
| 312 | final byte[] family = Bytes.get(cell.getFamily()); |
| 313 | final byte[] qualifier = Bytes.get(cell.getQualifier()); |
| 314 | final long timestamp = cell.getTimestamp(); |
| 315 | final byte[] value = Bytes.get(cell.getValue()); |
| 316 | if (prev == null) { |
| 317 | return new KeyValue(key, family, qualifier, timestamp, /*key_type,*/ |
| 318 | value); |
| 319 | } else { |
| 320 | return new KeyValue(Bytes.deDup(prev.key, key), |
| 321 | Bytes.deDup(prev.family, family), |
| 322 | Bytes.deDup(prev.qualifier, qualifier), |
| 323 | timestamp, /*key_type,*/ value); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // ------------------------------------------------------------ // |
| 328 | // Misc helper functions to validate some aspects of KeyValues. // |
no test coverage detected