< Summary - AsyncResponse (Release / net8.0+net10.0 / unit+integration)

Information
Class: AsyncResponse.RawJsonResponse
Assembly: AsyncResponse.Core
File(s): /_/src/AsyncResponse.Core/RawJsonResponse.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 51
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Json()100%11100%
DeserializeUntyped()100%22100%
Deserialize()100%11100%
Deserialize(...)100%11100%

File(s)

/_/src/AsyncResponse.Core/RawJsonResponse.cs

#LineLine coverage
 1namespace AsyncResponse;
 2
 3/// <summary>
 4/// Raw broker/webhook response payload that can be materialized into the active waiter's payload
 5/// type without first allocating an intermediate JsonElement.
 6/// </summary>
 7internal sealed class RawJsonResponse
 8{
 9    private readonly string _json;
 10
 11    // One instance is shared across every subscriber of a correlation id, and fan-out dispatch can
 12    // materialize payloads from multiple threads. TYPED payloads are deliberately NOT memoized:
 13    // handing one mutable payload instance to multiple same-type waiters would alias user state
 14    // across concurrently-running predicates and handlers — every durable channel deserializes a
 15    // private instance per waiter, and the in-memory raw path must match (wire parity, same rule
 16    // as the typed path's MaterializeAs). The untyped memo below stays: it materializes an
 17    // immutable JsonElement, so sharing it is safe; _gate guards its torn-publication hazard.
 30118    private readonly object _gate = new();
 19    private object? _untypedPayload;
 20    private bool _hasUntypedPayload;
 21
 22    /// <summary>Runs the RawJsonResponse operation.</summary>
 30123    public RawJsonResponse(string json)
 24    {
 30125        JsonSafety.ThrowIfClearlyNotJson(json);
 30126        _json = json;
 30127    }
 28
 229    public string Json => _json;
 30
 31    /// <summary>Runs the DeserializeUntyped operation.</summary>
 32    public object? DeserializeUntyped()
 33    {
 292634        lock (_gate)
 35        {
 292636            if (_hasUntypedPayload)
 270237                return _untypedPayload;
 38
 22439            _untypedPayload = JsonSafety.SafeDeserialize<object?>(_json);
 22440            _hasUntypedPayload = true;
 22441            return _untypedPayload;
 42        }
 292643    }
 44
 45    /// <summary>Runs the Deserialize operation.</summary>
 563146    public T? Deserialize<T>() => (T?)Deserialize(typeof(T));
 47
 48    /// <summary>Materializes a private payload instance per call — see the aliasing note above.</summary>
 49    public object? Deserialize(Type payloadType)
 563350        => JsonSafety.SafeDeserialize(_json, payloadType);
 51}