use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class ObserveViaCasRequest method encode.
@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
ByteBuf key = null;
ByteBuf content = null;
try {
key = encodedKeyWithCollection(alloc, ctx);
int keyLength = key.readableBytes();
content = alloc.buffer(keyLength + (Short.BYTES * 2));
content.writeShort(partition());
content.writeShort(keyLength);
content.writeBytes(key);
return request(alloc, MemcacheProtocol.Opcode.OBSERVE_CAS, noDatatype(), partition(), opaque, noCas(), noExtras(), noKey(), content);
} finally {
ReferenceCountUtil.release(key);
ReferenceCountUtil.release(content);
}
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class ObserveViaSeqnoRequest method decode.
@Override
public ObserveViaSeqnoResponse decode(final ByteBuf response, final KeyValueChannelContext ctx) {
ResponseStatus status = decodeStatus(response);
if (status.success()) {
ByteBuf content = body(response).get();
byte format = content.readByte();
short vbucketId = content.readShort();
long vbucketUUID = content.readLong();
long lastPersistedSeqno = content.readLong();
long currentSeqno = content.readLong();
switch(format) {
case 0:
return new ObserveViaSeqnoResponse(status, active, vbucketId, vbucketUUID, lastPersistedSeqno, currentSeqno, Optional.empty(), Optional.empty());
case 1:
return new ObserveViaSeqnoResponse(status, active, vbucketId, vbucketUUID, lastPersistedSeqno, currentSeqno, Optional.of(content.readLong()), Optional.of(content.readLong()));
default:
throw new IllegalStateException("Unsupported format 0x" + Integer.toHexString(format));
}
} else {
return new ObserveViaSeqnoResponse(status, active, (short) 0, 0L, 0L, 0L, Optional.empty(), Optional.empty());
}
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class RemoveRequest method encode.
@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
ByteBuf key = null;
ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType);
try {
key = encodedKeyWithCollection(alloc, ctx);
return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.DELETE, noDatatype(), partition(), opaque, cas, flexibleExtras, noExtras(), key, noBody());
} finally {
ReferenceCountUtil.release(key);
ReferenceCountUtil.release(flexibleExtras);
}
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class SearchRequest method encode.
@Override
public FullHttpRequest encode() {
ByteBuf c = Unpooled.wrappedBuffer(content);
String uri = "/api/index/" + indexName + "/query";
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri, c);
request.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON);
request.headers().set(HttpHeaderNames.CONTENT_LENGTH, c.readableBytes());
authenticator.authHttpRequest(serviceType(), request);
return request;
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class ViewRequest method encode.
@Override
public FullHttpRequest encode() {
StringBuilder path = new StringBuilder();
path.append("/").append(bucket).append("/_design/");
path.append(development ? "dev_" + design : design);
path.append("/_view/");
path.append(view);
path.append("?").append(query);
ByteBuf content = keysJson.isPresent() ? Unpooled.copiedBuffer(keysJson.get()) : Unpooled.EMPTY_BUFFER;
HttpMethod method = keysJson.isPresent() ? HttpMethod.POST : HttpMethod.GET;
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, path.toString(), content);
request.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON).set(HttpHeaderNames.CONTENT_LENGTH, content.readableBytes()).set(HttpHeaderNames.USER_AGENT, context().environment().userAgent().formattedLong());
authenticator.authHttpRequest(serviceType(), request);
return request;
}
Aggregations