List of usage examples for io.netty.buffer ByteBuf readUnsignedMedium
public abstract int readUnsignedMedium();
From source file:buildcraft.commander.ContainerZonePlan.java
License:Minecraft Mod Public
@Override public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) { if (side.isClient()) { if ("areaLoaded".equals(command)) { currentAreaSelection = new ZonePlan(); currentAreaSelection.readData(stream); gui.refreshSelectedArea();//from w w w . java 2 s . c om } else if ("receiveImage".equals(command)) { int size = stream.readUnsignedMedium(); for (int i = 0; i < size; ++i) { mapTexture.colorMap[i] = 0xFF000000 | MapColor.mapColorArray[stream.readUnsignedByte()].colorValue; } } } else if (side.isServer()) { if ("loadArea".equals(command)) { final int index = stream.readUnsignedByte(); BuildCraftCore.instance.sendToPlayer((EntityPlayer) sender, new PacketCommand(this, "areaLoaded", new CommandWriter() { public void write(ByteBuf data) { map.selectArea(index).writeData(data); } })); } else if ("saveArea".equals(command)) { final int index = stream.readUnsignedByte(); ZonePlan plan = new ZonePlan(); plan.readData(stream); map.setArea(index, plan); } else if ("computeMap".equals(command)) { computeMap(stream.readInt(), stream.readInt(), stream.readUnsignedShort(), stream.readUnsignedShort(), stream.readUnsignedByte(), (EntityPlayer) sender); } } }
From source file:buildcraft.robotics.gui.ContainerZonePlan.java
License:Minecraft Mod Public
@Override public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) { if (side.isClient()) { if ("areaLoaded".equals(command)) { currentAreaSelection = new ZonePlan(); currentAreaSelection.readData(stream); gui.refreshSelectedArea();//from w w w .ja va2s .co m } else if ("receiveImage".equals(command)) { int size = stream.readUnsignedMedium(); int pos = stream.readUnsignedMedium(); for (int i = 0; i < Math.min(size - pos, MAX_PACKET_LENGTH); ++i) { mapTexture.colorMap[pos + i] = 0xFF000000 | MapColor.mapColorArray[stream.readUnsignedByte()].colorValue; } } } else if (side.isServer()) { if ("loadArea".equals(command)) { final int index = stream.readUnsignedByte(); BuildCraftCore.instance.sendToPlayer((EntityPlayer) sender, new PacketCommand(this, "areaLoaded", new CommandWriter() { public void write(ByteBuf data) { map.selectArea(index).writeData(data); } })); } else if ("saveArea".equals(command)) { final int index = stream.readUnsignedByte(); ZonePlan plan = new ZonePlan(); plan.readData(stream); map.setArea(index, plan); } else if ("computeMap".equals(command)) { computeMap(stream.readInt(), stream.readInt(), stream.readUnsignedShort(), stream.readUnsignedShort(), stream.readFloat(), (EntityPlayer) sender); } else if ("setName".equals(command)) { map.mapName = NetworkUtils.readUTF(stream); } } }
From source file:com.friz.game.network.codec.LoginDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception { int type = buf.readUnsignedByte(); int size = buf.readUnsignedShort(); int major = buf.readInt(); int minor = buf.readInt(); boolean dropped = buf.readBoolean(); int rsaSize = buf.readUnsignedShort(); byte[] rsa = new byte[rsaSize]; buf.readBytes(rsa);/*from www . ja va 2 s.co m*/ ByteBuf rsaBuf = Unpooled.wrappedBuffer( new BigInteger(rsa).modPow(Constants.LOGIN_EXPONENT, Constants.LOGIN_MODULUS).toByteArray()); int rsaMagic = rsaBuf.readUnsignedByte(); int[] key = new int[4]; for (int i = 0; i < key.length; i++) key[i] = rsaBuf.readInt(); int block = rsaBuf.readUnsignedByte(); if (block == 1 || block == 3) { int code = rsaBuf.readUnsignedMedium(); rsaBuf.readerIndex(rsaBuf.readerIndex() + 1); } else if (block == 0) { int trusted = rsaBuf.readInt(); } else if (block == 2) { rsaBuf.readerIndex(rsaBuf.readerIndex() + 4); } String password = BufferUtils.getString(rsaBuf); long serverKey = rsaBuf.readLong(); long clientKey = rsaBuf.readLong(); byte[] xtea = new byte[buf.readableBytes()]; buf.readBytes(xtea); ByteBuf xteaBuf = Unpooled.wrappedBuffer(new XTEA(xtea).decrypt(key).toByteArray()); String username = ""; boolean asString = xteaBuf.readBoolean(); if (asString) username = BufferUtils.getString(xteaBuf); else username = BufferUtils.getBase37(xteaBuf); int display = xteaBuf.readUnsignedByte(); int width = xteaBuf.readUnsignedShort(); int height = xteaBuf.readUnsignedShort(); int multisample = xteaBuf.readByte(); byte[] uid = new byte[24]; for (int i = 0; i < uid.length; i++) uid[i] = xteaBuf.readByte(); String token = BufferUtils.getString(xteaBuf); int prefSize = xteaBuf.readUnsignedByte(); int prefVersion = xteaBuf.readUnsignedByte(); int aPref = xteaBuf.readUnsignedByte(); int antiAliasing = xteaBuf.readUnsignedByte(); int aPref1 = xteaBuf.readUnsignedByte(); int bloom = xteaBuf.readUnsignedByte(); int brightness = xteaBuf.readUnsignedByte(); int buildArea = xteaBuf.readUnsignedByte(); int aPref2 = xteaBuf.readUnsignedByte(); int flickeringEffects = xteaBuf.readUnsignedByte(); int fog = xteaBuf.readUnsignedByte(); int groundBlending = xteaBuf.readUnsignedByte(); int groundDecoration = xteaBuf.readUnsignedByte(); int idleAnimations = xteaBuf.readUnsignedByte(); int lighting = xteaBuf.readUnsignedByte(); int sceneryShadows = xteaBuf.readUnsignedByte(); int aPref3 = xteaBuf.readUnsignedByte(); int nullPref = xteaBuf.readUnsignedByte(); int orthoMode = xteaBuf.readUnsignedByte(); int particles = xteaBuf.readUnsignedByte(); int removeRoofs = xteaBuf.readUnsignedByte(); int maxScreenSize = xteaBuf.readUnsignedByte(); int skyboxes = xteaBuf.readUnsignedByte(); int mobShadows = xteaBuf.readUnsignedByte(); int textures = xteaBuf.readUnsignedByte(); int desiredToolkit = xteaBuf.readUnsignedByte(); int nullPref1 = xteaBuf.readUnsignedByte(); int water = xteaBuf.readUnsignedByte(); int screenSize = xteaBuf.readUnsignedByte(); int customCursors = xteaBuf.readUnsignedByte(); int graphics = xteaBuf.readUnsignedByte(); int cpu = xteaBuf.readUnsignedByte(); int aPref4 = xteaBuf.readUnsignedByte(); int safeMode = xteaBuf.readUnsignedByte(); int aPref5 = xteaBuf.readUnsignedByte(); int aPref6 = xteaBuf.readUnsignedByte(); int aPref7 = xteaBuf.readUnsignedByte(); int soundEffectsVolume = xteaBuf.readUnsignedByte(); int areaSoundsVolume = xteaBuf.readUnsignedByte(); int voiceOverVolume = xteaBuf.readUnsignedByte(); int musicVolume = xteaBuf.readUnsignedByte(); int themeMusicVolume = xteaBuf.readUnsignedByte(); int steroSound = xteaBuf.readUnsignedByte(); int infoVersion = xteaBuf.readUnsignedByte(); int osType = xteaBuf.readUnsignedByte(); boolean arch64 = xteaBuf.readBoolean(); int versionType = xteaBuf.readUnsignedByte(); int vendorType = xteaBuf.readUnsignedByte(); int jMajor = xteaBuf.readUnsignedByte(); int jMinor = xteaBuf.readUnsignedByte(); int jPatch = xteaBuf.readUnsignedByte(); boolean falseBool = xteaBuf.readBoolean(); int heapSize = xteaBuf.readUnsignedShort(); int pocessorCount = xteaBuf.readUnsignedByte(); int cpuPhyscialMemory = xteaBuf.readUnsignedMedium(); int cpuClock = xteaBuf.readUnsignedShort(); String gpuName = BufferUtils.getJagString(xteaBuf); String aString = BufferUtils.getJagString(xteaBuf); String dxVersion = BufferUtils.getJagString(xteaBuf); String aString1 = BufferUtils.getJagString(xteaBuf); int gpuDriverMonth = xteaBuf.readUnsignedByte(); int gpuDriverYear = xteaBuf.readUnsignedShort(); String cpuType = BufferUtils.getJagString(xteaBuf); String cpuName = BufferUtils.getJagString(xteaBuf); int cpuThreads = xteaBuf.readUnsignedByte(); int anInt = xteaBuf.readUnsignedByte(); int anInt1 = xteaBuf.readInt(); int anInt2 = xteaBuf.readInt(); int anInt3 = xteaBuf.readInt(); int anInt4 = xteaBuf.readInt(); String aString2 = BufferUtils.getString(xteaBuf); int anInt5 = xteaBuf.readInt(); int anInt6 = xteaBuf.readInt(); int anInt7 = xteaBuf.readInt(); String aString3 = BufferUtils.getString(xteaBuf); boolean hasAdditional = xteaBuf.readBoolean(); String additionalInfo = ""; if (hasAdditional) additionalInfo = BufferUtils.getString(xteaBuf); int anInt8 = xteaBuf.readUnsignedByte(); int anInt9 = xteaBuf.readUnsignedByte(); int anInt10 = xteaBuf.readUnsignedByte(); int anInt11 = xteaBuf.readInt(); String aString4 = BufferUtils.getString(xteaBuf); boolean newWorld = xteaBuf.readBoolean(); int lobbyId = xteaBuf.readUnsignedShort(); int[] checksums = new int[(xteaBuf.readableBytes() / 4) + 1]; for (int i = 0; i < checksums.length; i++) { if (i == 32) checksums[i] = -1; else checksums[i] = xteaBuf.readInt(); } }
From source file:com.friz.lobby.network.codec.LoginDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception { if (!buf.isReadable()) return;/*from w w w . j a v a 2s.c om*/ int type = buf.readUnsignedByte(); int size = buf.readUnsignedShort(); if (!buf.isReadable(size)) return; int major = buf.readInt(); int minor = buf.readInt(); int rsaSize = buf.readUnsignedShort(); byte[] rsa = new byte[rsaSize]; buf.readBytes(rsa); ByteBuf rsaBuf = Unpooled.wrappedBuffer( new BigInteger(rsa).modPow(Constants.LOGIN_EXPONENT, Constants.LOGIN_MODULUS).toByteArray()); int rsaMagic = rsaBuf.readUnsignedByte(); int[] key = new int[4]; for (int i = 0; i < key.length; i++) key[i] = rsaBuf.readInt(); int block = rsaBuf.readUnsignedByte(); if (block == 1 || block == 3) { int code = rsaBuf.readUnsignedMedium(); rsaBuf.readerIndex(rsaBuf.readerIndex() + 1); System.out.println(new GoogleAuthenticator().authorize("OE2ZSYF6T7N2R5CG", code)); } else if (block == 0) { int trusted = rsaBuf.readInt(); } else if (block == 2) { rsaBuf.readerIndex(rsaBuf.readerIndex() + 4); } String password = BufferUtils.getString(rsaBuf); long serverKey = rsaBuf.readLong(); long clientKey = rsaBuf.readLong(); byte[] xtea = new byte[buf.readableBytes()]; buf.readBytes(xtea); ByteBuf xteaBuf = Unpooled.wrappedBuffer(new XTEA(xtea).decrypt(key).toByteArray()); String username = ""; boolean asString = xteaBuf.readBoolean(); if (asString) username = BufferUtils.getString(xteaBuf); else username = BufferUtils.getBase37(xteaBuf); int game = xteaBuf.readUnsignedByte(); int lang = xteaBuf.readUnsignedByte(); int display = xteaBuf.readUnsignedByte(); int width = xteaBuf.readUnsignedShort(); int height = xteaBuf.readUnsignedShort(); int multisample = xteaBuf.readByte(); byte[] uid = new byte[24]; for (int i = 0; i < uid.length; i++) uid[i] = xteaBuf.readByte(); String token = BufferUtils.getString(xteaBuf); int prefSize = xteaBuf.readUnsignedByte(); int prefVersion = xteaBuf.readUnsignedByte(); int aPref = xteaBuf.readUnsignedByte(); int antiAliasing = xteaBuf.readUnsignedByte(); int aPref1 = xteaBuf.readUnsignedByte(); int bloom = xteaBuf.readUnsignedByte(); int brightness = xteaBuf.readUnsignedByte(); int buildArea = xteaBuf.readUnsignedByte(); int aPref2 = xteaBuf.readUnsignedByte(); int flickeringEffects = xteaBuf.readUnsignedByte(); int fog = xteaBuf.readUnsignedByte(); int groundBlending = xteaBuf.readUnsignedByte(); int groundDecoration = xteaBuf.readUnsignedByte(); int idleAnimations = xteaBuf.readUnsignedByte(); int lighting = xteaBuf.readUnsignedByte(); int sceneryShadows = xteaBuf.readUnsignedByte(); int aPref3 = xteaBuf.readUnsignedByte(); int nullPref = xteaBuf.readUnsignedByte(); int orthoMode = xteaBuf.readUnsignedByte(); int particles = xteaBuf.readUnsignedByte(); int removeRoofs = xteaBuf.readUnsignedByte(); int maxScreenSize = xteaBuf.readUnsignedByte(); int skyboxes = xteaBuf.readUnsignedByte(); int mobShadows = xteaBuf.readUnsignedByte(); int textures = xteaBuf.readUnsignedByte(); int desiredToolkit = xteaBuf.readUnsignedByte(); int nullPref1 = xteaBuf.readUnsignedByte(); int water = xteaBuf.readUnsignedByte(); int screenSize = xteaBuf.readUnsignedByte(); int customCursors = xteaBuf.readUnsignedByte(); int graphics = xteaBuf.readUnsignedByte(); int cpu = xteaBuf.readUnsignedByte(); int aPref4 = xteaBuf.readUnsignedByte(); int safeMode = xteaBuf.readUnsignedByte(); int aPref5 = xteaBuf.readUnsignedByte(); int aPref6 = xteaBuf.readUnsignedByte(); int aPref7 = xteaBuf.readUnsignedByte(); int soundEffectsVolume = xteaBuf.readUnsignedByte(); int areaSoundsVolume = xteaBuf.readUnsignedByte(); int voiceOverVolume = xteaBuf.readUnsignedByte(); int musicVolume = xteaBuf.readUnsignedByte(); int themeMusicVolume = xteaBuf.readUnsignedByte(); int steroSound = xteaBuf.readUnsignedByte(); int infoVersion = xteaBuf.readUnsignedByte(); int osType = xteaBuf.readUnsignedByte(); boolean arch64 = xteaBuf.readBoolean(); int versionType = xteaBuf.readUnsignedByte(); int vendorType = xteaBuf.readUnsignedByte(); int jMajor = xteaBuf.readUnsignedByte(); int jMinor = xteaBuf.readUnsignedByte(); int jPatch = xteaBuf.readUnsignedByte(); boolean falseBool = xteaBuf.readBoolean(); int heapSize = xteaBuf.readUnsignedShort(); int pocessorCount = xteaBuf.readUnsignedByte(); int cpuPhyscialMemory = xteaBuf.readUnsignedMedium(); int cpuClock = xteaBuf.readUnsignedShort(); String gpuName = BufferUtils.getJagString(xteaBuf); String aString = BufferUtils.getJagString(xteaBuf); String dxVersion = BufferUtils.getJagString(xteaBuf); String aString1 = BufferUtils.getJagString(xteaBuf); int gpuDriverMonth = xteaBuf.readUnsignedByte(); int gpuDriverYear = xteaBuf.readUnsignedShort(); String cpuType = BufferUtils.getJagString(xteaBuf); String cpuName = BufferUtils.getJagString(xteaBuf); int cpuThreads = xteaBuf.readUnsignedByte(); int anInt = xteaBuf.readUnsignedByte(); int anInt1 = xteaBuf.readInt(); int anInt2 = xteaBuf.readInt(); int anInt3 = xteaBuf.readInt(); int anInt4 = xteaBuf.readInt(); String aString2 = BufferUtils.getJagString(xteaBuf); int anInt5 = xteaBuf.readInt(); String aString3 = BufferUtils.getString(xteaBuf); int affiliate = xteaBuf.readInt(); int anInt6 = xteaBuf.readInt(); String aString4 = BufferUtils.getString(xteaBuf); int anInt7 = xteaBuf.readUnsignedByte(); int[] checksums = new int[(xteaBuf.readableBytes() / 4) + 1]; for (int i = 0; i < checksums.length; i++) { if (i == 32) checksums[i] = -1; else checksums[i] = xteaBuf.readInt(); } final List<Module> modules = new ArrayList<>(); modules.add(new ClientVersionModule(major, minor)); modules.add(new ClientTypeModule(game, lang, display, width, height)); out.add(new LoginRequestEvent(modules)); }
From source file:com.friz.lobby.network.codec.SocialDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception { if (!buf.isReadable()) return;/*from w w w .java 2 s .com*/ int type = buf.readUnsignedByte(); int size = buf.readUnsignedShort(); if (!buf.isReadable(size)) return; byte[] xtea = new byte[size]; buf.readBytes(xtea); ByteBuf xteaBuf = Unpooled.wrappedBuffer(new XTEA(xtea).decrypt(key).toByteArray()); int game = xteaBuf.readUnsignedByte(); int lang = xteaBuf.readUnsignedByte(); int display = xteaBuf.readUnsignedByte(); int width = xteaBuf.readUnsignedShort(); int height = xteaBuf.readUnsignedShort(); int multisample = xteaBuf.readByte(); byte[] uid = new byte[24]; for (int i = 0; i < uid.length; i++) uid[i] = xteaBuf.readByte(); String gameToken = BufferUtils.getString(xteaBuf); int prefSize = xteaBuf.readUnsignedByte(); int prefVersion = xteaBuf.readUnsignedByte(); int aPref = xteaBuf.readUnsignedByte(); int antiAliasing = xteaBuf.readUnsignedByte(); int aPref1 = xteaBuf.readUnsignedByte(); int bloom = xteaBuf.readUnsignedByte(); int brightness = xteaBuf.readUnsignedByte(); int buildArea = xteaBuf.readUnsignedByte(); int aPref2 = xteaBuf.readUnsignedByte(); int flickeringEffects = xteaBuf.readUnsignedByte(); int fog = xteaBuf.readUnsignedByte(); int groundBlending = xteaBuf.readUnsignedByte(); int groundDecoration = xteaBuf.readUnsignedByte(); int idleAnimations = xteaBuf.readUnsignedByte(); int lighting = xteaBuf.readUnsignedByte(); int sceneryShadows = xteaBuf.readUnsignedByte(); int aPref3 = xteaBuf.readUnsignedByte(); int nullPref = xteaBuf.readUnsignedByte(); int orthoMode = xteaBuf.readUnsignedByte(); int particles = xteaBuf.readUnsignedByte(); int removeRoofs = xteaBuf.readUnsignedByte(); int maxScreenSize = xteaBuf.readUnsignedByte(); int skyboxes = xteaBuf.readUnsignedByte(); int mobShadows = xteaBuf.readUnsignedByte(); int textures = xteaBuf.readUnsignedByte(); int desiredToolkit = xteaBuf.readUnsignedByte(); int nullPref1 = xteaBuf.readUnsignedByte(); int water = xteaBuf.readUnsignedByte(); int screenSize = xteaBuf.readUnsignedByte(); int customCursors = xteaBuf.readUnsignedByte(); int graphics = xteaBuf.readUnsignedByte(); int cpu = xteaBuf.readUnsignedByte(); int aPref4 = xteaBuf.readUnsignedByte(); int safeMode = xteaBuf.readUnsignedByte(); int aPref5 = xteaBuf.readUnsignedByte(); int aPref6 = xteaBuf.readUnsignedByte(); int aPref7 = xteaBuf.readUnsignedByte(); int soundEffectsVolume = xteaBuf.readUnsignedByte(); int areaSoundsVolume = xteaBuf.readUnsignedByte(); int voiceOverVolume = xteaBuf.readUnsignedByte(); int musicVolume = xteaBuf.readUnsignedByte(); int themeMusicVolume = xteaBuf.readUnsignedByte(); int steroSound = xteaBuf.readUnsignedByte(); xteaBuf.readMedium(); xteaBuf.readMedium(); int infoVersion = xteaBuf.readUnsignedByte(); int osType = xteaBuf.readUnsignedByte(); boolean arch64 = xteaBuf.readBoolean(); int versionType = xteaBuf.readUnsignedByte(); int vendorType = xteaBuf.readUnsignedByte(); int jMajor = xteaBuf.readUnsignedByte(); int jMinor = xteaBuf.readUnsignedByte(); int jPatch = xteaBuf.readUnsignedByte(); boolean falseBool = xteaBuf.readBoolean(); int heapSize = xteaBuf.readUnsignedShort(); int pocessorCount = xteaBuf.readUnsignedByte(); int cpuPhyscialMemory = xteaBuf.readUnsignedMedium(); int cpuClock = xteaBuf.readUnsignedShort(); String gpuName = BufferUtils.getJagString(xteaBuf); String aString = BufferUtils.getJagString(xteaBuf); String dxVersion = BufferUtils.getJagString(xteaBuf); String aString1 = BufferUtils.getJagString(xteaBuf); int gpuDriverMonth = xteaBuf.readUnsignedByte(); int gpuDriverYear = xteaBuf.readUnsignedShort(); String cpuType = BufferUtils.getJagString(xteaBuf); String cpuName = BufferUtils.getJagString(xteaBuf); int cpuThreads = xteaBuf.readUnsignedByte(); int anInt = xteaBuf.readUnsignedByte(); int anInt1 = xteaBuf.readInt(); int anInt2 = xteaBuf.readInt(); int anInt3 = xteaBuf.readInt(); int anInt4 = xteaBuf.readInt(); String aString2 = BufferUtils.getJagString(xteaBuf); int anInt5 = xteaBuf.readInt(); String seed = BufferUtils.getString(xteaBuf); int affiliate = xteaBuf.readInt(); int anInt6 = xteaBuf.readInt(); String updateToken = BufferUtils.getString(xteaBuf); int anInt7 = xteaBuf.readUnsignedByte(); int[] checksums = new int[(xteaBuf.readableBytes() / 4) + 1]; for (int i = 0; i < checksums.length; i++) { if (i == 32) checksums[i] = -1; else checksums[i] = xteaBuf.readInt(); } System.out.println(seed); }
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; 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);/*from w w w. ja v a 2 s. c om*/ 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.GrpcProxyFrontendHandler.java
License:Apache License
private void readFrame(final ChannelHandlerContext ctx, ByteBuf buf) { if (first) {// w w w . jav a 2s. co m 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.quavo.osrs.network.protocol.codec.update.UpdateDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (!in.isReadable() || in.readableBytes() < 4) { return;//from w ww.j ava 2 s .c o m } Optional<UpdateType> request = UpdateType.getType(in.readUnsignedByte()); if (request.isPresent()) { UpdateType updateType = request.get(); switch (updateType) { case LOW_PRIORITY_UPDATE: case HIGH_PRIORITY_UPDATE: int uid = in.readUnsignedMedium(); int type = (uid >> 16); int id = (uid & 0xffff); out.add(new UpdateRequest(this, type, id, updateType == UpdateType.HIGH_PRIORITY_UPDATE)); break; case XOR_ENCRYPTION_UPDATE: int key = in.readUnsignedByte(); in.readUnsignedShort(); out.add(new XOREncryptionRequest(this, key)); break; } } else { in.readUnsignedMedium(); } }
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
License:Open Source License
public static long getLengthCodedLong(ByteBuf cb) { short byte1 = cb.readUnsignedByte(); if (byte1 == LEN_CODED_NULL) return 0; if (byte1 <= LEN_CODED_8_BITS) { return byte1; } else if (byte1 == LEN_CODED_16_BITS) { return cb.readUnsignedShort(); } else if (byte1 == LEN_CODED_24_BITS) return cb.readUnsignedMedium(); return cb.readLong(); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyStatusVariables.java
License:Open Source License
public void parseStatusVariables(ByteBuf cb, int svLen) throws PEException { if (svLen > 0) { ByteBuf statsVarsBuf = cb.readBytes(svLen); while (statsVarsBuf.isReadable()) { byte code = statsVarsBuf.readByte(); MyQueryEventCode mqec = MyQueryEventCode.fromByte(code); if (mqec == null) { throw new PEException("Replication could not decode query event code: '" + code + "' (0x" + Integer.toHexString(code) + ")"); }/*from ww w.j a va 2 s . c om*/ switch (mqec) { case Q_FLAGS2_CODE: int flags = statsVarsBuf.readInt(); suppliedEventCodes.add(new QueryFlags2Event(flags)); break; case Q_SQL_MODE_CODE: long sqlMode = statsVarsBuf.readLong(); suppliedEventCodes.add(new QuerySQLModeEvent(sqlMode)); break; case Q_CATALOG_CODE: { byte len = statsVarsBuf.readByte(); String catalog = MysqlAPIUtils.readBytesAsString(statsVarsBuf, len, CharsetUtil.UTF_8); statsVarsBuf.readByte(); // null terminated byte suppliedEventCodes.add(new QueryCatalogEvent(catalog)); break; } case Q_AUTO_INCREMENT: int autoIncrementIncrement = statsVarsBuf.readUnsignedShort(); int autoIncrementOffset = statsVarsBuf.readUnsignedShort(); suppliedEventCodes .add(new QueryAutoIncrementEvent(autoIncrementIncrement, autoIncrementOffset)); break; case Q_CHARSET_CODE: int charSetClient = statsVarsBuf.readUnsignedShort(); int collationConnection = statsVarsBuf.readUnsignedShort(); int collationServer = statsVarsBuf.readUnsignedShort(); suppliedEventCodes .add(new QueryCharSetCodeEvent(charSetClient, collationConnection, collationServer)); break; case Q_TIME_ZONE_CODE: { byte len = statsVarsBuf.readByte(); String timeZone = MysqlAPIUtils.readBytesAsString(statsVarsBuf, len, CharsetUtil.UTF_8); suppliedEventCodes.add(new QueryTimeZoneCodeEvent(timeZone)); break; } case Q_CATALOG_NZ_CODE: { byte catalogLen = statsVarsBuf.readByte(); String catalog = MysqlAPIUtils.readBytesAsString(statsVarsBuf, catalogLen, CharsetUtil.UTF_8); suppliedEventCodes.add(new QueryCatalogNZEvent(catalog)); break; } case Q_LC_TIME_NAMES_CODE: short monthDayNames = statsVarsBuf.readShort(); suppliedEventCodes.add(new QueryTimeNamesEvent(monthDayNames)); break; case Q_CHARSET_DATABASE_CODE: short collationDatabase = statsVarsBuf.readShort(); suppliedEventCodes.add(new QueryCollationDatabaseEvent(collationDatabase)); break; case Q_TABLE_MAP_FOR_UPDATE_CODE: long tableMapForUpdate = statsVarsBuf.readLong(); suppliedEventCodes.add(new QueryTableMapEvent(tableMapForUpdate)); break; case Q_MASTER_DATA_WRITTEN_CODE: int originalLength = statsVarsBuf.readInt(); suppliedEventCodes.add(new QueryMasterDataWrittenEvent(originalLength)); break; case Q_INVOKER: int userLen = statsVarsBuf.readByte(); String user = MysqlAPIUtils.readBytesAsString(statsVarsBuf, userLen, CharsetUtil.UTF_8); int hostLen = statsVarsBuf.readByte(); String host = MysqlAPIUtils.readBytesAsString(statsVarsBuf, hostLen, CharsetUtil.UTF_8); suppliedEventCodes.add(new QueryInvokerEvent(user, host)); break; case Q_UPDATED_DB_NAMES: List<String> dbNames = new ArrayList<String>(); int numDbs = statsVarsBuf.readByte(); if (numDbs > 0) { for (int i = 0; i < numDbs; i++) { dbNames.add(statsVarsBuf.readSlice(statsVarsBuf.bytesBefore((byte) 0)) .toString(CharsetUtil.UTF_8)); statsVarsBuf.readByte(); //read null byte } } suppliedEventCodes.add(new QueryUpdatedDBNamesEvent(dbNames)); break; case Q_MICROSECONDS: int microseconds = statsVarsBuf.readMedium(); suppliedEventCodes.add(new QueryMicrosecondsEvent(microseconds)); break; case Q_HRNOW: //TODO: this was apparently added for MariaDB, but I can't find a lot of info on it. skip for now. suppliedEventCodes.add(new QueryMicrosecondsEvent(statsVarsBuf.readUnsignedMedium())); break; default: throw new PEException("Replication encountered an unknown query event code: '" + code + "' (0x" + Integer.toHexString(code) + ")"); } } } }