sip2json: A Focused SIP Parser for Modern C++¶
sip2json (v2.5.8-6) is a header-only Modern C++23 SIP protocol parser and serializer library designed with nlohmann::json as a first-class API metaphor for seamlessly converting SIP protocol messages to/from JSON for NoSQL databases and distributed event processing.
Design Objectives¶
- Header-Only Library: Easy integration without compiled binary dependencies; include and build.
- JSON as First-Class Metaphor: Compact and intuitive representation of SIP start lines, headers, and SDP bodies.
- Modern C++23: Built for C++23 standards using concepts, string views, move semantics, and CTRE (Compile-Time Regular Expressions).
- Asynchronous & Streaming Parsing: High-performance stream iterator parsing with non-blocking callbacks for multi-frame TCP buffers.
- Full SDP Support: Native decoding and encoding of Session Description Protocol (
application/sdp) payloads.
Quick Example¶
#include "siddiqsoft/sip2json.hpp"
using namespace siddiqsoft;
void processIncomingTcpData(std::string& readBuffer)
{
auto bufferStart = readBuffer.begin();
// Parses multiple SIP messages from buffer iterator asynchronously
sip2json::parseAsync(
bufferStart,
readBuffer.end(),
[](sipmessage&& msg) {
if (!msg.empty()) {
std::cout << "Received " << msg.method << " request for " << msg.uri << "\n";
}
},
[](sip2jsonErrors& errCode, const std::string& errMessage) {
std::cerr << "Parser warning/error: " << errMessage << "\n";
}
);
// Remove processed SIP frames from buffer
readBuffer.erase(readBuffer.begin(), bufferStart);
}
#include "siddiqsoft/sip2json.hpp"
using namespace siddiqsoft;
int main()
{
// Construct SIP INVITE request
sipmessage msg("INVITE", "sip:user@example.com", "call-8849-xyz", 1);
msg.setHeader("From", "sip:caller@example.com")
.setHeader("To", "sip:user@example.com")
.setHeader("User-Agent", "sip2json/2.0");
// Serialize to standard SIP string format
std::string rawSip = sip2json::serialize(msg);
std::cout << rawSip << std::endl;
return 0;
}
#include "siddiqsoft/sip2json.hpp"
using namespace siddiqsoft;
int main()
{
// Parse raw SIP string to sipmessage structure
sipmessage msg = sip2json::parse(rawSipString);
// Convert sipmessage directly to nlohmann::json representation
nlohmann::json doc = msg;
std::cout << "JSON document: " << doc.dump(2) << std::endl;
return 0;
}
Requirements¶
| Requirement | Details |
|---|---|
| Language Standard | C++23 (/std:c++latest on MSVC, -std=c++23 on Clang/GCC) |
| Dependencies | nlohmann/json v3.12.0+, ctre v3.11.0+ |
| Platform Support | Windows (MSVC 2022+), Linux (GCC 14+, Clang 17+), macOS (Apple Clang 15+) |
Navigation¶
- Features: Streaming parser, JSON schema, SDP body processing, and Standards Compliance.
- Integration: CMake CPM, Git submodules, and build setup.
- Architecture: Stateless design, iterator processing, and memory layout.
- API Reference: Comprehensive specifications for
sipmessage,sip2jsonmethods, and exceptions. - Examples: Sample applications and integration snippets.