encodeQueryGroup static method

String encodeQueryGroup(
  1. Map<String, String> group
)

Encodes a query group into a JSON-like representation.

Example:

final queryGroup = {
  'foo': 'bar',
  'baz': 'qux',
};

final encoded = FieldCodec.encodeQueryGroup(queryGroup);

print(encoded); // {foo:bar,baz:qux}

Implementation

static String encodeQueryGroup(Map<String, String> group) {
  final pairs = group.entries.map((entry) {
    // Both key and value are encoded to ensure that reserved
    // characters (e.g. `:`, `{`, `}` and `,`) are not misinterpreted.
    // For example, using a comma in a string value or a colon
    // in a date value would break the decoding process.
    final encodedKey = Uri.encodeComponent(entry.key);
    final encodedValue = Uri.encodeComponent(entry.value);

    return '$encodedKey:$encodedValue';
  });

  return '{${pairs.join(',')}}';
}