<commit_before>﻿using System;
using System.Collections.Generic;
using Google.Protobuf;

namespace Chinchilla.Serializers.Protobuf
{
    
    public class ProtobufMessageSerializer : IMessageSerializer
    {
        private class SerializerFunc
        {
            public SerializerFunc(Func<byte[], object> fromProto, Func<object, byte[]> toProto)
            {
                FromProto = fromProto;
                ToProto = toProto;
            }
            internal Func<byte[], object> FromProto { get; }
            internal Func<object, byte[]> ToProto { get; }
        }

        private Dictionary<Type, SerializerFunc> _cache = new Dictionary<Type, SerializerFunc>();

        private ProtobufMessageSerializer()
        {
        }
        
        public void Register<T>(MessageParser<T> parser) where T : Google.Protobuf.IMessage<T>
        {
            var toBytes = new Func<byte[], object>(b => parser.ParseFrom(b));
            var fromBytes = new Func<object, byte[]>(o => MessageExtensions.ToByteArray((T)o));
            if (!_cache.ContainsKey(typeof(T)))
            {
                _cache.Add(typeof(T), new SerializerFunc(toBytes, fromBytes));
            }
        }

        public static IMessageSerializer Create(Action<ProtobufMessageSerializer> create)
        {
            var s = new ProtobufMessageSerializer();
            create(s);
            return s;
        }

        public string ContentType { get; } = "application/x-protobuf";

        public IMessage<T> Deserialize<T>(byte[] message)
        {
            var typeSerializer = _cache[typeof(T)].FromProto; ;
            return Message.Create((T) typeSerializer(message));
        }

        public byte[] Serialize<T>(IMessage<T> message)
        {
            var typeSerializer = _cache[typeof(T)].ToProto;
            return typeSerializer(message.Body);
        }
    }
}<commit_msg>Clean up white spacing of in ProtobufMessageSerializer.cs<commit_after>﻿using Google.Protobuf;
using System;
using System.Collections.Generic;

namespace Chinchilla.Serializers.Protobuf
{
    public class ProtobufMessageSerializer : IMessageSerializer
    {
        private class SerializerFunc
        {
            public SerializerFunc(Func<byte[], object> fromProto, Func<object, byte[]> toProto)
            {
                FromProto = fromProto;
                ToProto = toProto;
            }

            internal Func<byte[], object> FromProto { get; }
            internal Func<object, byte[]> ToProto { get; }
        }

        private Dictionary<Type, SerializerFunc> _cache = new Dictionary<Type, SerializerFunc>();

        private ProtobufMessageSerializer()
        {
        }

        public void Register<T>(MessageParser<T> parser) where T : Google.Protobuf.IMessage<T>
        {
            var toBytes = new Func<byte[], object>(b => parser.ParseFrom(b));
            var fromBytes = new Func<object, byte[]>(o => MessageExtensions.ToByteArray((T)o));
            if (!_cache.ContainsKey(typeof(T)))
            {
                _cache.Add(typeof(T), new SerializerFunc(toBytes, fromBytes));
            }
        }

        public static IMessageSerializer Create(Action<ProtobufMessageSerializer> create)
        {
            var s = new ProtobufMessageSerializer();
            create(s);
            return s;
        }

        public string ContentType { get; } = "application/x-protobuf";

        public IMessage<T> Deserialize<T>(byte[] message)
        {
            var typeSerializer = _cache[typeof(T)].FromProto; ;
            return Message.Create((T)typeSerializer(message));
        }

        public byte[] Serialize<T>(IMessage<T> message)
        {
            var typeSerializer = _cache[typeof(T)].ToProto;
            return typeSerializer(message.Body);
        }
    }
}
{'fraction_non_alphanumeric': 0.10563564875491481, 'fraction_numerical': 0.0, 'mean_word_length': 2.1563275434243176, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 39, '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': '7659725', 'n_tokens_mistral': 1022, 'n_tokens_neox': 994, 'n_words': 217}