public static Deserializer<? extends IP> deserializer() {
        return (data, offset, length) -> {
            final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
            byte version = (byte) (bb.get() >> 4 & 0xf);

            switch (version) {
                case 4:
                    return IPv4.deserializer().deserialize(data, offset, length);
                case 6:
                    return IPv6.deserializer().deserialize(data, offset, length);
                default:
                    throw new DeserializationException("Invalid IP version");
            }
        };
    }
@Test(expected = DeserializationException.class)
    public void testBadIpVersion() throws Exception {
        Deserializer ipDeserializer = IP.deserializer();
        ipDeserializer.deserialize(badHeaderBytes, 0, badHeaderLength * 4);
    }