-
Notifications
You must be signed in to change notification settings - Fork 0
SdpTransform
SDP parser and writer for .NET. Transforms between SDP text, an object graph, and JSON — useful for VoIP and WebRTC work.
dotnet add package Utilme.SdpTransform
Requires .NET 10, no dependencies.
using Utilme.SdpTransform;
Sdp? sdp = sdpText.ToSdp(); // null if it cannot be parsed
SdpParseResult result = sdpText.ToSdpResult(); // same, plus every problem foundToSdpResult never throws. IsValid says whether an Sdp was produced; Diagnostics carries a
Warning for each line that was skipped and an Error if parsing had to stop, each with the
1-based line number from the original text.
Three representations, converted by paired extension methods:
SDP text ⇄ object graph ⇄ JSON
using Utilme.SdpTransform;
var sdp = sdpText.ToSdp(); // text -> object
var text = sdp.ToText(); // object -> text
var json = JsonSerializer.Serialize(sdp, options);
var back = JsonSerializer.Deserialize<Sdp>(json)!.ToText();Two design points that are not obvious from the file layout:
-
Model classes carry their own grammar. Each model exposes
const stringtokens next to the properties they parse —Sdp.OriginIndicator = "o=",Candidate.Label = "candidate:". Parser and writer both consume these constants; SDP tokens are never hardcoded in the conversion code. -
All conversion lives in one file,
Extensions/ModelExtensions.cs, as pairedToXxx(this string)/ToText(this Xxx)methods.ToSdpandToTextare the two entry points.
Enums are double-annotated: [JsonStringEnumMemberName] for the JSON wire form, [Display] for the
SDP text form, converted through DisplayName() / EnumFromDisplayName<T>().
| Page | What's in it |
|---|---|
| Getting Started | Parsing, writing, JSON, diagnostics, gotchas |
| API Reference | Every public type and member |
| Design Notes | Why it looks like this; invariants to preserve |
| Refactor Log | What changed on the way to 26.9.7, and what is left |
Additive-only, the same guarantee as Utilme.Result, enforced by an approval test over the whole public surface. See Design Notes.
149 tests — see Building and Testing. They began as a characterization suite pinning existing behaviour, defects included, which is what made the refactor safe.
Utilme.Result
Utilme.SdpTransform
Repository