class SimpleMapSerializer {

    public byte[] encode(Map<String, String> map) throws SerializationException {
        if (map == null || map.isEmpty()) {
            return null;
        }
        UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream(64);
        try {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                /**
                 * 排除不写null作为key
                 */
                if (key != null && value != null) {
                    writeString(out, key);
                    writeString(out, value);
                }
            }
            return out.toByteArray();
        } catch (IOException ex) {
            throw new SerializationException(ex.getMessage(), ex);
        }
    }

}