public static int encodeMap(String mapName, Map<String,?> map, ByteBuffer buffer) {
        if (map.isEmpty()) return 0;

        byte[] utf8 = Utf8.toBytes(mapName);
        buffer.putInt(utf8.length);
        buffer.put(utf8);
        buffer.putInt(map.size());
        for (Map.Entry<String, ?> entry : map.entrySet()) {
            String key = entry.getKey();
            utf8 = Utf8.toBytes(key);
            buffer.putInt(utf8.length);
            buffer.put(utf8);
            Object value = entry.getValue();
            utf8 = getUtf8(value);
            buffer.putInt(utf8.length);
            buffer.put(utf8);
        }

        return 1;
    }
Encodes a map as binary.
Does nothing if the value is null.

Returns the number of maps encoded - 0 or 1
container-search/src/main/java/com/yahoo/fs4/MapEncoder.java