<commit_before>﻿using RockLib.Compression;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace RockLib.Messaging
{
    /// <summary>
    /// A base class for implementations of the <see cref="IReceiverMessage"/> interface
    /// that handles binary/string encoding, compression, and provides a hook for header
    /// initialization.
    /// </summary>
    public abstract class ReceiverMessage : IReceiverMessage
    {
        private static readonly GZipDecompressor _gzip = new GZipDecompressor();

        private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);

        private readonly Lazy<string> _stringPayload;
        private readonly Lazy<byte[]> _binaryPayload;
        private readonly Lazy<HeaderDictionary> _headers;

        private string _handledBy;

        /// <summary>
        /// Initializes a new instance of the <see cref="ReceiverMessage"/> class using
        /// a raw string payload.
        /// </summary>
        /// <param name="getRawPayload">
        /// A function that returns the raw payload. Note that the <see cref="Payload"/> struct
        /// is implicitly convertable from the string and byte array types (i.e. this function
        /// can just return a string or byte array).
        /// </param>
        protected ReceiverMessage(Func<Payload> getRawPayload)
        {
            if (getRawPayload == null)
                throw new ArgumentNullException(nameof(getRawPayload));

            var rawPayload = new Lazy<object>(() => getRawPayload().Value
                ?? throw new InvalidOperationException("Cannot decode/decompress null payload."));

            _stringPayload = new Lazy<string>(() =>
            {
                if (rawPayload.Value is string stringPayload)
                {
                    if (this.IsCompressed())<commit_msg>Fix doc comment<commit_after>﻿using RockLib.Compression;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace RockLib.Messaging
{
    /// <summary>
    /// A base class for implementations of the <see cref="IReceiverMessage"/> interface
    /// that handles binary/string encoding, compression, and provides a hook for header
    /// initialization.
    /// </summary>
    public abstract class ReceiverMessage : IReceiverMessage
    {
        private static readonly GZipDecompressor _gzip = new GZipDecompressor();

        private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);

        private readonly Lazy<string> _stringPayload;
        private readonly Lazy<byte[]> _binaryPayload;
        private readonly Lazy<HeaderDictionary> _headers;

        private string _handledBy;

        /// <summary>
        /// Initializes a new instance of the <see cref="ReceiverMessage"/> class.
        /// </summary>
        /// <param name="getRawPayload">
        /// A function that returns the raw payload. Note that the <see cref="Payload"/> struct
        /// is implicitly convertable from the string and byte array types (i.e. this function
        /// can just return a string or byte array).
        /// </param>
        protected ReceiverMessage(Func<Payload> getRawPayload)
        {
            if (getRawPayload == null)
                throw new ArgumentNullException(nameof(getRawPayload));

            var rawPayload = new Lazy<object>(() => getRawPayload().Value
                ?? throw new InvalidOperationException("Cannot decode/decompress null payload."));

            _stringPayload = new Lazy<string>(() =>
            {
                if (rawPayload.Value is string stringPayload)
                {
                    if (this.IsCompressed())
{'fraction_non_alphanumeric': 0.09669012249152985, 'fraction_numerical': 0.0010424811050299713, 'mean_word_length': 2.4890909090909092, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 37, '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': '7132418', 'n_tokens_mistral': 959, 'n_tokens_neox': 928, 'n_words': 310}