Example usage for io.netty.handler.codec.memcache.binary FullBinaryMemcacheRequest setTotalBodyLength

List of usage examples for io.netty.handler.codec.memcache.binary FullBinaryMemcacheRequest setTotalBodyLength

Introduction

In this page you can find the example usage for io.netty.handler.codec.memcache.binary FullBinaryMemcacheRequest setTotalBodyLength.

Prototype

BinaryMemcacheMessage setTotalBodyLength(int totalBodyLength);

Source Link

Document

Sets the total body length.

Usage

From source file:com.couchbase.client.core.endpoint.binary.BinaryCodec.java

License:Open Source License

/**
 * Creates the actual protocol level request for an incoming upsert request.
 *
 * @param request the incoming upsert request.
 * @param ctx the channel handler context for buffer allocations.
 * @return the built protocol request./* w w  w. j a v a  2s .co m*/
 */
private BinaryMemcacheRequest handleUpsertRequest(final UpsertRequest request,
        final ChannelHandlerContext ctx) {
    ByteBuf extras = ctx.alloc().buffer(8);
    extras.writeInt(request.flags());
    extras.writeInt(request.expiration());

    FullBinaryMemcacheRequest msg = new DefaultFullBinaryMemcacheRequest(request.key(), extras,
            request.content());

    msg.setOpcode(BinaryMemcacheOpcodes.SET);
    msg.setKeyLength((short) request.key().length());
    msg.setTotalBodyLength(
            (short) request.key().length() + request.content().readableBytes() + extras.readableBytes());
    msg.setReserved(request.partition());
    msg.setExtrasLength((byte) extras.readableBytes());
    return msg;
}

From source file:com.couchbase.client.core.endpoint.binary.BinaryCodec.java

License:Open Source License

/**
 * Creates the actual protocol level request for an incoming replacer request.
 *
 * @param request the incoming replace request.
 * @param ctx the channel handler context for buffer allocations.
 * @return the built protocol request./* w  ww.  j  a  v a2s  .co m*/
 */
private BinaryMemcacheRequest handleReplaceRequest(final ReplaceRequest request,
        final ChannelHandlerContext ctx) {
    ByteBuf extras = ctx.alloc().buffer(8);
    extras.writeInt(request.flags());
    extras.writeInt(request.expiration());

    FullBinaryMemcacheRequest msg = new DefaultFullBinaryMemcacheRequest(request.key(), extras,
            request.content());

    msg.setOpcode(BinaryMemcacheOpcodes.REPLACE);
    msg.setCAS(request.cas());
    msg.setKeyLength((short) request.key().length());
    msg.setTotalBodyLength(
            (short) request.key().length() + request.content().readableBytes() + extras.readableBytes());
    msg.setReserved(request.partition());
    msg.setExtrasLength((byte) extras.readableBytes());
    return msg;
}

From source file:com.couchbase.client.core.endpoint.binary.BinaryCodec.java

License:Open Source License

/**
 * Creates the actual protocol level request for an incoming insert request.
 *
 * @param request the incoming insert request.
 * @param ctx the channel handler context for buffer allocations.
 * @return the built protocol request.//from ww w . j  av  a2s .c o m
 */
private BinaryMemcacheRequest handleInsertRequest(final InsertRequest request,
        final ChannelHandlerContext ctx) {
    ByteBuf extras = ctx.alloc().buffer(8);
    extras.writeInt(request.flags());
    extras.writeInt(request.expiration());

    FullBinaryMemcacheRequest msg = new DefaultFullBinaryMemcacheRequest(request.key(), extras,
            request.content());

    msg.setOpcode(BinaryMemcacheOpcodes.ADD);
    msg.setKeyLength((short) request.key().length());
    msg.setTotalBodyLength(
            (short) request.key().length() + request.content().readableBytes() + extras.readableBytes());
    msg.setReserved(request.partition());
    msg.setExtrasLength((byte) extras.readableBytes());
    return msg;
}