@@ -41,9 +41,10 @@ ObjectMetadata ObjectMetadata::ParseFromJson(internal::nl::json const& json) {
4141 result.crc32c_ = json.value (" crc32c" , " " );
4242 if (json.count (" customerEncryption" ) != 0 ) {
4343 auto field = json[" customerEncryption" ];
44- result.customer_encryption_ .encryption_algorithm =
45- field.value (" encryptionAlgorithm" , " " );
46- result.customer_encryption_ .key_sha256 = field.value (" keySha256" , " " );
44+ CustomerEncryption e;
45+ e.encryption_algorithm = field.value (" encryptionAlgorithm" , " " );
46+ e.key_sha256 = field.value (" keySha256" , " " );
47+ result.customer_encryption_ = std::move (e);
4748 }
4849 result.generation_ = internal::ParseLongField (json, " generation" );
4950 result.kms_key_name_ = json.value (" kmsKeyName" , " " );
@@ -76,10 +77,7 @@ bool ObjectMetadata::operator==(ObjectMetadata const& rhs) const {
7677 content_encoding_ == rhs.content_encoding_ and
7778 content_language_ == rhs.content_language_ and
7879 content_type_ == rhs.content_type_ and crc32c_ == rhs.crc32c_ and
79- customer_encryption_.encryption_algorithm ==
80- rhs.customer_encryption_ .encryption_algorithm and
81- customer_encryption_.key_sha256 ==
82- rhs.customer_encryption_ .key_sha256 and
80+ customer_encryption_ == customer_encryption_ and
8381 generation_ == rhs.generation_ and
8482 kms_key_name_ == rhs.kms_key_name_ and md5_hash_ == rhs.md5_hash_ and
8583 media_link_ == rhs.media_link_ and metadata_ == rhs.metadata_ and
@@ -102,23 +100,32 @@ std::ostream& operator<<(std::ostream& os, ObjectMetadata const& rhs) {
102100 << " , content_disposition=" << rhs.content_disposition ()
103101 << " , content_encoding=" << rhs.content_encoding ()
104102 << " , content_language=" << rhs.content_language ()
105- << " , content_type=" << rhs.content_type () << " , crc32c=" << rhs.crc32c ()
106- << " , customer_encryption.encryption_algorithm="
107- << rhs.customer_encryption ().encryption_algorithm
108- << " , customer_encryption.key_sha256="
109- << rhs.customer_encryption ().key_sha256 << " , etag=" << rhs.etag ()
110- << " , generation=" << rhs.generation () << " , id=" << rhs.id ()
111- << " , kind=" << rhs.kind () << " , kms_key_name=" << rhs.kms_key_name ()
103+ << " , content_type=" << rhs.content_type () << " , crc32c=" << rhs.crc32c ();
104+
105+ if (rhs.has_customer_encryption ()) {
106+ os << " , customer_encryption.encryption_algorithm="
107+ << rhs.customer_encryption ().encryption_algorithm
108+ << " , customer_encryption.key_sha256="
109+ << rhs.customer_encryption ().key_sha256 ;
110+ }
111+
112+ os << " , etag=" << rhs.etag () << " , generation=" << rhs.generation ()
113+ << " , id=" << rhs.id () << " , kind=" << rhs.kind ()
114+ << " , kms_key_name=" << rhs.kms_key_name ()
112115 << " , md5_hash=" << rhs.md5_hash () << " , media_link=" << rhs.media_link ();
113116 sep = " metadata." ;
114117 for (auto const & kv : rhs.metadata_ ) {
115118 os << sep << kv.first << " =" << kv.second ;
116119 sep = " , metadata." ;
117120 }
118- os << " , metageneration=" << rhs.metageneration () << " , name=" << rhs.name ()
119- << " , owner.entity=" << rhs.owner ().entity
120- << " , owner.entity_id=" << rhs.owner ().entity_id
121- << " , self_link=" << rhs.self_link () << " , size=" << rhs.size ()
121+ os << " , metageneration=" << rhs.metageneration () << " , name=" << rhs.name ();
122+
123+ if (rhs.has_owner ()) {
124+ os << " , owner.entity=" << rhs.owner ().entity
125+ << " , owner.entity_id=" << rhs.owner ().entity_id ;
126+ }
127+
128+ os << " , self_link=" << rhs.self_link () << " , size=" << rhs.size ()
122129 << " , storage_class=" << rhs.storage_class ()
123130 << " , time_created=" << rhs.time_created ().time_since_epoch ().count ()
124131 << " , time_deleted=" << rhs.time_deleted ().time_since_epoch ().count ()
0 commit comments