use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class CompressionTest method doesNotCompressIfTooShortUpsert.
@Test
void doesNotCompressIfTooShortUpsert() {
UpsertRequest request = new UpsertRequest(key, shortContent, expiry, preserveExpiry, flags, timeout, coreContext, cid, retryStrategy, Optional.empty(), null);
ByteBuf encoded = request.encode(allocator, 0, ctx(true));
assertEquals(0, datatype(encoded));
assertEquals(Unpooled.wrappedBuffer(shortContent), body(encoded).get());
ReferenceCountUtil.release(encoded);
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class GetCollectionIdRequest method encode.
@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
ByteBuf body = null;
try {
CollectionIdentifier ci = collectionIdentifier();
if (!ci.collection().isPresent()) {
throw InvalidArgumentException.fromMessage("A collection name needs to be present");
}
// Note that the scope can be empty, according to spec it is the same as _default scope
body = Unpooled.copiedBuffer(ci.scope().orElse("") + "." + ci.collection().get(), UTF_8);
return request(alloc, MemcacheProtocol.Opcode.COLLECTIONS_GET_CID, noDatatype(), noPartition(), opaque, noCas(), noExtras(), noKey(), body);
} finally {
ReferenceCountUtil.release(body);
}
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class GetCollectionManifestRequest method decode.
@Override
public GetCollectionManifestResponse decode(final ByteBuf response, final KeyValueChannelContext ctx) {
ResponseStatus status = MemcacheProtocol.decodeStatus(response);
Optional<String> manifest = Optional.empty();
if (status.success()) {
manifest = Optional.of(body(response).map(ByteBufUtil::getBytes).orElse(Bytes.EMPTY_BYTE_ARRAY)).map(b -> new String(b, StandardCharsets.UTF_8));
}
return new GetCollectionManifestResponse(status, manifest);
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class IncrementRequest method encode.
@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
ByteBuf key = null;
ByteBuf extras = null;
ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType);
try {
key = encodedKeyWithCollection(alloc, ctx);
extras = alloc.buffer((Long.BYTES * 2) + Integer.BYTES);
extras.writeLong(delta);
if (initial.isPresent()) {
extras.writeLong(initial.get());
extras.writeInt((int) expiry);
} else {
// no initial present, will lead to doc not found
extras.writeLong(0);
extras.writeInt(COUNTER_NOT_EXISTS_EXPIRY);
}
return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.INCREMENT, noDatatype(), partition(), opaque, noCas(), flexibleExtras, extras, key, noBody());
} finally {
ReferenceCountUtil.release(key);
ReferenceCountUtil.release(extras);
ReferenceCountUtil.release(flexibleExtras);
}
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf 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);
}
}
Aggregations