in blogs/sept-2021/converter.cc [106:142]
FieldValue Converter::ConvertAny(const Variant& from, bool within_array) const {
switch (from.type()) {
// Primitives -- one-to-one mapping.
case Variant::Type::kTypeNull:
return FieldValue::Null();
case Variant::Type::kTypeBool:
return FieldValue::Boolean(from.bool_value());
case Variant::Type::kTypeInt64:
return FieldValue::Integer(from.int64_value());
case Variant::Type::kTypeDouble:
return FieldValue::Double(from.double_value());
// Firestore does not have a distinction between static and mutable
// strings and blobs. In all cases, the resulting `FieldValue` has
// ownership of the underlying string or blob.
case Variant::Type::kTypeStaticString:
case Variant::Type::kTypeMutableString:
return FieldValue::String(from.string_value());
case Variant::Type::kTypeStaticBlob:
case Variant::Type::kTypeMutableBlob:
return FieldValue::Blob(from.blob_data(), from.blob_size());
// Containers are converted recursively.
case Variant::Type::kTypeVector:
return ConvertArray(from.vector(), within_array);
case Variant::Type::kTypeMap:
return ConvertMap(from.map());
default:
assert(false && "Unknown Variant type");
std::terminate();
}
}