List of usage examples for io.netty.buffer ByteBuf writeByte
public abstract ByteBuf writeByte(int value);
From source file:com.neoba.messages.PingPongMessage.java
@Override public ByteBuf result() { ByteBuf reply = buffer(6); reply.writeByte(Constants.VERSION); reply.writeByte(Constants.PINGPONG); reply.writeInt(Constants.W_PING);/* www . ja va2s.co m*/ return reply; }
From source file:com.neoba.messages.ProtocolExpiredMessage.java
@Override public ByteBuf result() { ByteBuf reply = buffer(6); reply.writeByte(Constants.VERSION); reply.writeByte(type);/*from w w w .j a v a 2 s . c om*/ reply.writeInt(Constants.W_ERR_PROTOCOL_EXPIRED); return reply; }
From source file:com.neoba.messages.UserCreateMessage.java
@Override public ByteBuf result() { ByteBuf reply = buffer(6); reply.writeByte(Constants.VERSION); reply.writeByte(Constants.USER_CREATE); if (!isnametaken) reply.writeInt(Constants.W_SUCCESS); else//from www. j av a 2 s. c o m reply.writeInt(Constants.W_ERR_DUP_USERNAME); return reply; }
From source file:com.neoba.messages.UserLoginMessage.java
@Override public ByteBuf result() { ByteBuf reply; if (response == Constants.W_SUCCESS) { reply = buffer(6 + 16);// ww w .j a v a 2s . co m } else { reply = buffer(6); } reply.writeByte(Constants.VERSION); reply.writeByte(Constants.USER_LOGIN); reply.writeInt(response); if (response == Constants.W_SUCCESS) { reply.writeLong(sessid.getLeastSignificantBits()); reply.writeLong(sessid.getMostSignificantBits()); } return reply; }
From source file:com.neoba.messages.UserLogoutMessage.java
public ByteBuf result() { ByteBuf reply = buffer(6); reply.writeByte(Constants.VERSION); reply.writeByte(Constants.LOGOUT);/*from www .j ava2s . com*/ if (session_not_found) { reply.writeInt(Constants.W_ERR_SESSION_NOT_FOUND); } else { reply.writeInt(Constants.W_SUCCESS); } return reply; }
From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyBackendHandler.java
License:Apache License
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) { ByteBuf buf = (ByteBuf) msg;// ww w. j a v a 2s . c o m System.out.println("channelRead:" + ByteBufUtil.hexDump((buf))); while (buf.readableBytes() > 0) { int payload = buf.readUnsignedMedium(); int frameType = buf.readByte(); Http2Flags flags = new Http2Flags(buf.readUnsignedByte()); int streamId = readUnsignedInt(buf); ByteBuf payloadBuf = buf.readBytes(payload); ByteBuf copy = ctx.alloc().buffer(); System.out.println("frame_type:" + frameType + "," + ByteBufUtil.hexDump((payloadBuf))); switch (frameType) { case Http2FrameTypes.SETTINGS: handleSettingFrame(ctx, flags); break; case Http2FrameTypes.WINDOW_UPDATE: handleWindowsUpdateFrame(ctx); break; case Http2FrameTypes.HEADERS: copy.writeMedium(payload); copy.writeByte(frameType); copy.writeByte(flags.value()); copy.writeInt(streamId); copy.writeBytes(payloadBuf); forward(ctx, copy); break; case Http2FrameTypes.DATA: copy.writeMedium(payload); copy.writeByte(frameType); copy.writeByte(flags.value()); copy.writeInt(streamId); copy.writeBytes(payloadBuf); forward(ctx, copy); break; default: break; } } }
From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyBackendHandler.java
License:Apache License
private void handleSettingFrame(final ChannelHandlerContext ctx, Http2Flags flags) { ByteBufAllocator alloc = ctx.alloc(); ByteBuf byteBuf = alloc.buffer(); if (!flags.ack()) { //00 00 0c 04 00 00 00 00 00 00 03 7f ff ff ff 00 byteBuf.writeByte(0x00); byteBuf.writeByte(0x00);// ww w. j av a2 s . c om byteBuf.writeByte(0x0c); byteBuf.writeByte(0x04); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x03); byteBuf.writeByte(0x7f); byteBuf.writeByte(0xff); byteBuf.writeByte(0xff); byteBuf.writeByte(0xff); byteBuf.writeByte(0x00); //04 00 10 00 00 byteBuf.writeByte(0x04); byteBuf.writeByte(0x00); byteBuf.writeByte(0x10); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); } else { // System.out.println("********************* setting ack received ..."); //00 00 00 04 01 00 00 00 00 byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x04); byteBuf.writeByte(0x01); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); } ctx.writeAndFlush(byteBuf).addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // System.out.println(" ...operationComplete isSuccess"); ctx.channel().read(); } else { // System.out.println("...operationComplete failure"); future.channel().close(); } } }); }
From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyBackendHandler.java
License:Apache License
private void handleWindowsUpdateFrame(final ChannelHandlerContext ctx) { ByteBufAllocator alloc = ctx.alloc(); ByteBuf byteBuf = alloc.buffer(); // 00 00 04 08 00 00 00 00 00 00 0f 00 01 byteBuf.writeByte(0x00); byteBuf.writeByte(0x00);// ww w . j a va2 s .c o m byteBuf.writeByte(0x04); byteBuf.writeByte(0x08); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x0f); byteBuf.writeByte(0x00); byteBuf.writeByte(0x01); ctx.writeAndFlush(byteBuf).addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { ctx.channel().read(); } else { future.channel().close(); } } }); }
From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyFrontendHandler.java
License:Apache License
private void readFrame(final ChannelHandlerContext ctx, ByteBuf buf) { if (first) {// w w w .j a v a 2 s . c om try { readClientPrefaceString(buf); } catch (Http2Exception e) { e.printStackTrace(); } first = false; } while (buf.readableBytes() > 0) { int payload = buf.readUnsignedMedium(); int frameType = buf.readByte(); Http2Flags flags = new Http2Flags(buf.readUnsignedByte()); int streamId = readUnsignedInt(buf); ByteBuf payloadBuf = buf.readBytes(payload); ByteBuf copy = ctx.alloc().buffer(); switch (frameType) { case Http2FrameTypes.SETTINGS: handleSettingFrame(ctx, flags); break; case Http2FrameTypes.WINDOW_UPDATE: handleWindowsUpdateFrame(ctx); break; case Http2FrameTypes.HEADERS: copy.writeMedium(payload); copy.writeByte(frameType); copy.writeByte(flags.value()); copy.writeInt(streamId); copy.writeBytes(payloadBuf); handleHeaderFrame(ctx, copy, streamId); break; case Http2FrameTypes.DATA: copy.writeMedium(payload); copy.writeByte(frameType); copy.writeByte(flags.value()); copy.writeInt(streamId); copy.writeBytes(payloadBuf); handleDataFrame(ctx, copy, streamId); break; default: break; } } }
From source file:com.netty.grpc.proxy.demo.handler.GrpcProxyFrontendHandler.java
License:Apache License
private void handleSettingFrame(final ChannelHandlerContext ctx, Http2Flags flags) { ByteBufAllocator alloc = ctx.alloc(); ByteBuf byteBuf = alloc.buffer(); if (!flags.ack()) { // System.out.println("********************* setting received ..."); //00 00 0c 04 00 00 00 00 00 00 03 7f ff ff ff 00 byteBuf.writeByte(0x00); byteBuf.writeByte(0x00);/*from w w w . java 2 s . com*/ byteBuf.writeByte(0x0c); byteBuf.writeByte(0x04); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x03); byteBuf.writeByte(0x7f); byteBuf.writeByte(0xff); byteBuf.writeByte(0xff); byteBuf.writeByte(0xff); byteBuf.writeByte(0x00); //04 00 10 00 00 byteBuf.writeByte(0x04); byteBuf.writeByte(0x00); byteBuf.writeByte(0x10); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); } else { // System.out.println("********************* setting ack received ..."); //00 00 00 04 01 00 00 00 00 byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x04); byteBuf.writeByte(0x01); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); byteBuf.writeByte(0x00); } ctx.writeAndFlush(byteBuf).addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { // System.out.println(" ...operationComplete isSuccess"); ctx.channel().read(); } else { // System.out.println("...operationComplete failure"); future.channel().close(); } } }); }