Created
September 11, 2011 15:09
-
-
Save masayuki038/1209689 to your computer and use it in GitHub Desktop.
Serializing HashMap By MessagePack for Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testSerliazingMapByMessagePack(){ | |
Map<String, Object> map = new HashMap<String, Object>(); | |
map.put("int", 1); | |
map.put("long", 1L); | |
map.put("date", new Date()); | |
map.put("string", "test"); | |
byte[] buffer = MessagePack.pack(map); | |
for (byte b : buffer) { | |
System.out.print(Integer.toHexString(b & 0xFF) + " "); | |
} | |
System.out.println(); | |
System.out.println("buffer.length: " + buffer.length); | |
System.out.println(); | |
InputStream in = new ByteArrayInputStream(buffer); | |
Unpacker unpacker = new Unpacker(in); | |
for(Object obj : unpacker){ | |
MapType mapType = (MapType)obj; | |
Map<MessagePackObject, MessagePackObject> ret = mapType.asMap(); | |
for(MessagePackObject key : ret.keySet()){ | |
String keyStr = key.asString(); | |
Object value = ret.get(key); | |
System.out.println(String.format("%s: %s", keyStr, value)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Which msgpack version are you using ? @masayuki038