BosonWriter { public void writeMap(ByteBuf buffer, Map<?, ?> value) { buffer.writeByte(MAP); buffer.writeInt(value.size()); for (Object key : value.keySet()) { Object v = value.get(key); validateAndWriteType(buffer, key); validateAndWriteType(buffer, v); } } 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 testWriteMap() throws Exception { BosonWriter writer = new BosonWriter(); 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"); ByteBuf buf = Unpooled.buffer(); writer.writeMap(buf, map); assertEquals(MAP, buf.readByte()); assertEquals(3, buf.readInt()); assertEquals(STRING, buf.readByte()); }