public enum MemcacheProtocol extends Enum<MemcacheProtocol>
MemcacheProtocol class holds static helpers that deal with the encoding
and decoding as well as access of the memcache binary protocol.| Modifier and Type | Class and Description |
|---|---|
static class |
MemcacheProtocol.Datatype |
static class |
MemcacheProtocol.FlexibleExtras |
static class |
MemcacheProtocol.Magic |
static class |
MemcacheProtocol.Opcode
Contains all known/used kv protocol opcodes.
|
static class |
MemcacheProtocol.ServerPushOpcode |
static class |
MemcacheProtocol.Status |
| Modifier and Type | Field and Description |
|---|---|
static byte |
FRAMING_EXTRAS_READ_UNITS_USED
Signals that read/write units have been returned.
|
static byte |
FRAMING_EXTRAS_TRACING
The byte used to signal this is a tracing extras frame.
|
static byte |
FRAMING_EXTRAS_WRITE_UNITS_USED |
static byte |
PRESERVE_TTL_FLEXIBLE_IDENT
Flag which indicates that this flexible extra frame is for preserve ttl.
|
static byte |
SYNC_REPLICATION_FLEXIBLE_IDENT
Flag which indicates that this flexible extra frame is for syc replication.
|
static short |
SYNC_REPLICATION_TIMEOUT_FLOOR_MS
Minimum sync durability timeout that can be set and which will override any lower
user-provided value.
|
static int |
UNITS_NOT_PRESENT
The server did not return units.
|
static int |
UNSIGNED_SHORT_MAX
Holds the max value a unsigned short can represent.
|
| Modifier and Type | Method and Description |
|---|---|
static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> |
body(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Returns the decompressed body of the message, or an empty Optional
if the body length is zero.
|
static byte[] |
bodyAsBytes(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Returns the decompressed body of this message as a byte array.
|
static String |
bodyAsString(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Returns the decompressed body of this message as a UTF-8 string.
|
static long |
cas(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Helper method to extract the cas from a message.
|
static byte |
datatype(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Helper method to return the datatype from a request or response.
|
static ResponseStatus |
decodeStatus(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Decodes and converts the status from a message.
|
static ResponseStatus |
decodeStatus(short status)
Converts the KeyValue protocol status into its generic format.
|
static SubDocumentOpResponseStatus |
decodeSubDocumentStatus(short status)
Converts a KeyValue protocol status into its generic format.
|
static Optional<MutationToken> |
extractToken(boolean enabled,
short partition,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf msg,
String bucket)
Tries to extract the mutation token if the surround msg and environment allows for it.
|
static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> |
extras(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
static int |
extrasAsInt(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message,
int offset,
int defaultValue)
Tries to extract the extras as an integer value and if not possible returns the default value.
|
static byte |
extrasLength(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
static byte |
flexExtrasLength(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
static MemcacheProtocol.FlexibleExtras |
flexibleExtras(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Retrieve the flexible extras from the packet.
|
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
flexibleRequest(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
MemcacheProtocol.Opcode opcode,
byte datatype,
short partition,
int opaque,
long cas,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf framingExtras,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
Create a flexible memcached protocol request with all fields necessary.
|
static boolean |
isFlexible(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
static boolean |
isRequest(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> |
key(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
static short |
keyLength(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
static byte |
magic(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
static CouchbaseException |
mapSubDocumentError(KeyValueRequest<?> request,
SubDocumentOpResponseStatus status,
String path,
int index,
MemcacheProtocol.FlexibleExtras flexibleExtras)
For any response that can be returned by a SubDocument command - path, document, or execution-based - map it to
an appropriate SubDocumentException.
|
static String |
messageToString(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Helper method during development and debugging to dump the raw message as a
verbose string.
|
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
mutationFlexibleExtras(KeyValueRequest<?> request,
KeyValueChannelContext ctx,
com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
Optional<DurabilityLevel> durabilityLevel) |
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
mutationFlexibleExtras(KeyValueRequest<?> request,
KeyValueChannelContext ctx,
com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
Optional<DurabilityLevel> durabilityLevel,
boolean preserveExpiry) |
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
noBody()
Helper to express no body is used for this message.
|
static long |
noCas()
Helper to express no cas is used for this message.
|
static byte |
noDatatype()
Helper to express no datatype is used for this message.
|
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
noExtras()
Helper to express no extras are used for this message.
|
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
noFramingExtras()
Helper to express no framing extras are used for this message.
|
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
noKey()
Helper to express no key is used for this message.
|
static int |
noOpaque()
Helper to express no opaque is used for this message.
|
static short |
noPartition()
Helper to express no partition is used for this message.
|
static int |
opaque(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Helper method to return the opaque value for the given request or response.
|
static byte |
opcode(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Helper method to return the opcode for the given request or response.
|
static long |
parseServerDurationFromResponse(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf response)
Parses the server duration from the frame.
|
static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> |
rawBody(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Returns the raw (possibly compressed) content of the message,
or an empty Optional if the raw content length is zero.
|
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
request(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
MemcacheProtocol.Opcode opcode,
byte datatype,
short partition,
int opaque,
long cas,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
Create a regular, non-flexible memcached protocol request with all fields necessary.
|
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
response(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
MemcacheProtocol.Opcode opcode,
byte datatype,
short status,
int opaque,
long cas,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
Create a regular, non-flexible memcached protocol response with all fields necessary.
|
static short |
status(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Returns the status of that response.
|
static boolean |
successful(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
Helper method to check if the given response has a successful status.
|
static int |
totalBodyLength(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
tryCompression(byte[] input,
double minRatio)
Try to compress the input, but if it is below the min ratio then it will return null.
|
static byte[] |
tryDecompression(byte[] input,
byte datatype)
Try to decompress the input if the datatype has the snappy flag enabled.
|
static MemcacheProtocol |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static MemcacheProtocol[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final int UNSIGNED_SHORT_MAX
public static final byte SYNC_REPLICATION_FLEXIBLE_IDENT
public static final byte PRESERVE_TTL_FLEXIBLE_IDENT
public static final short SYNC_REPLICATION_TIMEOUT_FLOOR_MS
public static final byte FRAMING_EXTRAS_TRACING
public static final byte FRAMING_EXTRAS_READ_UNITS_USED
public static final byte FRAMING_EXTRAS_WRITE_UNITS_USED
public static final int UNITS_NOT_PRESENT
public static MemcacheProtocol[] values()
for (MemcacheProtocol c : MemcacheProtocol.values()) System.out.println(c);
public static MemcacheProtocol valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf flexibleRequest(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
MemcacheProtocol.Opcode opcode,
byte datatype,
short partition,
int opaque,
long cas,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf framingExtras,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf request(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
MemcacheProtocol.Opcode opcode,
byte datatype,
short partition,
int opaque,
long cas,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf response(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
MemcacheProtocol.Opcode opcode,
byte datatype,
short status,
int opaque,
long cas,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf extras,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf key,
com.couchbase.client.core.deps.io.netty.buffer.ByteBuf body)
This method is mostly used for testing purposes.
public static short status(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
message - the memcache message to extract from.public static short keyLength(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static boolean isFlexible(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static byte flexExtrasLength(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static byte extrasLength(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static byte magic(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static boolean isRequest(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static int totalBodyLength(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static boolean successful(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
message - the memcache message to extract from.public static byte opcode(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
message - the message to get the opcode from.public static byte datatype(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
message - the message to get the datatype from.public static int opaque(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
message - the message to get the opaque from.public static long cas(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
message - the message to extract the cas from.public static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> body(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> rawBody(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> key(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static byte[] bodyAsBytes(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static String bodyAsString(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> extras(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static int extrasAsInt(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message,
int offset,
int defaultValue)
Note that while this method looks a bit too specific, in profiling it has been shown that extras extraction on the get command otherwise needs a buffer slice and has to box the integer due to the optional. So this avoids two small performance hits and it can be used on the hot code path.
message - the message to extract from.offset - the offset in the extras from where the int should be loaded.defaultValue - the default value to use.@Nullable public static MemcacheProtocol.FlexibleExtras flexibleExtras(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noKey()
public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noExtras()
public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noFramingExtras()
public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf noBody()
public static byte noDatatype()
public static short noPartition()
public static int noOpaque()
public static long noCas()
public static ResponseStatus decodeStatus(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
This is a convenience method usually used in decoders.
message - the message to extract from.public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf mutationFlexibleExtras(KeyValueRequest<?> request, KeyValueChannelContext ctx, com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc, Optional<DurabilityLevel> durabilityLevel)
public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf mutationFlexibleExtras(KeyValueRequest<?> request, KeyValueChannelContext ctx, com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc, Optional<DurabilityLevel> durabilityLevel, boolean preserveExpiry)
public static long parseServerDurationFromResponse(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf response)
Math.round(float) function and has microsecond
precision.response - the response to extract it from.public static ResponseStatus decodeStatus(short status)
Note that only the most likely statuses are covered here, the rest is in decodeOtherStatus(short) so
that the JIT can inline the method efficiently.
status - the protocol status.public static SubDocumentOpResponseStatus decodeSubDocumentStatus(short status)
status - the protocol status.public static CouchbaseException mapSubDocumentError(KeyValueRequest<?> request, SubDocumentOpResponseStatus status, String path, int index, @Nullable MemcacheProtocol.FlexibleExtras flexibleExtras)
public static com.couchbase.client.core.deps.io.netty.buffer.ByteBuf tryCompression(byte[] input,
double minRatio)
input - the input array.minRatio - the minimum ratio to accept and return the buffer.ByteBuf if compressed, or null if below the min ratio.public static byte[] tryDecompression(byte[] input,
byte datatype)
If datatype does not indicate snappy enabled, then the input is returned as presented.
input - the input byte array.datatype - the datatype for the response.public static String messageToString(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
public static Optional<MutationToken> extractToken(boolean enabled, short partition, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf msg, String bucket)
enabled - if enabledpartition - the partition idmsg - the msg to checkbucket - the bucket for this msgCopyright © 2024 Couchbase, Inc.. All rights reserved.