package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.memcache.AbstractMemcacheObject;
import io.netty.util.internal.UnstableApi;
@UnstableApi
public abstract class AbstractBinaryMemcacheMessage
extends AbstractMemcacheObject
implements BinaryMemcacheMessage {
private ByteBuf key;
private ByteBuf extras;
private byte magic;
private byte opcode;
private short keyLength;
private byte extrasLength;
private byte dataType;
private int totalBodyLength;
private int opaque;
private long cas;
protected AbstractBinaryMemcacheMessage(ByteBuf key, ByteBuf extras) {
this.key = key;
keyLength = key == null ? 0 : (short) key.readableBytes();
this.extras = extras;
extrasLength = extras == null ? 0 : (byte) extras.readableBytes();
totalBodyLength = keyLength + extrasLength;
}
@Override
public ByteBuf key() {
return key;
}
@Override
public ByteBuf extras() {
return extras;
}
@Override
public BinaryMemcacheMessage setKey(ByteBuf key) {
if (this.key != null) {
this.key.release();
}
this.key = key;
short oldKeyLength = keyLength;
keyLength = key == null ? 0 : (short) key.readableBytes();
totalBodyLength = totalBodyLength + keyLength - oldKeyLength;
return this;
}
@Override
public BinaryMemcacheMessage setExtras(ByteBuf extras) {
if (this.extras != null) {
this.extras.release();
}
this.extras = extras;
short oldExtrasLength = extrasLength;
extrasLength = extras == null ? 0 : (byte) extras.readableBytes();
totalBodyLength = totalBodyLength + extrasLength - oldExtrasLength;
return this;
}
@Override
public byte magic() {
return magic;
}
@Override
public BinaryMemcacheMessage setMagic(byte magic) {
this.magic = magic;
return this;
}
@Override
public long cas() {
return cas;
}
@Override
public BinaryMemcacheMessage setCas(long cas) {
this.cas = cas;
return this;
}
@Override
public int opaque() {
return opaque;
}
@Override
public BinaryMemcacheMessage setOpaque(int opaque) {
this.opaque = opaque;
return this;
}
@Override
public int totalBodyLength() {
return totalBodyLength;
}
@Override
public BinaryMemcacheMessage setTotalBodyLength(int totalBodyLength) {
this.totalBodyLength = totalBodyLength;
return this;
}
@Override
public byte dataType() {
return dataType;
}
@Override
public BinaryMemcacheMessage setDataType(byte dataType) {
this.dataType = dataType;
return this;
}
@Override
public byte extrasLength() {
return extrasLength;
}
BinaryMemcacheMessage setExtrasLength(byte extrasLength) {
this.extrasLength = extrasLength;
return this;
}
@Override
public short keyLength() {
return keyLength;
}
BinaryMemcacheMessage setKeyLength(short keyLength) {
this.keyLength = keyLength;
return this;
}
@Override
public byte opcode() {
return opcode;
}
@Override
public BinaryMemcacheMessage setOpcode(byte opcode) {
this.opcode = opcode;
return this;
}
@Override
public BinaryMemcacheMessage retain() {
super.retain();
return this;
}
@Override
public BinaryMemcacheMessage retain(int increment) {
super.retain(increment);
return this;
}
@Override
protected void deallocate() {
if (key != null) {
key.release();
}
if (extras != null) {
extras.release();
}
}
@Override
public BinaryMemcacheMessage touch() {
super.touch();
return this;
}
@Override
public BinaryMemcacheMessage touch(Object hint) {
if (key != null) {
key.touch(hint);
}
if (extras != null) {
extras.touch(hint);
}
return this;
}
}