public static PacketType validateHeader ( DatagramPacket packet , int port ) { byte [ ] data = packet . getData ( ) ; if ( data . length < PACKET_TYPE_OFFSET ) { logger . warn ( "Packet is too short to be a Pro DJ Link packet; must be at least " + PACKET_TYPE_OFFSET + " bytes long, was only " + data . length + "." ) ; return null ; } if ( ! getMagicHeader ( ) . equals ( ByteBuffer . wrap ( data , 0 , MAGIC_HEADER . length ) ) ) { logger . warn ( "Packet did not have correct nine-byte header for the Pro DJ Link protocol." ) ; return null ; } final Map < Byte , PacketType > portMap = PACKET_TYPE_MAP . get ( port ) ; if ( portMap == null ) { logger . warn ( "Do not know any Pro DJ Link packets that are received on port " + port + "." ) ; return null ; } final PacketType result = portMap . get ( data [ PACKET_TYPE_OFFSET ] ) ; if ( result == null ) { logger . warn ( "Do not know any Pro DJ Link packets received on port " + port + " with type " + String . format ( "0x%02x" , data [ PACKET_TYPE_OFFSET ] ) + "." ) ; } return result ; }
Check to see whether a packet starts with the standard header bytes followed by a known byte identifying it . If so return the kind of packet that has been recognized .