using Confluent.Kafka;

namespace JiShe.CollectBus.Kafka.Internal;

/// <summary>
///     消息头过滤器
/// </summary>
public class HeadersFilter : Dictionary<string, byte[]>
{
    /// <summary>
    ///     判断Headers是否匹配
    /// </summary>
    /// <param name="headers"></param>
    /// <returns></returns>
    public bool Match(Headers headers)
    {
        foreach (var kvp in this)
            if (!headers.TryGetLastBytes(kvp.Key, out var value) || !value.SequenceEqual(kvp.Value))
                return false;
        return true;
    }
}