List of usage examples for io.netty.buffer ByteBuf getBytes
public abstract int getBytes(int index, GatheringByteChannel out, int length) throws IOException;
From source file:se.sics.nstream.torrent.conn.msg.NetOpenTransferSerializerTest.java
License:Open Source License
@Test public void simpleResp() { Serializer serializer = Serializers.lookupSerializer(NetOpenTransfer.Response.class); NetTransferDefResponseEC ec = new NetTransferDefResponseEC(); NetOpenTransfer.Response original, copy; ByteBuf serializedOriginal, serializedCopy; NetOpenTransfer.Request request = new NetOpenTransfer.Request( TorrentIds.fileId(overlayIdFactory.randomId(), 1)); original = request.answer(true);/*from www . j av a 2s . c o m*/ serializedOriginal = Unpooled.buffer(); serializer.toBinary(original, serializedOriginal); serializedCopy = Unpooled.buffer(); serializedOriginal.getBytes(0, serializedCopy, serializedOriginal.readableBytes()); copy = (NetOpenTransfer.Response) serializer.fromBinary(serializedCopy, Optional.absent()); Assert.assertTrue(ec.isEqual(original, copy)); Assert.assertEquals(0, serializedCopy.readableBytes()); }
From source file:se.sics.nstream.torrent.FileIdentifierSerializerTest.java
License:Open Source License
@Test public void simpleTest() { Serializer serializer = Serializers.lookupSerializer(FileId.class); FileId original, copy;//from w w w . j ava 2 s . c o m ByteBuf serializedOriginal, serializedCopy; original = TorrentIds.fileId(overlayIdFactory.randomId(), 1); serializedOriginal = Unpooled.buffer(); serializer.toBinary(original, serializedOriginal); serializedCopy = Unpooled.buffer(); serializedOriginal.getBytes(0, serializedCopy, serializedOriginal.readableBytes()); copy = (FileId) serializer.fromBinary(serializedCopy, Optional.absent()); Assert.assertEquals(original, copy); Assert.assertEquals(0, serializedCopy.readableBytes()); }
From source file:se.sics.nstream.torrent.transfer.msg.CacheHintSerializerTest.java
License:Open Source License
@Test public void simpleReq() { Serializer serializer = Serializers.lookupSerializer(CacheHint.Request.class); CacheHintRequestEC ec = new CacheHintRequestEC(); CacheHint.Request original, copy; ByteBuf serializedOriginal, serializedCopy; Set<Integer> blocks = new TreeSet<>(); blocks.add(0);// w ww . j a v a 2 s . c o m blocks.add(1); KHint.Summary cacheHint = new KHint.Summary(1l, blocks); original = new CacheHint.Request(TorrentIds.fileId(overlayIdFactory.randomId(), 2), cacheHint); serializedOriginal = Unpooled.buffer(); serializer.toBinary(original, serializedOriginal); serializedCopy = Unpooled.buffer(); serializedOriginal.getBytes(0, serializedCopy, serializedOriginal.readableBytes()); copy = (CacheHint.Request) serializer.fromBinary(serializedCopy, Optional.absent()); Assert.assertTrue(ec.isEqual(original, copy)); Assert.assertEquals(0, serializedCopy.readableBytes()); }
From source file:se.sics.nstream.torrent.transfer.msg.CacheHintSerializerTest.java
License:Open Source License
@Test public void simpleResp() { Serializer serializer = Serializers.lookupSerializer(CacheHint.Response.class); CacheHintResponseEC ec = new CacheHintResponseEC(); CacheHint.Response original, copy; ByteBuf serializedOriginal, serializedCopy; Set<Integer> blocks = new TreeSet<>(); blocks.add(0);//w ww .j a v a2s .com blocks.add(1); KHint.Summary cacheHint = new KHint.Summary(1l, blocks); CacheHint.Request request = new CacheHint.Request(TorrentIds.fileId(overlayIdFactory.randomId(), 2), cacheHint); original = request.success(); serializedOriginal = Unpooled.buffer(); serializer.toBinary(original, serializedOriginal); serializedCopy = Unpooled.buffer(); serializedOriginal.getBytes(0, serializedCopy, serializedOriginal.readableBytes()); copy = (CacheHint.Response) serializer.fromBinary(serializedCopy, Optional.absent()); Assert.assertTrue(ec.isEqual(original, copy)); Assert.assertEquals(0, serializedCopy.readableBytes()); }
From source file:se.sics.nstream.torrent.transfer.msg.DownloadHashSerializerTest.java
License:Open Source License
@Test public void simpleReq() { Serializer serializer = Serializers.lookupSerializer(DownloadHash.Request.class); DownloadHashRequestEC ec = new DownloadHashRequestEC(); DownloadHash.Request original, copy; ByteBuf serializedOriginal, serializedCopy; Set<Integer> hashes = new TreeSet<>(); hashes.add(1);/*from w ww . ja v a 2 s . c om*/ hashes.add(2); original = new DownloadHash.Request(TorrentIds.fileId(overlayIdFactory.randomId(), 2), hashes); serializedOriginal = Unpooled.buffer(); serializer.toBinary(original, serializedOriginal); serializedCopy = Unpooled.buffer(); serializedOriginal.getBytes(0, serializedCopy, serializedOriginal.readableBytes()); copy = (DownloadHash.Request) serializer.fromBinary(serializedCopy, Optional.absent()); Assert.assertTrue(ec.isEqual(original, copy)); Assert.assertEquals(0, serializedCopy.readableBytes()); }
From source file:se.sics.nstream.torrent.transfer.msg.DownloadHashSerializerTest.java
License:Open Source License
@Test public void simpleResp() { Serializer serializer = Serializers.lookupSerializer(DownloadHash.Response.class); DownloadHashResponseEC ec = new DownloadHashResponseEC(); DownloadHash.Response original, copy; ByteBuf serializedOriginal, serializedCopy; Set<Integer> hashes = new TreeSet<>(); hashes.add(1);//from w w w.j a va2 s.com hashes.add(2); DownloadHash.Request request = new DownloadHash.Request(TorrentIds.fileId(overlayIdFactory.randomId(), 2), hashes); Map<Integer, byte[]> hashValues = new TreeMap<>(); hashValues.put(1, new byte[] { 1, 2, 3, 4 }); hashValues.put(2, new byte[] { 1, 2, 3, 4, 5 }); original = request.success(hashValues); serializedOriginal = Unpooled.buffer(); serializer.toBinary(original, serializedOriginal); serializedCopy = Unpooled.buffer(); serializedOriginal.getBytes(0, serializedCopy, serializedOriginal.readableBytes()); copy = (DownloadHash.Response) serializer.fromBinary(serializedCopy, Optional.absent()); Assert.assertTrue(ec.isEqual(original, copy)); Assert.assertEquals(0, serializedCopy.readableBytes()); }
From source file:se.sics.nstream.torrent.transfer.msg.DownloadPieceSerializerTest.java
License:Open Source License
@Test public void simpleReq() { Serializer serializer = Serializers.lookupSerializer(DownloadPiece.Request.class); DownloadPieceRequestEC ec = new DownloadPieceRequestEC(); DownloadPiece.Request original, copy; ByteBuf serializedOriginal, serializedCopy; original = new DownloadPiece.Request(TorrentIds.fileId(overlayIdFactory.randomId(), 2), Pair.with(1, 2)); serializedOriginal = Unpooled.buffer(); serializer.toBinary(original, serializedOriginal); serializedCopy = Unpooled.buffer();/*w w w. j a v a 2s . co m*/ serializedOriginal.getBytes(0, serializedCopy, serializedOriginal.readableBytes()); copy = (DownloadPiece.Request) serializer.fromBinary(serializedCopy, Optional.absent()); Assert.assertTrue(ec.isEqual(original, copy)); Assert.assertEquals(0, serializedCopy.readableBytes()); }
From source file:se.sics.nstream.torrent.transfer.msg.DownloadPieceSerializerTest.java
License:Open Source License
@Test public void simpleResp() { Serializer serializer = Serializers.lookupSerializer(DownloadPiece.Response.class); DownloadPieceResponseEC ec = new DownloadPieceResponseEC(); DownloadPiece.Response original, copy; ByteBuf serializedOriginal, serializedCopy; DownloadPiece.Request request = new DownloadPiece.Request(TorrentIds.fileId(overlayIdFactory.randomId(), 2), Pair.with(1, 2));//from www. j a v a2 s . c o m byte[] piece = new byte[] { 1, 2, 3, 4 }; KReference<byte[]> ref = KReferenceFactory.getReference(piece); ref.retain(); //serializer releases the ref and we cannot compare with it anymore original = request.success(ref); serializedOriginal = Unpooled.buffer(); serializer.toBinary(original, serializedOriginal); serializedCopy = Unpooled.buffer(); serializedOriginal.getBytes(0, serializedCopy, serializedOriginal.readableBytes()); copy = (DownloadPiece.Response) serializer.fromBinary(serializedCopy, Optional.absent()); Assert.assertTrue(ec.isEqual(original, copy)); Assert.assertEquals(0, serializedCopy.readableBytes()); }
From source file:se.sics.nstream.util.BlockDetailsSerializerTest.java
License:Open Source License
@Test public void simpleTest() { Serializer serializer = Serializers.lookupSerializer(BlockDetails.class); BlockDetailsEqc eqc = new BlockDetailsEqc(); BlockDetails original, copy;// w w w . j a va 2s . c o m ByteBuf serializedOriginal, serializedCopy; original = new BlockDetails(10, 10, 10, 10); serializedOriginal = Unpooled.buffer(); serializer.toBinary(original, serializedOriginal); serializedCopy = Unpooled.buffer(); serializedOriginal.getBytes(0, serializedCopy, serializedOriginal.readableBytes()); copy = (BlockDetails) serializer.fromBinary(serializedCopy, Optional.absent()); Assert.assertTrue(eqc.isEqual(original, copy)); Assert.assertEquals(0, serializedCopy.readableBytes()); }