decode static method

Strictly decodes exact canonical V1 UTF-8 JSON bytes.

Duplicate object keys are rejected by the byte parser before any map is materialized. The decoded value is then re-encoded and must match the input byte-for-byte, so whitespace and noncanonical ordering fail closed.

Implementation

static FlowExperimentClientContractV1 decode(List<int> bytes) {
  try {
    final frozenBytes = Uint8List.fromList(bytes);
    final parsed = _StrictJsonParser(frozenBytes).parse();
    final root = _asJsonObject(parsed, r'$');
    final contract = _decodeClientContract(root);
    if (!_bytesEqual(frozenBytes, contract.canonicalBytes)) {
      throw const FormatException(
        'Flow experiment contract is not exact canonical JSON.',
      );
    }
    return contract;
  } on FormatException {
    rethrow;
  } on Object catch (error) {
    throw FormatException('Invalid flow experiment contract: $error');
  }
}