List of usage examples for io.netty.buffer Unpooled buffer
public static ByteBuf buffer()
From source file:divconq.test.TestYaml.java
License:Open Source License
public static void testSerial() { ByteBuf bb = Unpooled.buffer(); CompositeToBufferBuilder sb = new CompositeToBufferBuilder(bb); try {/*from ww w .j a va 2 s . c o m*/ /* sb.startList(); sb.startList(); sb.value("a"); //sb.value(null); //sb.value("b"); sb.endList(); sb.value("c"); sb.startList(); sb.value(null); sb.endList(); sb.endList(); */ sb.startList(); sb.startList(); sb.startList(); sb.value("a"); sb.value("b"); sb.endList(); sb.value(null); sb.value(22); sb.value(2.2); sb.startList(); sb.value(2.2); sb.value(null); sb.value(22); sb.endList(); sb.endList(); sb.startRecord(); sb.field("Name", "ted"); sb.field("Age", 7); sb.field("DOB", new DateTime(1998, 8, 3, 17, 12)); sb.field("Sex", "m"); sb.field("Software"); sb.startList(); sb.value("Afterstep <& or \""); sb.value( "CTWM this is an abcdefghijklmnopqrstuvwxy is an abcdefghijklmnopqrstuvwxy is /> an abcdefghijklmnopqrstuvwxy is \nan abcdefghijklmnopqrstuvwxy is \tan abcdefghijklmnopqrstuvwxy"); sb.value("Oroborus"); sb.endList(); sb.field("Friends"); sb.startList(); sb.startRecord(); sb.field("Name", "macy"); sb.field("Age", 6); sb.field("Sex", "f"); sb.endRecord(); sb.startRecord(); sb.field("Name", "rich"); sb.field("Age", 7); sb.field("Sex", "m"); sb.field("Foods"); sb.startList(); sb.value("Apple"); sb.value("Cookie"); sb.endList(); sb.endRecord(); sb.endList(); sb.endRecord(); sb.startRecord(); sb.field("Name", "kathy"); sb.field("Father"); sb.startRecord(); sb.field("Name", "Ted"); sb.field("Age", 29); sb.endRecord(); sb.field("Age"); sb.field("DOB", new DateTime(1994, 3, 13, 8, 55)); sb.field("Sex", "f"); sb.endRecord(); sb.endList(); } catch (Exception x) { System.out.println("builder error: " + sb); } System.out.println("built:\n" + Utf8Decoder.decode(bb)); ListStruct list = (ListStruct) sb.toLocal(); System.out.println(); System.out.println("item 2 name: " + list.getItemAsRecord(1).getFieldAsString("Name")); //System.out.println("item 2: " + list.getItem(1)); System.out.println(); System.out.println(list.toPrettyString()); System.exit(0); }
From source file:dodo.network.netty.DodoMessageUtilsTest.java
License:Apache License
@Test public void testEncodeMessage() { ByteBuf encoded = Unpooled.buffer(); Map<String, Object> pp = new HashMap<>(); pp.put("1", 1); pp.put("2", 2L); pp.put("3", "3"); Map<String, Object> pp_map = new HashMap<>(); pp.put("pp_map", pp_map); pp_map.put("m1", 1); pp_map.put("m2", 2L); pp_map.put("m3", "3"); Set<Object> pp_set = new HashSet<>(); pp.put("pp_set", pp_set); pp_set.add(1);/* w w w . j av a 2 s . c o m*/ pp_set.add(2L); pp_set.add("3"); Set<Object> runningTasks = new HashSet<>(); runningTasks.add(null); runningTasks.add(Integer.valueOf(1)); runningTasks.add(Long.valueOf(1)); runningTasks.add("teststring"); pp.put("4", runningTasks); Map<String, Object> tags = new HashMap<>(); tags.put("a", null); tags.put("b", Integer.valueOf(1)); tags.put("c", Long.valueOf(1)); tags.put("d", "teststring"); pp.put("5", tags); Message m = new Message("a", Message.TYPE_KILL_WORKER, pp); m.replyMessageId = "b"; m.messageId = "c"; DodoMessageUtils.encodeMessage(encoded, m); Message read = DodoMessageUtils.decodeMessage(encoded); System.out.println("read.parameters:" + read.parameters); assertEquals(read.messageId, m.messageId); assertEquals(read.replyMessageId, m.replyMessageId); assertEquals(read.workerProcessId, m.workerProcessId); assertEquals(read.parameters.size(), m.parameters.size()); assertEquals(read.parameters.get("1"), m.parameters.get("1")); assertEquals(read.parameters.get("2"), m.parameters.get("2")); assertEquals(read.parameters.get("3"), m.parameters.get("3")); assertEquals(read.parameters.get("4"), m.parameters.get("4")); assertEquals(read.parameters.get("5"), m.parameters.get("5")); assertEquals(read.parameters.get("pp_map"), m.parameters.get("pp_map")); assertEquals(read.parameters.get("pp_set"), m.parameters.get("pp_set")); }
From source file:growthcraft.core.common.tileentity.GrcBaseTile.java
License:Open Source License
@Override public Packet getDescriptionPacket() { final NBTTagCompound data = new NBTTagCompound(); final ByteBuf stream = Unpooled.buffer(); try {/*from w ww .j a v a 2s. com*/ writeToStream(stream); if (stream.readableBytes() == 0) { return null; } } catch (Throwable t) { System.err.println(t); } // P, for payload data.setByteArray("P", stream.array()); return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 127, data); }
From source file:hellfirepvp.astralsorcery.common.event.listener.EventHandlerNetwork.java
License:Open Source License
@SubscribeEvent public void onLoginEarly(FMLNetworkEvent.ServerConnectionFromClientEvent event) { PacketBuffer buf = new PacketBuffer(Unpooled.buffer()); List<Integer> dimensions = ((DataWorldSkyHandlers) SyncDataHolder .getDataServer(SyncDataHolder.DATA_SKY_HANDLERS)).getSkyHandlerDimensions(); buf.writeInt(dimensions.size());/*from w w w. j ava 2 s. c om*/ for (int i : dimensions) { buf.writeInt(i); } event.getManager().sendPacket(new SPacketCustomPayload(AS_WORLDHANDLERS_PAYLOAD, buf)); }