SocketAddressTemplate extends AbstractTemplate<SocketAddress> { @Override public SocketAddress read(Unpacker unpacker, SocketAddress endpoint, boolean required) throws IOException { unpacker.readArrayBegin(); String host = unpacker.readString(); int port = unpacker.readInt(); unpacker.readArrayEnd(); return new InetSocketAddress(host, port); } private  SocketAddressTemplate(); static Template<SocketAddress> getInstance(); @Override void write(Packer packer, SocketAddress endpoint, boolean required); @Override SocketAddress read(Unpacker unpacker, SocketAddress endpoint, boolean required);  }
@Test public void read() throws IOException { String host = "localhost"; int port = 3456; MessagePack pack = new MessagePack(); byte[] bytes = pack.write(Arrays.asList(host, port)); SocketAddress result = pack.read(bytes, SocketAddressTemplate.getInstance()); Assert.assertThat(result, new IsInstanceOf(InetSocketAddress.class)); Assert.assertEquals(host, ((InetSocketAddress) result).getHostName()); Assert.assertEquals(port, ((InetSocketAddress) result).getPort()); }