use of com.couchbase.client.core.deps.io.netty.buffer.CompositeByteBuf in project couchbase-jvm-clients by couchbase.
the class SubdocMutateRequest method encode.
@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
ByteBuf key = null;
ByteBuf extras = null;
ByteBuf content = null;
ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType, preserveExpiry);
try {
if (createAsDeleted && !ctx.createAsDeleted()) {
// It is left purely as an additional safety measure.
throw new FeatureNotAvailableException("Cannot use createAsDeleted Sub-Document flag, as it is not supported by this version of the cluster");
}
key = encodedKeyWithCollection(alloc, ctx);
extras = alloc.buffer();
if (expiration != 0) {
extras.writeInt((int) expiration);
}
if (flags != 0) {
extras.writeByte(flags);
}
if (commands.size() == 1) {
content = commands.get(0).encode(alloc);
} else {
content = alloc.compositeBuffer(commands.size());
for (Command command : commands) {
ByteBuf commandBuffer = command.encode(alloc);
try {
((CompositeByteBuf) content).addComponent(commandBuffer);
content.writerIndex(content.writerIndex() + commandBuffer.readableBytes());
} catch (Exception ex) {
ReferenceCountUtil.release(commandBuffer);
throw ex;
}
}
}
return flexibleRequest(alloc, Opcode.SUBDOC_MULTI_MUTATE, noDatatype(), partition(), opaque, cas, flexibleExtras, extras, key, content);
} finally {
ReferenceCountUtil.release(key);
ReferenceCountUtil.release(extras);
ReferenceCountUtil.release(flexibleExtras);
ReferenceCountUtil.release(content);
}
}
use of com.couchbase.client.core.deps.io.netty.buffer.CompositeByteBuf in project couchbase-jvm-clients by couchbase.
the class SubdocGetRequest method encode.
@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
ByteBuf key = null;
ByteBuf extras = null;
ByteBuf body = null;
try {
if (!ctx.vattrEnabled()) {
// Do a check to see if all vattr commands meet a whitelist of vattrs.
for (Command c : commands) {
if (c.xattr() && (c.path.length() > 0 && c.path.charAt(0) == '$') && !(c.path.startsWith("$document") || c.path.startsWith("$XTOC"))) {
throw mapSubDocumentError(this, SubDocumentOpResponseStatus.XATTR_UNKNOWN_VATTR, c.path, c.originalIndex());
}
}
}
key = encodedKeyWithCollection(alloc, ctx);
if (flags != 0) {
extras = alloc.buffer(Byte.BYTES).writeByte(flags);
}
if (commands.size() == 1) {
// Note currently the only subdoc error response handled is ERR_SUBDOC_MULTI_PATH_FAILURE. Make sure to
// add the others if do the single lookup optimisation.
// Update: single subdoc optimization will not be supported. It adds just 3 bytes to the package size and gives
// minimal performance gains, in return for additional client complexity.
body = commands.get(0).encode(alloc);
} else {
body = alloc.compositeBuffer(commands.size());
for (Command command : commands) {
ByteBuf commandBuffer = command.encode(alloc);
try {
((CompositeByteBuf) body).addComponent(commandBuffer);
body.writerIndex(body.writerIndex() + commandBuffer.readableBytes());
} catch (Exception ex) {
ReferenceCountUtil.release(commandBuffer);
throw ex;
}
}
}
return request(alloc, MemcacheProtocol.Opcode.SUBDOC_MULTI_LOOKUP, noDatatype(), partition(), opaque, noCas(), extras == null ? noExtras() : extras, key, body);
} finally {
ReferenceCountUtil.release(key);
ReferenceCountUtil.release(body);
ReferenceCountUtil.release(extras);
}
}
Aggregations