@SuppressWarnings("unchecked") @Test public void testNullMap() throws Exception { Map<String, String> src = null; ByteArrayOutputStream out = new ByteArrayOutputStream(); new Packer(out).pack(src); byte[] bytes = out.toByteArray(); Template tmpl = null; Unpacker unpacker = new Unpacker(); Map<String, String> dst = null; try { tmpl = new MapTemplate(StringTemplate.getInstance(), StringTemplate.getInstance()); unpacker.wrap(bytes); dst = (Map<String, String>) tmpl.unpack(unpacker); fail(); } catch (Exception e) { assertTrue(e instanceof MessageTypeException); } unpacker.wrap(bytes); tmpl = new OptionalTemplate( new MapTemplate(StringTemplate.getInstance(), StringTemplate.getInstance())); dst = (Map<String, String>) tmpl.unpack(unpacker); assertEquals(src, dst); }
@Override public void messageUnpack(Unpacker unpacker) throws IOException, MessageTypeException { if (unpacker.tryUnpackNull()) { return; } unpacker.unpackArray(); f0 = unpacker.unpackInt(); f1 = unpacker.unpackInt(); }
@Test public void testNullLong() throws Exception { Long src = null; ByteArrayOutputStream out = new ByteArrayOutputStream(); new Packer(out).pack(src); byte[] bytes = out.toByteArray(); Template tmpl = null; Unpacker unpacker = new Unpacker(); Long dst = null; try { tmpl = LongTemplate.getInstance(); unpacker.wrap(bytes); dst = (Long) tmpl.unpack(unpacker); fail(); } catch (Exception e) { assertTrue(e instanceof MessageTypeException); } unpacker.wrap(bytes); tmpl = new OptionalTemplate(LongTemplate.getInstance()); dst = (Long) tmpl.unpack(unpacker); assertEquals(src, dst); }
public Object unpack(Unpacker pac) throws IOException, MessageTypeException { return pac.unpackFloat(); }