extractEJson static method

BsonBinaryData extractEJson(
  1. Map<String, dynamic> eJsonMap
)

Implementation

static BsonBinaryData extractEJson(Map<String, dynamic> eJsonMap) {
  var entry = eJsonMap.entries.first;
  if (entry.key != type$binary) {
    throw ArgumentError(
        'The received Map is not a valid EJson Binary representation');
  }
  if (entry.value['base64'] is! String || entry.value['subType'] is! String) {
    throw ArgumentError(
        'The received Map is not a valid EJson Binary representation');
  }
  var content = entry.value as Map<String, Object>;
  if (content.containsKey('base64') && content.containsKey('subType')) {
    String key = content['base64'] as String;
    String type = content['subType'] as String;

    var uint8List = base64Decode(key);
    int locSubType = int.parse(type, radix: 16);
    return BsonBinaryData(uint8List, locSubType);
  }
  throw ArgumentError(
      'The received Map is not a avalid EJson Binary representation');
}