decode static method

Object? decode(
  1. Object? wire
)

Decodes a wire value supplied by a client for a write or filter.

Implementation

static Object? decode(Object? wire) {
  if (wire is! Map) return wire;
  final type = wire[typeKey];
  final v = wire['value'];
  switch (type) {
    case 'bigint' when v is String:
      return int.tryParse(v) ?? (throw _bad('Invalid bigint "$v"'));
    case 'real' when v is String:
      return double.tryParse(v) ?? (throw _bad('Invalid real "$v"'));
    case 'dateTime' when v is String:
      return DateTime.tryParse(v) ?? (throw _bad('Invalid dateTime "$v"'));
    case 'blob' when wire['base64'] is String:
      return base64Decode(wire['base64'] as String);
    case 'json':
      return v;
    case 'masked':
    case 'text' || 'blob' when wire['truncated'] == true:
      throw _bad('Masked or truncated values cannot be written back');
    default:
      throw _bad('Unsupported value type "$type"');
  }
}