sanitizeMessagePack static method

Map<String, dynamic> sanitizeMessagePack(
  1. Map<String, dynamic> data
)

Sanitize the messagepack before sending it, removing canonical values.

Implementation

static Map<String, dynamic> sanitizeMessagePack(Map<String, dynamic> data) {
  // Sort the map alphabetically
  final sortedData = SplayTreeMap<String, dynamic>.from(data);

  // Sanitize the map and remove canonical values
  sortedData.removeWhere(
    (key, value) =>
        value == null ||
        value == false ||
        (value is Map && value.isEmpty) ||
        (value is List && value.isEmpty) ||
        (value is BigInt && value == BigInt.zero) ||
        (value is String && value.isEmpty || (value is int && value == 0)),
  );

  return sortedData;
}