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.Magic |
static class |
MemcacheProtocol.Opcode
Contains all known/used kv protocol opcodes.
|
static class |
MemcacheProtocol.Status |
Modifier and Type | Field and Description |
---|---|
static byte |
FRAMING_EXTRAS_TRACING
The byte used to signal this is a tracing extras frame.
|
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 |
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 body of the message if available.
|
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 Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> |
flexibleExtras(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message) |
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 com.couchbase.client.core.deps.io.netty.buffer.ByteBuf |
flexibleSyncReplication(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc,
DurabilityLevel type,
Duration timeout,
CoreContext ctx)
Helper method to create the flexible extras for sync replication.
|
static CouchbaseException |
mapSubDocumentError(KeyValueRequest<?> request,
SubDocumentOpResponseStatus status,
String path,
int index)
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 |
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 long |
parseServerDurationFromResponse(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf response)
Parses the server duration from the frame.
|
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 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 short SYNC_REPLICATION_TIMEOUT_FLOOR_MS
public static final byte FRAMING_EXTRAS_TRACING
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 boolean successful(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf message)
message
- the memcache message to extract 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 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)
message
- the message of the body or empty if none found.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 Optional<com.couchbase.client.core.deps.io.netty.buffer.ByteBuf> 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 flexibleSyncReplication(com.couchbase.client.core.deps.io.netty.buffer.ByteBufAllocator alloc, DurabilityLevel type, Duration timeout, CoreContext ctx)
Note that this method writes a short value from an integer deadline. The netty method will make sure to only look at the lower 16 bits - this allows us to write an unsigned short!
alloc
- the allocator to use.type
- the type of sync replication.timeout
- the timeout to use.ctx
- the core context to use.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)
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)
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 © 2020 Couchbase, Inc.. All rights reserved.