com.webpieces.http2parser.impl.RstStreamMarshaller Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http2-parser Show documentation
Show all versions of http2-parser Show documentation
A re-usable asynchronous http2 parser
package com.webpieces.http2parser.impl;
import java.nio.ByteBuffer;
import java.util.Optional;
import org.webpieces.data.api.BufferPool;
import org.webpieces.data.api.DataWrapper;
import org.webpieces.data.api.DataWrapperGenerator;
import com.webpieces.http2parser.api.FrameMarshaller;
import com.webpieces.http2parser.api.dto.Http2ErrorCode;
import com.webpieces.http2parser.api.dto.Http2Frame;
import com.webpieces.http2parser.api.dto.Http2RstStream;
public class RstStreamMarshaller extends FrameMarshallerImpl implements FrameMarshaller {
RstStreamMarshaller(BufferPool bufferPool, DataWrapperGenerator dataGen) {
super(bufferPool, dataGen);
}
@Override
public byte marshalFlags(Http2Frame frame) {
return 0x0;
}
@Override
public DataWrapper marshalPayload(Http2Frame frame) {
Http2RstStream castFrame = (Http2RstStream) frame;
ByteBuffer payload = bufferPool.nextBuffer(4);
payload.putInt(castFrame.getErrorCode().getCode());
payload.flip();
return dataGen.wrapByteBuffer(payload);
}
@Override
public void unmarshalFlagsAndPayload(Http2Frame frame, byte flags, Optional maybePayload) {
Http2RstStream castFrame = (Http2RstStream) frame;
maybePayload.ifPresent(payload -> {
ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(payload);
castFrame.setErrorCode(Http2ErrorCode.fromInteger(payloadByteBuffer.getInt()));
bufferPool.releaseBuffer(payloadByteBuffer);
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy