Package com.couchbase.client.core.util
Class UnsignedLEB128
java.lang.Object
com.couchbase.client.core.util.UnsignedLEB128
public class UnsignedLEB128 extends Object
Encodes and decodes the unsigned LEB128 (Little Endian Base 128) format.
See https://en.wikipedia.org/wiki/LEB128
-
Method Summary
Modifier and Type Method Description static longdecode(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 longread(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf buf)Reads an unsigned LEB128 value from the buffer.static voidskip(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 voidwrite(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 void 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 methods throws an exception the reader index will be unchanged.- 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
-