use of com.firenio.buffer.ByteBuf in project baseio by generallycloud.
the class Http2Codec method encode.
@Override
public ByteBuf encode(Channel ch, Frame frame) {
Http2Frame f = (Http2Frame) frame;
Http2FrameType frameType = f.getHttp2FrameType();
byte[] payload = null;
switch(frameType) {
case FRAME_TYPE_CONTINUATION:
break;
case FRAME_TYPE_DATA:
break;
case FRAME_TYPE_GOAWAY:
break;
case FRAME_TYPE_HEADERS:
Http2HeadersFrame hf = (Http2HeadersFrame) f;
break;
case FRAME_TYPE_PING:
break;
case FRAME_TYPE_PRIORITY:
break;
case FRAME_TYPE_PUSH_PROMISE:
break;
case FRAME_TYPE_RST_STREAM:
break;
case FRAME_TYPE_SETTINGS:
Http2SettingsFrame sf = (Http2SettingsFrame) f;
long[] settings = sf.getSettings();
payload = new byte[6 * 6];
for (int i = 0; i < 6; i++) {
int realI = i + 1;
int offset = i * 6;
ByteUtil.putShort(payload, (short) realI, offset);
ByteUtil.putInt(payload, (int) settings[realI], offset + 2);
}
break;
case FRAME_TYPE_WINDOW_UPDATE:
break;
default:
break;
}
int length = payload.length;
ByteBuf buf = ch.alloc().allocate(length + PROTOCOL_HEADER);
byte b2 = (byte) ((length & 0xff));
byte b1 = (byte) ((length >> 8 * 1) & 0xff);
byte b0 = (byte) ((length >> 8 * 2) & 0xff);
byte b3 = frameType.getByteValue();
buf.writeByte(b0);
buf.writeByte(b1);
buf.writeByte(b2);
buf.writeByte(b3);
buf.writeByte((byte) 0);
buf.writeInt(f.getStreamIdentifier());
buf.writeBytes(payload);
return buf;
}
use of com.firenio.buffer.ByteBuf in project baseio by generallycloud.
the class TestMask method main.
public static void main(String[] args) {
ByteBuf buf = ByteBuf.wrap("hello word!".getBytes());
byte mask = (byte) buf.readableBytes();
mask(buf, mask);
System.out.println(new String(buf.readBytes()));
buf.readIndex(0);
mask(buf, mask);
System.out.println(new String(buf.readBytes()));
}
use of com.firenio.buffer.ByteBuf in project baseio by generallycloud.
the class Lz4CompressedInputStream method read.
@Override
public int read(byte[] b, int off, int len) throws IOException {
ByteBuf buf = this.buf;
byte[] readBuffer = buf.array();
int limit = buf.writeIndex();
int offset = buf.readIndex();
if (buf.readableBytes() <= 4) {
if (!hasRemaining) {
return -1;
}
read(buf);
return read(b, off, len);
}
int _len = ByteUtil.getInt(readBuffer, offset);
offset += 4;
if (limit - offset < _len) {
if (!hasRemaining) {
return -1;
}
read(buf);
return read(b, off, len);
}
buf.readIndex(offset + _len);
return Lz4RawDecompressor.decompress(readBuffer, offset, _len, b, off, len);
}
Aggregations