Class UnsignedLEB128
java.lang.Object
com.couchbase.client.dcp.core.utils.UnsignedLEB128
Encodes and decodes the unsigned LEB128 (Little Endian Base 128) format.
See https://en.wikipedia.org/wiki/LEB128
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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(io.netty.buffer.ByteBuf buf) Reads an unsigned LEB128 value from the buffer.static voidskip(io.netty.buffer.ByteBuf buf) Advances the buffer's reader index past the unsigned LEB128 value at the reader index.static voidwrite(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(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(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(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
-