package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.UnstableApi;
@UnstableApi
public class DefaultFullBinaryMemcacheResponse extends DefaultBinaryMemcacheResponse
implements FullBinaryMemcacheResponse {
private final ByteBuf content;
public DefaultFullBinaryMemcacheResponse(ByteBuf key, ByteBuf extras) {
this(key, extras, Unpooled.buffer(0));
}
public DefaultFullBinaryMemcacheResponse(ByteBuf key, ByteBuf extras,
ByteBuf content) {
super(key, extras);
if (content == null) {
throw new NullPointerException("Supplied content is null.");
}
this.content = content;
setTotalBodyLength(keyLength() + extrasLength() + content.readableBytes());
}
@Override
public ByteBuf content() {
return content;
}
@Override
public FullBinaryMemcacheResponse retain() {
super.retain();
return this;
}
@Override
public FullBinaryMemcacheResponse retain(int increment) {
super.retain(increment);
return this;
}
@Override
public FullBinaryMemcacheResponse touch() {
super.touch();
return this;
}
@Override
public FullBinaryMemcacheResponse touch(Object hint) {
super.touch(hint);
content.touch(hint);
return this;
}
@Override
protected void deallocate() {
super.deallocate();
content.release();
}
@Override
public FullBinaryMemcacheResponse copy() {
ByteBuf key = key();
if (key != null) {
key = key.copy();
}
ByteBuf extras = extras();
if (extras != null) {
extras = extras.copy();
}
return new DefaultFullBinaryMemcacheResponse(key, extras, content().copy());
}
@Override
public FullBinaryMemcacheResponse duplicate() {
ByteBuf key = key();
if (key != null) {
key = key.duplicate();
}
ByteBuf extras = extras();
if (extras != null) {
extras = extras.duplicate();
}
return new DefaultFullBinaryMemcacheResponse(key, extras, content().duplicate());
}
@Override
public FullBinaryMemcacheResponse retainedDuplicate() {
return replace(content().retainedDuplicate());
}
@Override
public FullBinaryMemcacheResponse replace(ByteBuf content) {
ByteBuf key = key();
if (key != null) {
key = key.retainedDuplicate();
}
ByteBuf extras = extras();
if (extras != null) {
extras = extras.retainedDuplicate();
}
return new DefaultFullBinaryMemcacheResponse(key, extras, content);
}
}