Package com.couchbase.client.core.util
Class UnsignedLEB128
java.lang.Object
com.couchbase.client.core.util.UnsignedLEB128
Encodes and decodes the unsigned LEB128 (Little Endian Base 128) format.
See LEB128.
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
decode
(byte[] bytes) Given a byte array starting with an unsigned LEB128 value, returns the decoded form of that value.static byte[]
encode
(long value) Returns a byte array containing the unsigned LEB128 representation of the given value.static long
read
(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf buf) Reads an unsigned LEB128 value from the buffer.static int
skip
(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf buf) Advances the buffer's reader index past the unsigned LEB128 value at the reader index.static void
write
(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf buf, long value) Writes the unsigned LEB128 representation of the value to the buffer.
-
Method Details
-
read
public static long read(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf buf) Reads an unsigned LEB128 value from the buffer. If this methods throws an exception the reader index remains unchanged, otherwise the index advances past the value.- Returns:
- the decoded value
- Throws:
ArithmeticException
- if the decoded value is longer than 64 bits.IndexOutOfBoundsException
- if the buffer's readable bytes do not contain a complete value.
-
skip
public static int skip(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf buf) Advances the buffer's reader index past the unsigned LEB128 value at the reader index. If this method throws an exception, the reader index will be unchanged.- Returns:
- the number of bytes skipped.
- Throws:
IndexOutOfBoundsException
- if the buffer's readable bytes do not contain a complete value.
-
write
public static void write(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf buf, long value) Writes the unsigned LEB128 representation of the value to the buffer. -
encode
public static byte[] encode(long value) Returns a byte array containing the unsigned LEB128 representation of the given value. -
decode
public static long decode(byte[] bytes) Given a byte array starting with an unsigned LEB128 value, returns the decoded form of that value.- Throws:
ArithmeticException
- if the decoded value is larger than 64 bits.IndexOutOfBoundsException
- if the input does not contain a complete LEB128 value
-