encode method
Serialise back to the wire.
Implementation
String encode() {
final sb = StringBuffer();
if (isRequest) {
sb.write('$method $requestUri SIP/2.0\r\n');
} else {
sb.write('SIP/2.0 $statusCode $reasonPhrase\r\n');
}
final hasContentLength = headers.any(
(h) => h.key.toLowerCase() == 'content-length',
);
for (final h in headers) {
sb.write('${h.key}: ${h.value}\r\n');
}
if (!hasContentLength) {
sb.write('Content-Length: ${body.length}\r\n');
}
sb.write('\r\n');
sb.write(body);
return sb.toString();
}