// Copyright © WireMock.Net using System; using WireMock.Models; namespace WireMock.Matchers.Request; /// /// The request body Grpc ProtoBuf matcher. /// public class RequestMessageProtoBufMatcher : IRequestMatcher { /// /// The ProtoBufMatcher. /// public IProtoBufMatcher? Matcher { get; } /// /// Initializes a new instance of the class. /// /// The match behaviour. (default = "AcceptOnMatch") /// The Func to define the proto definitions as id or text. /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". /// The optional matcher to use to match the ProtoBuf as (json) object. public RequestMessageProtoBufMatcher(MatchBehaviour matchBehaviour, Func protoDefinition, string messageType, IObjectMatcher? matcher = null) { #if PROTOBUF Matcher = new ProtoBufMatcher(protoDefinition, messageType, matchBehaviour, matcher); #else throw new System.NotSupportedException("The ProtoBufMatcher can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower."); #endif } /// public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult) { var (score, exception) = GetMatchResult(requestMessage).Expand(); return requestMatchResult.AddScore(GetType(), score, exception); } private MatchResult GetMatchResult(IRequestMessage requestMessage) { return Matcher?.IsMatchAsync(requestMessage.BodyAsBytes).GetAwaiter().GetResult() ?? default; } }