<commit_before>﻿using System;
using System.Net;

namespace BmpListener.Bgp
{
    public class IPAddrPrefix
    {
        public IPAddrPrefix(byte[] data, int offset, AddressFamily afi = AddressFamily.IP)
        {
            DecodeFromBytes(data, offset, afi);
        }

        internal int ByteLength { get { return 1 + (Length + 7) / 8; } }
        public int Length { get; private set; }
        public IPAddress Prefix { get; private set; }

        public override string ToString()
        {
            return ($"{Prefix}/{Length}");
        }

        public void DecodeFromBytes(byte[] data, int offset, AddressFamily afi = AddressFamily.IP)
        {
            Length = data[offset];
            var byteLength = (Length + 7) / 8;
            var ipBytes = afi == AddressFamily.IP
                ? new byte[4]
                : new byte[16];
            Array.Copy(data, offset + 1, ipBytes, 0, byteLength);
            Prefix = new IPAddress(ipBytes);
        }
    }
}<commit_msg>Return prefix and byte length<commit_after>﻿using System;
using System.Linq;
using System.Net;

namespace BmpListener.Bgp
{
    public class IPAddrPrefix
    {
        // RFC 4721 4.3
        // The Type field indicates the length in bits of the IP address prefix.
        public int Length { get; private set; }
        public IPAddress Prefix { get; private set; }

        public override string ToString()
        {
            return ($"{Prefix}/{Length}");
        }

        public static (IPAddrPrefix prefix, int byteLength) Decode(byte[] data, int offset, AddressFamily afi)
        {
            var bitLength = data[offset];
            var byteLength = (bitLength + 7) / 8;
            var ipBytes = afi == AddressFamily.IP
                ? new byte[4]
                : new byte[16];
            Array.Copy(data, offset + 1, ipBytes, 0, byteLength);
            var prefix = new IPAddress(ipBytes);
            var ipAddrPrefix = new IPAddrPrefix { Length = bitLength, Prefix = prefix };
            return (ipAddrPrefix, byteLength + 1);
        }

        public static (IPAddrPrefix prefix, int byteLength) Decode(ArraySegment<byte> data, int offset, AddressFamily afi)
        {
            byte bitLength = data.First();
            var ipBytes = afi == AddressFamily.IP
                ? new byte[4]
                : new byte[16];
            offset += data.Offset;
            return Decode(data.Array, data.Offset, afi);
        }
    }
}

{'fraction_non_alphanumeric': 0.09833401056481106, 'fraction_numerical': 0.010971149939049168, 'mean_word_length': 1.8561484918793503, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4210536', 'n_tokens_mistral': 701, 'n_tokens_neox': 666, 'n_words': 208}