MCPcopy Create free account
hub / github.com/OpenTSDB/asynchbase / numberOfKeyValuesAhead

Method numberOfKeyValuesAhead

src/RegionClient.java:1874–1893  ·  view source on GitHub ↗

Pre-computes how many KVs we have so we can rightsized arrays. This assumes that what's coming next in the buffer is a sequence of KeyValues, each of which is prefixed by its length on 32 bits. @param buf The buffer to peek into. @param length The total size of all the KeyValues that follow.

(final ChannelBuffer buf, int length)

Source from the content-addressed store, hash-verified

1872 * @param length The total size of all the KeyValues that follow.
1873 */
1874 static int numberOfKeyValuesAhead(final ChannelBuffer buf, int length) {
1875 // Immediately try to "fault" if `length' bytes aren't available.
1876 ensureReadable(buf, length);
1877 int num_kv = 0;
1878 int offset = buf.readerIndex();
1879 length += offset;
1880 while (offset < length) {
1881 final int kv_length = buf.getInt(offset);
1882 HBaseRpc.checkArrayLength(buf, kv_length);
1883 num_kv++;
1884 offset += kv_length + 4;
1885 }
1886 if (offset != length) {
1887 final int index = buf.readerIndex();
1888 badResponse("We wanted read " + (length - index)
1889 + " bytes but we read " + (offset - index)
1890 + " from " + buf + '=' + Bytes.pretty(buf));
1891 }
1892 return num_kv;
1893 }
1894
1895 /**
1896 * De-serializes an {@code hbase.client.Result} object.

Callers 2

convertResultMethod · 0.95
parseResultMethod · 0.95

Calls 5

ensureReadableMethod · 0.95
checkArrayLengthMethod · 0.95
badResponseMethod · 0.95
prettyMethod · 0.95
getIntMethod · 0.45

Tested by

no test coverage detected