List of usage examples for io.netty.buffer ByteBuf readLong
public abstract long readLong();
From source file:matteroverdrive.network.packet.bi.PacketWeaponTick.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { timestamp = buf.readLong(); if (buf.readBoolean()) { this.plasmaShot = new PacketFirePlasmaShot(); this.plasmaShot.fromBytes(buf); }/*from w ww .j a va 2 s. co m*/ }
From source file:matteroverdrive.starmap.data.TravelEvent.java
License:Open Source License
public void readFromBuffer(ByteBuf buf) { from = new GalacticPosition(buf); to = new GalacticPosition(buf); ship = ByteBufUtils.readItemStack(buf); timeLength = buf.readInt();/*w w w . ja v a2 s . c o m*/ timeStart = buf.readLong(); }
From source file:nenea.client.file.FileClientHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { System.out.println("channelRead0"); ByteBuf buf = (ByteBuf) msg; System.out.println(buf.readableBytes()); System.out.println(msg);// w w w .j a va 2s . co m System.out.println(buf.toString(CharsetUtil.UTF_8)); System.out.println((ByteBufUtil.hexDump(buf))); // byte[] msgg = buf.array(); // System.out.println(buf.readInt()); int header1 = buf.readInt(); String header2 = buf.readBytes(header1).toString(CharsetUtil.UTF_8); long header3 = buf.readLong(); System.err.println(header1); System.err.println(header2); System.err.println(header3); }
From source file:nenea.client.file.FileClientHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; // System.out.println((ByteBufUtil.hexDump(buf))); // ? ? ? //from w w w .jav a2s. co m if (!fileHeaderRead) { startTm = System.currentTimeMillis(); /* * if (buf.readableBytes() <= 20) { * System.out.println("buf.readableBytes() : " + buf.readableBytes() * + "?? ? 20? ?. "); return; } */ fileNameSize = buf.readInt(); if (fileNameSize >= 100 || fileNameSize < 0) { System.out.println("fileNameSize : " + fileNameSize); return; } fileName = buf.readBytes(fileNameSize).toString(CharsetUtil.UTF_8); fileSize = buf.readLong(); System.out.println( "fileSize : " + fileSize + ", fileName : " + fileName + ", fileNameSize" + fileNameSize); fileHeaderRead = true; localFileName = "D:\\nene_data\\" + System.currentTimeMillis() + fileName; recFile = new File(localFileName); fileOutputStream = new FileOutputStream(recFile); } int a = buf.readableBytes(); int b = (int) Math.min(fileSize - offset, a); // System.out.println("### readableBytes : " + a); // System.out.println("### to read bytes : " + b); // System.out.println("fileSize - offset : " + (fileSize - offset)); buf.readBytes(fileOutputStream, b); offset += b; // System.out.println("offset : " + offset); // ??? ? if (offset >= fileSize) { offset = 0; fileHeaderRead = false; if (fileOutputStream != null) fileOutputStream.close(); System.out.println("? : " + localFileName); System.out.println( "? : " + ((System.currentTimeMillis() - startTm) / 1000.0f) + ""); return; } }
From source file:nenea.client.operation.OperationClientHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; // System.out.println("? : " + (ByteBufUtil.hexDump(buf))); // ? ? //from w w w . j a v a2 s.c om if (!headerRead) { startTm = System.currentTimeMillis(); /* * if (buf.readableBytes() <= 20) { * System.out.println("buf.readableBytes() : " + buf.readableBytes() * + "?? ? 20? ?. "); return; } */ // 1. ? ? headerSize = buf.readInt(); if (headerSize >= 100 || headerSize < 0) { System.out.println("fileNameSize : " + headerSize); // System.out.println((ByteBufUtil.hexDump(buf))); return; } headerBody = buf.readBytes(headerSize).toString(CharsetUtil.UTF_8); dataSize = buf.readLong(); System.out.println( "headerSize : " + headerSize + ", headerBody : " + headerBody + ", dataSize : " + dataSize); headerRead = true; // 2. ? ? ? : operation or file if (headerBody.startsWith("OP")) { operationCode = headerBody; //} else if (headerBody.endsWith(".zip") || headerBody.endsWith(".txt") || headerBody.endsWith(".tar")) { } else if (true) { //? ? ? fileName = headerBody; localFileName = "D:\\nene_data\\" + ctx.channel().id() + System.currentTimeMillis() + fileName; recFile = new File(localFileName); fileOutputStream = new FileOutputStream(recFile); } else { System.err.println("? Header Body . : " + headerBody); return; } } int a = buf.readableBytes(); int b = (int) Math.min(dataSize - offset, a); System.out.println("ReadableBytes : " + a + ", To-Read Bytes : " + b); if (headerBody.startsWith("OP")) { operationData += buf.readBytes(b).toString(CharsetUtil.UTF_8); System.out.println("OP Data : " + operationData); offset += b; if (offset >= dataSize) { offset = 0; headerRead = false; System.out.println("OP Data : " + operationData); System.out.println( "OP Data : " + ((System.currentTimeMillis() - startTm) / 1000.0f) + ""); operationData = ""; return; } } else { buf.readBytes(fileOutputStream, b); offset += b; // System.out.println("offset : " + offset); // ??? ? if (offset >= dataSize) { offset = 0; headerRead = false; if (fileOutputStream != null) fileOutputStream.close(); System.out.println("? : " + localFileName); System.out.println( "? : " + ((System.currentTimeMillis() - startTm) / 1000.0f) + ""); return; } } }
From source file:net.doubledoordev.inventorylock.network.Reply.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { key = BlockPos.fromLong(buf.readLong()); int i = buf.readInt(); while (i-- > 0) value.add(ByteBufUtils.readUTF8String(buf)); pub = buf.readBoolean();/*ww w.ja v a2 s .c o m*/ }
From source file:net.doubledoordev.inventorylock.network.Request.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { key = BlockPos.fromLong(buf.readLong()); }
From source file:net.hasor.rsf.protocol.rsf.RsfDecoder.java
License:Apache License
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; }//from w w w . ja v a 2 s . co m // byte rsfHead = frame.getByte(0);//?? short status = this.doDecode(rsfHead, ctx, frame);//??? if (status != ProtocolStatus.OK) { frame = frame.resetReaderIndex().skipBytes(1); long requestID = frame.readLong(); ResponseInfo info = ProtocolUtils.buildResponseStatus(this.rsfEnvironment, requestID, status, null); ctx.pipeline().writeAndFlush(info); } return null; }
From source file:net.hasor.rsf.protocol.rsf.v1.RpcRequestProtocolV1.java
License:Apache License
/**decode stream to object*/ public RequestBlock decode(ByteBuf buf) throws IOException { //* --------------------------------------------------------bytes =13 //* byte[1] version RSF(0xC1) byte rsfHead = buf.readByte(); //* byte[8] requestID ?ID long requestID = buf.readLong(); //* byte[1] keepData ? buf.skipBytes(1);/*from www.ja v a2 s . c o m*/ //* byte[3] contentLength ? buf.skipBytes(3);//.readUnsignedMedium() // RequestBlock req = new RequestBlock(); req.setHead(rsfHead); req.setRequestID(requestID); //* --------------------------------------------------------bytes =14 //* byte[2] servicesName-(attr-index) ??? req.setServiceName(buf.readShort()); //* byte[2] servicesGroup-(attr-index) ? req.setServiceGroup(buf.readShort()); //* byte[2] servicesVersion-(attr-index) ? req.setServiceVersion(buf.readShort()); //* byte[2] servicesMethod-(attr-index) ??? req.setTargetMethod(buf.readShort()); //* byte[2] serializeType-(attr-index) ? req.setSerializeType(buf.readShort()); //* byte[4] clientTimeout req.setClientTimeout(buf.readInt()); //* --------------------------------------------------------bytes =1 ~ 1021 //* byte[1] paramCount ? byte paramCount = buf.readByte(); for (int i = 0; i < paramCount; i++) { //* byte[4] ptype-0-(attr-index,attr-index) ? int mergeData = buf.readInt(); req.addParameter(mergeData); } //* --------------------------------------------------------bytes =1 ~ 1021 //* byte[1] optionCount ? byte optionCount = buf.readByte(); for (int i = 0; i < optionCount; i++) { //* byte[4] attr-0-(attr-index,attr-index) ? int mergeData = buf.readInt(); req.addOption(mergeData); } //* --------------------------------------------------------bytes =n //* dataBody ? req.fillFrom(buf); return req; }
From source file:net.hasor.rsf.protocol.rsf.v1.RpcResponseProtocolV1.java
License:Apache License
/**decode stream to object*/ public ResponseBlock decode(ByteBuf buf) throws IOException { //* --------------------------------------------------------bytes =13 //* byte[1] version RSF byte version = buf.readByte(); //* byte[8] requestID ?ID long requestID = buf.readLong(); //* byte[1] keepData ? buf.skipBytes(1);// www .j a va2s.c o m //* byte[3] contentLength ? buf.skipBytes(3);//.readUnsignedMedium() // ResponseBlock res = new ResponseBlock(); res.setHead(version); res.setRequestID(requestID); //* --------------------------------------------------------bytes =8 //* byte[2] status ?? res.setStatus(buf.readShort()); //* byte[2] serializeType-(attr-index) ? res.setSerializeType(buf.readShort()); //* byte[2] returnData-(attr-index) ? res.setReturnData(buf.readShort()); //* --------------------------------------------------------bytes =1 ~ 1021 //* byte[1] optionCount ? byte optionCount = buf.readByte(); for (int i = 0; i < optionCount; i++) { //* byte[4] attr-0-(attr-index,attr-index) ? int mergeData = buf.readInt(); res.addOption(mergeData); } //* --------------------------------------------------------bytes =n //* dataBody ? res.fillFrom(buf); return res; }