package io.netty.handler.codec.http2;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi;
@UnstableApi
public final class DefaultHttp2GoAwayFrame extends DefaultByteBufHolder implements Http2GoAwayFrame {
private final long errorCode;
private final int lastStreamId;
private int extraStreamIds;
public DefaultHttp2GoAwayFrame(Http2Error error) {
this(error.code());
}
public DefaultHttp2GoAwayFrame(long errorCode) {
this(errorCode, Unpooled.EMPTY_BUFFER);
}
public DefaultHttp2GoAwayFrame(Http2Error error, ByteBuf content) {
this(error.code(), content);
}
public DefaultHttp2GoAwayFrame(long errorCode, ByteBuf content) {
this(-1, errorCode, content);
}
DefaultHttp2GoAwayFrame(int lastStreamId, long errorCode, ByteBuf content) {
super(content);
this.errorCode = errorCode;
this.lastStreamId = lastStreamId;
}
@Override
public String name() {
return "GOAWAY";
}
@Override
public long errorCode() {
return errorCode;
}
@Override
public int extraStreamIds() {
return extraStreamIds;
}
@Override
public Http2GoAwayFrame setExtraStreamIds(int extraStreamIds) {
if (extraStreamIds < 0) {
throw new IllegalArgumentException("extraStreamIds must be non-negative");
}
this.extraStreamIds = extraStreamIds;
return this;
}
@Override
public int lastStreamId() {
return lastStreamId;
}
@Override
public Http2GoAwayFrame copy() {
return new DefaultHttp2GoAwayFrame(lastStreamId, errorCode, content().copy());
}
@Override
public Http2GoAwayFrame duplicate() {
return (Http2GoAwayFrame) super.duplicate();
}
@Override
public Http2GoAwayFrame retainedDuplicate() {
return (Http2GoAwayFrame) super.retainedDuplicate();
}
@Override
public Http2GoAwayFrame replace(ByteBuf content) {
return new DefaultHttp2GoAwayFrame(errorCode, content).setExtraStreamIds(extraStreamIds);
}
@Override
public Http2GoAwayFrame retain() {
super.retain();
return this;
}
@Override
public Http2GoAwayFrame retain(int increment) {
super.retain(increment);
return this;
}
@Override
public Http2GoAwayFrame touch() {
super.touch();
return this;
}
@Override
public Http2GoAwayFrame touch(Object hint) {
super.touch(hint);
return this;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof DefaultHttp2GoAwayFrame)) {
return false;
}
DefaultHttp2GoAwayFrame other = (DefaultHttp2GoAwayFrame) o;
return errorCode == other.errorCode && extraStreamIds == other.extraStreamIds && super.equals(other);
}
@Override
public int hashCode() {
int hash = super.hashCode();
hash = hash * 31 + (int) (errorCode ^ (errorCode >>> 32));
hash = hash * 31 + extraStreamIds;
return hash;
}
@Override
public String toString() {
return StringUtil.simpleClassName(this) + "(errorCode=" + errorCode + ", content=" + content()
+ ", extraStreamIds=" + extraStreamIds + ", lastStreamId=" + lastStreamId + ')';
}
}