You are building a DTLS (Datagram Transport Layer Security) packet parser for Discord’s voice infrastructure. DTLS runs over UDP, so every UDP datagram may contain one or more DTLS records. Each record has a 13-byte header that starts with
0x16 0xfe 0xfd …
followed by epoch, sequence number, and length fields. The 2-byte big-endian length field tells you how many bytes of record payload follow the header. Records are laid out back-to-back in the datagram with no padding or alignment gaps.
Write a function
List<byte[]> parseDatagram(byte[] datagram)
that returns every complete DTLS record found in the datagram as a separate byte array (header + payload). If the datagram ends in the middle of a record header or in the middle of a declared payload, that partial record must be discarded. Return the list in the order the records appear. An empty datagram or one that contains no complete records must return an empty list.