List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:net.epsilony.utils.codec.modbus.reqres.WriteHoldingResponse.java
License:Open Source License
@Override public void writePduCore(ByteBuf out) { out.writeShort(address); out.writeShort(value); }
From source file:net.hasor.rsf.protocol.rsf.v1.PoolBlock.java
License:Apache License
public void fillTo(ByteBuf toData) { if (toData == null) return;/* ww w. j a v a 2 s . co m*/ // toData.writeShort(poolMap.length); for (int i = 0; i < poolMap.length; i++) { toData.writeInt(poolMap[i]); } toData.writeBytes(this.poolData); }
From source file:net.hasor.rsf.protocol.rsf.v1.RpcRequestProtocolV1.java
License:Apache License
private ByteBuf encodeRequest(RequestBlock reqMsg) { ByteBuf bodyBuf = ProtocolUtils.newByteBuf(); //* --------------------------------------------------------bytes =14 //* byte[2] servicesName-(attr-index) ??? bodyBuf.writeShort(reqMsg.getServiceName()); //* byte[2] servicesGroup-(attr-index) ? bodyBuf.writeShort(reqMsg.getServiceGroup()); //* byte[2] servicesVersion-(attr-index) ? bodyBuf.writeShort(reqMsg.getServiceVersion()); //* byte[2] servicesMethod-(attr-index) ??? bodyBuf.writeShort(reqMsg.getTargetMethod()); //* byte[2] serializeType-(attr-index) ? bodyBuf.writeShort(reqMsg.getSerializeType()); //* byte[4] clientTimeout bodyBuf.writeInt(reqMsg.getClientTimeout()); //* --------------------------------------------------------bytes =1 ~ 1021 //* byte[1] paramCount ? int[] paramMapping = reqMsg.getParameters(); bodyBuf.writeByte(paramMapping.length); for (int i = 0; i < paramMapping.length; i++) { //* byte[4] ptype-0-(attr-index,attr-index) ?1 //* byte[4] ptype-1-(attr-index,attr-index) ?2 bodyBuf.writeInt(paramMapping[i]); }//from ww w . j ava 2s.c o m //* --------------------------------------------------------bytes =1 ~ 1021 //* byte[1] optionCount ? int[] optionMapping = reqMsg.getOptions(); bodyBuf.writeByte(optionMapping.length); for (int i = 0; i < optionMapping.length; i++) { //* byte[4] ptype-0-(attr-index,attr-index) ?1 //* byte[4] ptype-1-(attr-index,attr-index) ?2 bodyBuf.writeInt(optionMapping[i]); } //* --------------------------------------------------------? //* dataBody ? reqMsg.fillTo(bodyBuf); return bodyBuf; }
From source file:net.hasor.rsf.protocol.rsf.v1.RpcResponseProtocolV1.java
License:Apache License
private ByteBuf encodeResponse(ResponseBlock resMsg) { ByteBuf bodyBuf = ProtocolUtils.newByteBuf(); ///*www.j a v a2s .com*/ //* --------------------------------------------------------bytes =8 //* byte[2] status ?? bodyBuf.writeShort(resMsg.getStatus()); //* byte[2] serializeType-(attr-index) ? bodyBuf.writeShort(resMsg.getSerializeType()); //* byte[2] returnData-(attr-index) ? bodyBuf.writeShort(resMsg.getReturnData()); //* --------------------------------------------------------bytes =1 ~ 1021 //* byte[1] optionCount ? int[] optionMapping = resMsg.getOptions(); bodyBuf.writeByte(optionMapping.length); for (int i = 0; i < optionMapping.length; i++) { //* byte[4] ptype-0-(attr-index,attr-index) ?1 //* byte[4] ptype-1-(attr-index,attr-index) ?2 bodyBuf.writeInt(optionMapping[i]); } //* --------------------------------------------------------bytes =n //* dataBody ? resMsg.fillTo(bodyBuf); return bodyBuf; }
From source file:net.hasor.rsf.remoting.transport.protocol.codec.RpcRequestProtocol.java
License:Apache License
private ByteBuf encodeRequest(RequestSocketBlock reqMsg) { ByteBuf bodyBuf = ByteBufAllocator.DEFAULT.heapBuffer(); //* --------------------------------------------------------bytes =14 //* byte[2] servicesName-(attr-index) ??? bodyBuf.writeShort(reqMsg.getServiceName()); //* byte[2] servicesGroup-(attr-index) ? bodyBuf.writeShort(reqMsg.getServiceGroup()); //* byte[2] servicesVersion-(attr-index) ? bodyBuf.writeShort(reqMsg.getServiceVersion()); //* byte[2] servicesMethod-(attr-index) ??? bodyBuf.writeShort(reqMsg.getTargetMethod()); //* byte[2] serializeType-(attr-index) ? bodyBuf.writeShort(reqMsg.getSerializeType()); //* byte[4] clientTimeout bodyBuf.writeInt(reqMsg.getClientTimeout()); //* --------------------------------------------------------bytes =1 ~ 1021 //* byte[1] paramCount ? int[] paramMapping = reqMsg.getParameters(); bodyBuf.writeByte(paramMapping.length); for (int i = 0; i < paramMapping.length; i++) { //* byte[4] ptype-0-(attr-index,attr-index) ?1 //* byte[4] ptype-1-(attr-index,attr-index) ?2 bodyBuf.writeInt(paramMapping[i]); }//from w w w. j av a 2s .c om //* --------------------------------------------------------bytes =1 ~ 1021 //* byte[1] optionCount ? int[] optionMapping = reqMsg.getOptions(); bodyBuf.writeByte(optionMapping.length); for (int i = 0; i < optionMapping.length; i++) { //* byte[4] ptype-0-(attr-index,attr-index) ?1 //* byte[4] ptype-1-(attr-index,attr-index) ?2 bodyBuf.writeInt(optionMapping[i]); } //* --------------------------------------------------------bytes =6 ~ 8192 //* byte[2] attrPool-size (Max = 2047) ? 0x07FF int[] poolData = reqMsg.getPoolData(); bodyBuf.writeShort(poolData.length); for (int i = 0; i < poolData.length; i++) { //* byte[4] ptype-0-(attr-index,attr-index) 1? //* byte[4] ptype-1-(attr-index,attr-index) 1? bodyBuf.writeInt(poolData[i]); } //* --------------------------------------------------------bytes =n //* dataBody ? reqMsg.fillTo(bodyBuf); return bodyBuf; }
From source file:net.hasor.rsf.remoting.transport.protocol.codec.RpcResponseProtocol.java
License:Apache License
private ByteBuf encodeResponse(ResponseSocketBlock resMsg) { ByteBuf bodyBuf = ByteBufAllocator.DEFAULT.heapBuffer(); ////from ww w . j a va 2 s. c om //* --------------------------------------------------------bytes =8 //* byte[2] status ?? bodyBuf.writeShort(resMsg.getStatus()); //* byte[2] serializeType-(attr-index) ? bodyBuf.writeShort(resMsg.getSerializeType()); //* byte[2] returnType-(attr-index) bodyBuf.writeShort(resMsg.getReturnType()); //* byte[2] returnData-(attr-index) ? bodyBuf.writeShort(resMsg.getReturnData()); //* --------------------------------------------------------bytes =1 ~ 1021 //* byte[1] optionCount ? int[] optionMapping = resMsg.getOptions(); bodyBuf.writeByte(optionMapping.length); for (int i = 0; i < optionMapping.length; i++) { //* byte[4] ptype-0-(attr-index,attr-index) ?1 //* byte[4] ptype-1-(attr-index,attr-index) ?2 bodyBuf.writeInt(optionMapping[i]); } //* --------------------------------------------------------bytes =6 ~ 8192 //* byte[2] attrPool-size (Max = 2047) ? 0x07FF int[] poolData = resMsg.getPoolData(); bodyBuf.writeShort(poolData.length); for (int i = 0; i < poolData.length; i++) { //* byte[4] ptype-0-(attr-index,attr-index) 1? //* byte[4] ptype-1-(attr-index,attr-index) 2? bodyBuf.writeInt(poolData[i]); } //* --------------------------------------------------------bytes =n //* dataBody ? resMsg.fillTo(bodyBuf); return bodyBuf; }
From source file:net.ieldor.network.codec.buf.PacketBufEncoder.java
License:Open Source License
@Override public void encode(ChannelHandlerContext ctx, Packet buf, ByteBuf out) throws Exception { if (buf.isHeaderless()) { out.writeBytes(buf.getPayload()); } else {// ww w . j a va 2 s.c om int opcode = buf.getOpcode(); PacketType type = buf.getType(); int length = buf.getLength(); int finalLength = length + 2 + type.getValue(); ByteBuf buffer = Unpooled.buffer(finalLength); if (opcode >= 128) { buffer.writeByte((opcode >> 8) + 128); buffer.writeByte(opcode); } else { buffer.writeByte(opcode); } //System.out.println("Sending packet. Opcode="+((opcode) & 0xFF)); switch (type) { case BYTE: buffer.writeByte(length); break; case SHORT: buffer.writeShort(length); break; default: break; } buffer.writeBytes(buf.getPayload()); out.writeBytes(buffer); } }
From source file:net.ieldor.network.codec.login.LoginEncoder.java
License:Open Source License
@Override public void encode(ChannelHandlerContext ctx, LoginResponse msg, ByteBuf out) throws Exception { out.writeByte(msg.getReturnCode());//from w ww . j av a 2 s . co m if (msg.hasPayload()) { if (msg.isVarShort()) { out.writeShort(msg.getPayloadSize()); } else { System.out.println("Sending player data. Size=" + msg.getPayloadSize()); out.writeByte(msg.getPayloadSize()); } out.writeBytes(msg.getPayload()); } }
From source file:net.ieldor.network.codec.worldlist.WorldListEncoder.java
License:Open Source License
@Override public void encode(ChannelHandlerContext ctx, WorldListMessage list, ByteBuf out) throws Exception { ByteBuf buf = Unpooled.buffer(); buf.writeByte(1);/* w w w. java 2s . c o m*/ buf.writeByte(1); Country[] countries = list.getCountries(); ByteBufUtils.writeSmart(buf, countries.length); for (Country country : countries) { ByteBufUtils.writeSmart(buf, country.getFlag()); ByteBufUtils.writeWorldListString(buf, country.getName()); } WorldData[] worlds = list.getWorlds(); int minId = worlds[0].getNodeId(); int maxId = worlds[0].getNodeId(); for (int i = 1; i < worlds.length; i++) { WorldData world = worlds[i]; int id = world.getNodeId(); if (id > maxId) maxId = id; if (id < minId) minId = id; } ByteBufUtils.writeSmart(buf, minId); ByteBufUtils.writeSmart(buf, maxId); ByteBufUtils.writeSmart(buf, worlds.length); for (WorldData world : worlds) { ByteBufUtils.writeSmart(buf, world.getNodeId() - minId); buf.writeByte(world.getCountry().getFlag()); buf.writeInt(world.getFlags()); ByteBufUtils.writeWorldListString(buf, world.getActivity()); ByteBufUtils.writeWorldListString(buf, world.getIp()); } buf.writeInt(list.getSessionId()); for (int i = 0; i < worlds.length; i++) { WorldData world = worlds[i]; ByteBufUtils.writeSmart(buf, world.getNodeId() - minId); buf.writeShort(0); } out.writeByte(0); // 0 = ok, 7/9 = world full out.writeShort(buf.readableBytes()); out.writeBytes(buf); }
From source file:net.ieldor.utility.flooder.FlooderChannelHandler.java
License:Open Source License
@Override public void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf buf) throws IOException { Channel channel = ctx.channel(); if (state == State.READ_SERVER_SESSION_KEY) { if (buf.readableBytes() >= 9) { if (buf.readUnsignedByte() != 0) throw new IOException("expecting EXCHANGE_KEYS opcode"); serverSessionKey = buf.readLong(); ByteBuf payload = Unpooled.buffer(); payload.writeInt(530);//w w w. j a va 2 s .co m payload.writeByte(0); payload.writeByte(0); payload.writeByte(0); payload.writeByte(0); payload.writeShort(765); payload.writeShort(503); payload.writeByte(0); for (int i = 0; i < 24; i++) payload.writeByte(0); ByteBufUtils.writeString(payload, "kKmok3kJqOeN6D3mDdihco3oPeYN2KFy6W5--vZUbNA"); payload.writeInt(0); payload.writeInt(0); payload.writeShort(0); for (int i = 0; i < 28; i++) { payload.writeInt(crc[i]); } payload.writeByte(10); payload.writeLong(clientSessionKey); payload.writeLong(serverSessionKey); payload.writeLong(encodedUsername); ByteBufUtils.writeString(payload, password); ByteBuf packet = Unpooled.buffer(); packet.writeByte(18); packet.writeShort(payload.readableBytes()); packet.writeBytes(payload); channel.write(packet); int[] seed = new int[4]; seed[0] = (int) (clientSessionKey >> 32); seed[1] = (int) clientSessionKey; seed[2] = (int) (serverSessionKey >> 32); seed[3] = (int) serverSessionKey; state = State.READ_LOGIN_STATUS; } } if (state == State.READ_LOGIN_STATUS) { if (buf.readable()) { int status = buf.readUnsignedByte(); if (status != 2) throw new IOException("expecting OK login response"); state = State.READ_LOGIN_PAYLOAD; } } if (state == State.READ_LOGIN_PAYLOAD) { if (buf.readableBytes() >= 11) { buf.readerIndex(buf.readerIndex() + 11); state = State.READ_GAME_OPCODE; } } if (state == State.READ_GAME_OPCODE) { } }