public static Class<? extends DhtStorablePacket> decodePacketTypeCode(char packetTypeCode) { Class<? extends I2PBotePacket> packetType = I2PBotePacket.decodePacketTypeCode(packetTypeCode); if (packetType!=null && DhtStorablePacket.class.isAssignableFrom(packetType)) return packetType.asSubclass(DhtStorablePacket.class); else { log.debug("Invalid type code for DhtStorablePacket: <" + packetTypeCode + ">"); return null; } }
@Test public void testDecodePacketTypeCode() throws Exception { Field allPacketTypesField = I2PBotePacket.class.getDeclaredField("ALL_PACKET_TYPES"); allPacketTypesField.setAccessible(true); @SuppressWarnings("unchecked") Class<? extends I2PBotePacket>[] allPacketTypes = (Class<? extends I2PBotePacket>[])allPacketTypesField.get(null); for (Class<? extends I2PBotePacket> packetType: allPacketTypes) { TypeCode typeCode = packetType.getAnnotation(TypeCode.class); assertTrue(I2PBotePacket.decodePacketTypeCode(typeCode.value()).equals(packetType)); } } }