BosonWriter { public ByteBuf serialize(Object msg) { ByteBuf buffer = Unpooled.buffer(); validateAndWriteType(buffer, msg); buffer.readerIndex(0); return buffer; } BosonWriter();  BosonWriter(Set<ReadMutator> mutators); ByteBuf serialize(Object msg); ByteBuf serialize(BosonMessage msg); void serializeResponse(ByteBuf buffer, BosonMessage msg); void serializeRequest(ByteBuf buffer, BosonMessage msg); void writeByte(ByteBuf buffer, byte b); void writeNull(ByteBuf buffer); void writeShort(ByteBuf buffer, short s); void writeInt(ByteBuf buffer, int i); void writeLong(ByteBuf buffer, long l); void writeFloat(ByteBuf buffer, float f); void writeDouble(ByteBuf buffer, double d); void writeBoolean(ByteBuf buffer, boolean b); void writeChar(ByteBuf buffer, char c); void writeString(ByteBuf buffer, String s); void writeEnum(ByteBuf buf, Enum param); void writeList(ByteBuf buffer, List<Object> value); void writeSet(ByteBuf buffer, Set<Object> value); void writeArray(ByteBuf buffer, Object[] value); void writeMap(ByteBuf buffer, Map<?, ?> value); void writePolo(ByteBuf buffer, Object obj, int ref); void validateAndWriteType(ByteBuf buffer, Object param); static final int MAX_RECURSION_DEPTH; static final Charset utf8; }
@Test public void testWriteReadMap() throws Exception { String intStr = "int"; Map<String, Map<String, Object>> map = new HashMap<>(); Map intMap = new HashMap<>(); Map longMap = new HashMap<>(); Map stringMap = new HashMap<>(); map.put("int", intMap); map.put("long", longMap); map.put("string", stringMap); intMap.put("a", 1); intMap.put("b", 2); longMap.put("a", 1L); longMap.put("b", 2L); longMap.put("c", 3L); stringMap.put("a", "a"); stringMap.put("b", "ab"); stringMap.put("c", "abc"); BosonMessage msg = new BosonMessage(new Object[]{ map }, "test"); BosonWriter writer = new BosonWriter(); BosonReader r = new BosonReader(); BosonMessage m = new BosonMessage(); ByteBuf buf = writer.serialize(msg); r.deSerialize(buf, m); assertEquals(map, m.arguments[0]); }
@Test public void testSerializingEnum() throws Exception { BosonWriter writer = new BosonWriter(); BosonReader reader = new BosonReader(); EnumEnclosingType obj = new EnumEnclosingType(SomeType.B); ByteBuf out = writer.serialize(obj); EnumEnclosingType in = reader.deSerialize(out); assertNotNull(in); assertEquals(obj.value, in.value); }
@Test public void testSerializingEnumInNestedPOLO() throws Exception { BosonWriter writer = new BosonWriter(); BosonReader reader = new BosonReader(); OuterEnclosingType obj = new OuterEnclosingType(); ByteBuf out = writer.serialize(obj); OuterEnclosingType in = reader.deSerialize(out); assertNotNull(in); assertEquals(obj.type.value, in.type.value); }
@Test public void testSerializeCircularReference() throws Exception { CircularReferenceB[] b = new CircularReferenceB[1]; for (int i = 0; i < b.length; i++) { b[i] = new CircularReferenceB(); b[i].init(); } BosonMessage original = new BosonMessage(b, "test", "callback"); BosonWriter writer = new BosonWriter(); ByteBuf obj = writer.serialize(original); BosonReader reader = new BosonReader(); BosonMessage msg = new BosonMessage(); reader.deSerialize(obj, msg); assertTrue("At least 1 instance required", original.arguments.length > 0); Object arg = original.arguments[0]; assertTrue("Must be instance of CircularReferenceB", arg instanceof CircularReferenceB); CircularReferenceB b1 = (CircularReferenceB) arg; assertNotNull("CircularReferenceA not initialized", b1.a); CircularReferenceA a1 = b1.a; assertNotNull("CircularReferenceB not initialized", a1.b); assertTrue("CircularReferenceB and CircularReferenceA are not equal", a1.b == b1); assertTrue("At least 1 instance required", msg.arguments.length > 0); Object arg1 = msg.arguments[0]; assertTrue("Must be instance of CircularReferenceB", arg1 instanceof CircularReferenceB); CircularReferenceB b2 = (CircularReferenceB) arg; assertNotNull("CircularReferenceA not initialized", b2.a); CircularReferenceA a2 = b2.a; assertNotNull("CircularReferenceB not initialized", a2.b); assertTrue("CircularReferenceB and CircularReferenceA are not equal", a2.b == b2); }
@Test public void testSerialize() throws Exception { }