List of usage examples for io.netty.buffer ByteBuf writeLong
public abstract ByteBuf writeLong(long value);
From source file:net.hasor.rsf.remoting.transport.protocol.codec.RpcRequestProtocol.java
License:Apache License
/**encode Message to byte & write to network framework*/ public void encode(RequestSocketBlock reqMsg, ByteBuf buf) throws IOException { //* --------------------------------------------------------bytes =13 //* byte[1] version RSF(0xC1) buf.writeByte(reqMsg.getVersion());//from w w w. java2 s. c o m //* byte[8] requestID ID buf.writeLong(reqMsg.getRequestID()); //* byte[1] keepData ? buf.writeByte(0); //* byte[3] contentLength ?(max = 16MB) ByteBuf requestBody = this.encodeRequest(reqMsg); int bodyLength = requestBody.readableBytes(); bodyLength = (bodyLength << 8) >>> 8;//8??8??16777215? buf.writeMedium(bodyLength); // buf.writeBytes(requestBody); }
From source file:net.hasor.rsf.remoting.transport.protocol.codec.RpcResponseProtocol.java
License:Apache License
/**encode Message to byte & write to network framework*/ public void encode(ResponseSocketBlock resMsg, ByteBuf buf) throws IOException { ////from w w w.ja v a2 s. c o m //* --------------------------------------------------------bytes =13 //* byte[1] version RSF(0x81) buf.writeByte(resMsg.getVersion()); //* byte[8] requestID ID buf.writeLong(resMsg.getRequestID()); //* byte[1] keepData ? buf.writeByte(0); //* byte[3] contentLength ?(max = 16MB) ByteBuf responseBody = this.encodeResponse(resMsg); int bodyLength = responseBody.readableBytes(); bodyLength = (bodyLength << 8) >>> 8;//8??8??16777215? buf.writeMedium(bodyLength); // buf.writeBytes(responseBody); // }
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);//from w w w. ja v a2s. 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) { } }
From source file:net.malisis.advert.advert.ServerAdvert.java
License:Open Source License
public void toBytes(ByteBuf buf) { buf.writeInt(id);/*from ww w. j a v a2 s .c o m*/ ByteBufUtils.writeUTF8String(buf, name); ByteBufUtils.writeUTF8String(buf, url); ByteBufUtils.writeUTF8String(buf, hash != null ? hash : ""); buf.writeLong(size); buf.writeInt(width); buf.writeInt(height); }
From source file:net.malisis.switches.tileentity.SwitchTileEntity.java
License:Open Source License
@Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); ByteBuf bytes = Unpooled.buffer(linkedPos.size() * 8); for (BlockPos pos : linkedPos) bytes.writeLong(pos.toLong()); tag.setByteArray("linkedPos", bytes.array()); }
From source file:net.tridentsdk.data.Position.java
License:Open Source License
@Override public void write(ByteBuf buf) { buf.writeLong((long) ((int) this.loc.getX() & 0x3FFFFFF) << 38 | (long) ((int) this.loc.getY() & 0xFFF) << 26 | (long) ((int) this.loc.getZ() & 0x3FFFFFF)); }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutSpawnPlayer.java
License:Open Source License
@Override public void encode(ByteBuf buf) { Location loc = this.player.getLocation(); UUID id = this.player.getUniqueId(); Codec.writeVarInt32(buf, this.entityId); buf.writeLong(id.getMostSignificantBits()); buf.writeLong(id.getLeastSignificantBits()); buf.writeInt((int) loc.getX() * 32); buf.writeInt((int) loc.getY() * 32); buf.writeInt((int) loc.getZ() * 32); buf.writeByte((int) (byte) loc.getYaw()); buf.writeByte((int) (byte) loc.getPitch()); }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutSpawnPosition.java
License:Open Source License
@Override public void encode(ByteBuf buf) { buf.writeLong((long) (((int) this.location.getX() & 0x3FFFFFF) << 6 | ((int) this.location.getY() & 0xFFF) << 26 | (int) this.location.getZ() & 0x3FFFFFF)); }
From source file:net.tridentsdk.packets.play.out.PacketPlayOutTimeUpdate.java
License:Open Source License
@Override public void encode(ByteBuf buf) { buf.writeLong(this.worldAge); buf.writeLong(this.time); }
From source file:net.tridentsdk.packets.status.PacketStatusOutPing.java
License:Open Source License
@Override public void encode(ByteBuf buf) { buf.writeLong(this.clientTime); }