<commit_before>use super::ipv4_header::IPv4Header;
use super::ipv4_packet::{IPv4Packet, MAX_PACKET_LENGTH};
use super::source_destination::SourceDestination;
use super::transport_header::TransportHeader;

pub struct Packetizer {
    buffer: Box<[u8; MAX_PACKET_LENGTH]>,
    payload_index: usize,
    ipv4_header: IPv4Header,
    transport_header: TransportHeader,
}

impl Packetizer {
    pub fn new(ipv4_packet: &IPv4Packet) -> Self {
        assert!(ipv4_packet.is_valid());
        let mut buffer = Box::new([0; MAX_PACKET_LENGTH]);

        let mut ipv4_header = ipv4_packet.ipv4_header.clone();
        let mut transport_header = ipv4_packet.transport_header.as_ref().unwrap().clone();

        let headers_length = ipv4_header.header_length as usize +
                             transport_header.get_header_length() as usize;
        &mut buffer[0..headers_length].copy_from_slice(&ipv4_packet.raw[0..headers_length]);

        ipv4_header.switch_source_and_destination(&mut buffer[..]);
        transport_header.switch_source_and_destination(&mut buffer[ipv4_header.header_length as usize..]);
        Self {
            buffer: buffer,
            payload_index: headers_length,
            ipv4_header: ipv4_header,
            transport_header: transport_header,
        }<commit_msg>Pass reference to headers separately<commit_after>use super::ipv4_header::IPv4Header;
use super::ipv4_packet::{IPv4Packet, MAX_PACKET_LENGTH};
use super::source_destination::SourceDestination;
use super::transport_header::TransportHeader;

pub struct Packetizer {
    buffer: Box<[u8; MAX_PACKET_LENGTH]>,
    payload_index: usize,
    ipv4_header: IPv4Header,
    transport_header: TransportHeader,
}

impl Packetizer {
    pub fn new(raw: &mut [u8], ipv4_header: &IPv4Header, transport_header: &TransportHeader) -> Self {
        let mut buffer = Box::new([0; MAX_PACKET_LENGTH]);

        let mut ipv4_header = ipv4_header.clone();
        let mut transport_header = transport_header.clone();

        let headers_length = ipv4_header.header_length as usize +
                             transport_header.get_header_length() as usize;
        &mut buffer[0..headers_length].copy_from_slice(&raw[0..headers_length]);

        ipv4_header.switch_source_and_destination(&mut buffer[..]);
        transport_header.switch_source_and_destination(&mut buffer[ipv4_header.header_length as usize..]);

        Self {
            buffer: buffer,
            payload_index: headers_length,
            ipv4_header: ipv4_header,
            transport_header: transport_header,
        }
{'fraction_non_alphanumeric': 0.10097087378640776, 'fraction_numerical': 0.016699029126213592, 'mean_word_length': 3.583629893238434, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5879698', 'n_tokens_mistral': 780, 'n_tokens_neox': 788, 'n_words': 142}