Your question is Discord DTLS Buffer Processing. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Discord's voice transport may need to assemble ordered DTLS message payloads into fixed-size buffers. Each emitted fragment has a fixed DTLS record overhead, so a buffer can contain fewer payload bytes when it contains more fragments.
Implement pack_dtls_messages(messages, buffer_size, record_overhead). Process messages in order, fragmenting messages when necessary, and return the minimum number of buffers required.
messages is a list of non-negative integer payload lengths.buffer_size is the maximum number of bytes in every output buffer.record_overhead is the number of bytes added for each emitted fragment.[message_index, offset, length].offset is the payload offset within the original message, and length is the fragment payload length.record_overhead + length bytes, and each returned buffer must stay within buffer_size.Use a greedy strategy: fill the current buffer with the largest possible next fragment. Start a new buffer when the next fragment cannot fit.
def pack_dtls_messages(messages, buffer_size, record_overhead):