List of usage examples for io.netty.buffer ByteBuf readShort
public abstract short readShort();
From source file:org.projectfloodlight.openflow.protocol.ver15.OFHeaderTypeNamespaceSerializerVer15.java
public static OFHeaderTypeNamespace readFrom(ByteBuf bb) throws OFParseError { try {//from w w w .j av a 2 s .c o m return ofWireValue(bb.readShort()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
From source file:org.projectfloodlight.openflow.protocol.ver15.OFHeaderTypeOnfSerializerVer15.java
public static OFHeaderTypeOnf readFrom(ByteBuf bb) throws OFParseError { try {//from w ww . j a v a 2 s . co m return ofWireValue(bb.readShort()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
From source file:org.projectfloodlight.openflow.protocol.ver15.OFOxsClassSerializerVer15.java
public static OFOxsClass readFrom(ByteBuf bb) throws OFParseError { try {/* w w w .j a v a 2 s . co m*/ return ofWireValue(bb.readShort()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
From source file:org.rhq.metrics.netty.collectd.packet.CollectdPacketDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext context, DatagramPacket packet, List<Object> out) throws Exception { long start = System.currentTimeMillis(); ByteBuf content = packet.content(); List<Part> parts = new ArrayList<Part>(100); for (;;) {//from w w w . j a v a2 s . co m if (!hasReadableBytes(content, 4)) { break; } short partTypeId = content.readShort(); PartType partType = PartType.findById(partTypeId); int partLength = content.readUnsignedShort(); int valueLength = partLength - 4; if (!hasReadableBytes(content, valueLength)) { break; } if (partType == null) { content.skipBytes(valueLength); continue; } Part part; switch (partType) { case HOST: case PLUGIN: case PLUGIN_INSTANCE: case TYPE: case INSTANCE: part = new StringPart(partType, readStringPartContent(content, valueLength)); break; case TIME: case TIME_HIGH_RESOLUTION: case INTERVAL: case INTERVAL_HIGH_RESOLUTION: part = new NumericPart(partType, readNumericPartContent(content)); break; case VALUES: part = new ValuePart(partType, readValuePartContent(content, valueLength)); break; default: part = null; content.skipBytes(valueLength); } //noinspection ConstantConditions if (part != null) { logger.trace("Decoded part: {}", part); parts.add(part); } } if (logger.isTraceEnabled()) { long stop = System.currentTimeMillis(); logger.trace("Decoded datagram in {} ms", stop - start); } if (parts.size() > 0) { CollectdPacket collectdPacket = new CollectdPacket(parts.toArray(new Part[parts.size()])); out.add(collectdPacket); } else { logger.debug("No parts decoded, no CollectdPacket output"); } }
From source file:org.spongepowered.clean.network.packet.play.serverbound.ClickWindowPacket.java
License:MIT License
@Override public void read(ByteBuf buffer) { this.windowid = buffer.readByte(); this.slot = buffer.readShort(); this.button = buffer.readByte(); this.actionNumber = buffer.readShort(); this.mode = ByteBufUtil.readVarInt(buffer); this.slotBlockId = buffer.readShort(); if (this.slotBlockId != -1) { this.slotCount = buffer.readByte(); this.slotDamage = buffer.readShort(); int mark = buffer.readerIndex(); byte next = buffer.readByte(); if (next != 0) { buffer.readerIndex(mark);/*from w w w . j a v a2s .c om*/ this.slotNbt = ByteBufUtil.readNBT(buffer); } } }
From source file:org.spongepowered.clean.network.packet.play.serverbound.ConfirmTransactionPacket.java
License:MIT License
@Override public void read(ByteBuf buffer) { this.windowid = buffer.readByte(); this.transactionid = buffer.readShort(); this.state = buffer.readBoolean(); }
From source file:org.spongepowered.clean.network.packet.play.serverbound.CreativeInventoryActionPacket.java
License:MIT License
@Override public void read(ByteBuf buffer) { this.slot = buffer.readShort(); this.slotBlockId = buffer.readShort(); if (this.slotBlockId != -1) { this.slotCount = buffer.readByte(); this.slotDamage = buffer.readShort(); int mark = buffer.readerIndex(); byte next = buffer.readByte(); if (next != 0) { buffer.readerIndex(mark);//w w w . jav a2 s .c om this.slotNbt = ByteBufUtil.readNBT(buffer); } } }
From source file:org.spongepowered.clean.network.packet.play.serverbound.HeldItemChangePacket.java
License:MIT License
@Override public void read(ByteBuf buffer) { this.slot = buffer.readShort(); }
From source file:org.spongepowered.common.mixin.core.status.MixinPingResponseHandler.java
License:MIT License
private boolean readLegacy(ChannelHandlerContext ctx, ByteBuf buf) { if (buf.readUnsignedByte() != 0xFE) { return false; }/* www . ja v a2 s. c o m*/ MinecraftServer server = this.networkSystem.getServer(); InetSocketAddress client = (InetSocketAddress) ctx.channel().remoteAddress(); ServerStatusResponse response; int i = buf.readableBytes(); switch (i) { case 0: logger.debug("Ping: (<=1.3) from {}:{}", client.getAddress(), client.getPort()); response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_3, null); if (response != null) { this.writeResponse(ctx, String.format("%s%d%d", SpongeStatusResponse.getUnformattedMotd(response), response.getPlayerCountData().getOnlinePlayerCount(), response.getPlayerCountData().getMaxPlayers())); } else { ctx.close(); } break; case 1: if (buf.readUnsignedByte() != 0x01) { return false; } logger.debug("Ping: (1.4-1.5) from {}:{}", client.getAddress(), client.getPort()); response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_5, null); if (response != null) { this.writeResponse(ctx, String.format("1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getProtocolVersionInfo().getProtocol(), response.getProtocolVersionInfo().getName(), SpongeStatusResponse.getMotd(response), response.getPlayerCountData().getOnlinePlayerCount(), response.getPlayerCountData().getMaxPlayers())); } else { ctx.close(); } break; default: if (buf.readUnsignedByte() != 0x01 || buf.readUnsignedByte() != 0xFA) { return false; } if (!buf.isReadable(2)) { break; } short length = buf.readShort(); if (!buf.isReadable(length * 2)) { break; } if (!buf.readBytes(length * 2).toString(Charsets.UTF_16BE).equals("MC|PingHost")) { return false; } if (!buf.isReadable(2)) { break; } length = buf.readShort(); if (!buf.isReadable(length)) { break; } int protocol = buf.readUnsignedByte(); length = buf.readShort(); String host = buf.readBytes(length * 2).toString(Charsets.UTF_16BE); int port = buf.readInt(); logger.debug("Ping: (1.6) from {}:{}", client.getAddress(), client.getPort()); response = SpongeStatusResponse.postLegacy(server, client, new SpongeLegacyMinecraftVersion(SpongeLegacyMinecraftVersion.V1_6, protocol), InetSocketAddress.createUnresolved(host, port)); if (response != null) { this.writeResponse(ctx, String.format("1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getProtocolVersionInfo().getProtocol(), response.getProtocolVersionInfo().getName(), SpongeStatusResponse.getMotd(response), response.getPlayerCountData().getOnlinePlayerCount(), response.getPlayerCountData().getMaxPlayers())); } else { ctx.close(); } break; } return true; }
From source file:org.spongepowered.granite.mixin.status.MixinPingResponseHandler.java
License:MIT License
private boolean readLegacy(ChannelHandlerContext ctx, ByteBuf buf) { if (buf.readUnsignedByte() != 0xFE) { return false; }/*from w ww. j a va2 s . com*/ MinecraftServer server = this.networkSystem.getServer(); InetSocketAddress client = (InetSocketAddress) ctx.channel().remoteAddress(); ServerStatusResponse response; int i = buf.readableBytes(); switch (i) { case 0: logger.debug("Ping: (<=1.3) from {}:{}", client.getAddress(), client.getPort()); response = GraniteStatusResponse.postLegacy(server, client, GraniteLegacyMinecraftVersion.V1_3, null); if (response != null) { this.writeResponse(ctx, String.format("%s%d%d", GraniteStatusResponse.getUnformattedMotd(response), response.getPlayerCountData().getOnlinePlayerCount(), response.getPlayerCountData().getMaxPlayers())); } else { ctx.close(); } break; case 1: if (buf.readUnsignedByte() != 0x01) { return false; } logger.debug("Ping: (1.4-1.5) from {}:{}", client.getAddress(), client.getPort()); response = GraniteStatusResponse.postLegacy(server, client, GraniteLegacyMinecraftVersion.V1_5, null); if (response != null) { this.writeResponse(ctx, String.format("1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getProtocolVersionInfo().getProtocol(), response.getProtocolVersionInfo().getName(), GraniteStatusResponse.getMotd(response), response.getPlayerCountData().getOnlinePlayerCount(), response.getPlayerCountData().getMaxPlayers())); } else { ctx.close(); } break; default: if (buf.readUnsignedByte() != 0x01 || buf.readUnsignedByte() != 0xFA) { return false; } if (!buf.isReadable(2)) { break; } short length = buf.readShort(); if (!buf.isReadable(length * 2)) { break; } if (!buf.readBytes(length * 2).toString(Charsets.UTF_16BE).equals("MC|PingHost")) { return false; } if (!buf.isReadable(2)) { break; } length = buf.readShort(); if (!buf.isReadable(length)) { break; } int protocol = buf.readUnsignedByte(); length = buf.readShort(); String host = buf.readBytes(length * 2).toString(Charsets.UTF_16BE); int port = buf.readInt(); logger.debug("Ping: (1.6) from {}:{}", client.getAddress(), client.getPort()); response = GraniteStatusResponse.postLegacy(server, client, new GraniteLegacyMinecraftVersion(GraniteLegacyMinecraftVersion.V1_6, protocol), InetSocketAddress.createUnresolved(host, port)); if (response != null) { this.writeResponse(ctx, String.format("1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getProtocolVersionInfo().getProtocol(), response.getProtocolVersionInfo().getName(), GraniteStatusResponse.getMotd(response), response.getPlayerCountData().getOnlinePlayerCount(), response.getPlayerCountData().getMaxPlayers())); } else { ctx.close(); } break; } return true; }