Adaptation of the core draft.
Also javadoc'd packet and packet_db, and optimized them a needless bit.