serialize method

Uint8Buffer serialize()

To byte buffer Complete serialization of the properties including the property length bytes

Implementation

typed.Uint8Buffer serialize() {
  final buffer = typed.Uint8Buffer();
  final stream = MqttByteBuffer(buffer);
  // Empty check
  if (_container.isEmpty && _userProperties.isEmpty) {
    return _enc.fromInt(0);
  }
  for (var property in _container.values) {
    property.writeTo(stream);
  }
  for (var property in _userProperties) {
    property.writeTo(stream);
  }
  final length = stream.length;
  final out = _enc.fromInt(length);
  return out..addAll(stream.buffer!);
}