Design Patterns¶
sip2json applies clean C++ design patterns to provide a fluent and intuitive API.
1. Builder Pattern (Method Chaining)¶
The sipmessage class supports method chaining for configuring headers, start lines, and content:
sipmessage msg("INVITE", "sip:alice@example.com", "call-id-100", 1);
msg.setHeader("From", "sip:bob@example.com")
.setHeader("To", "sip:alice@example.com")
.setHeader("User-Agent", "sip2json/2.0");
2. Strategy / Callback Pattern¶
Asynchronous stream parsing uses non-blocking callbacks for decoupled event handling:
sip2json::parseAsync(
startIt,
endIt,
[](sipmessage&& msg) {
// Message handler strategy
},
[](sip2jsonErrors& err, const std::string& info) {
// Error handler strategy
}
);
3. Data Transfer Object (DTO) & Type Conversions¶
sipmessage integrates natively with nlohmann::json via C++ standard to_json and from_json serializer functions, allowing implicit conversions: