15 #include "google/cloud/storage/object_metadata.h"
16 #include "google/cloud/storage/internal/metadata_parser.h"
17 #include "google/cloud/storage/internal/object_acl_requests.h"
18 #include "google/cloud/internal/absl_str_join_quiet.h"
19 #include "google/cloud/internal/format_time_point.h"
20 #include <nlohmann/json.hpp>
30 return static_cast<internal::CommonMetadata<
ObjectMetadata>
const&>(lhs) ==
32 lhs.acl_ == rhs.acl_ && lhs.bucket_ == rhs.bucket_ &&
33 lhs.cache_control_ == rhs.cache_control_ &&
34 lhs.component_count_ == rhs.component_count_ &&
35 lhs.content_disposition_ == rhs.content_disposition_ &&
36 lhs.content_encoding_ == rhs.content_encoding_ &&
37 lhs.content_language_ == rhs.content_language_ &&
38 lhs.content_type_ == rhs.content_type_ && lhs.crc32c_ == rhs.crc32c_ &&
39 lhs.customer_encryption_ == rhs.customer_encryption_ &&
40 lhs.event_based_hold_ == rhs.event_based_hold_ &&
41 lhs.generation_ == rhs.generation_ &&
42 lhs.kms_key_name_ == rhs.kms_key_name_ &&
43 lhs.md5_hash_ == rhs.md5_hash_ && lhs.media_link_ == rhs.media_link_ &&
44 lhs.metadata_ == rhs.metadata_ &&
45 lhs.retention_expiration_time_ == rhs.retention_expiration_time_ &&
46 lhs.temporary_hold_ == rhs.temporary_hold_ &&
47 lhs.time_deleted_ == rhs.time_deleted_ &&
48 lhs.time_storage_class_updated_ == rhs.time_storage_class_updated_ &&
49 lhs.size_ == rhs.size_ && lhs.custom_time_ == rhs.custom_time_;
53 os <<
"ObjectMetadata={name=" << rhs.name() <<
", acl=[";
54 os << absl::StrJoin(rhs
.acl(),
", ", absl::StreamFormatter());
64 os <<
", customer_encryption.encryption_algorithm="
66 <<
", customer_encryption.key_sha256="
70 os <<
", etag=" << rhs.etag() <<
", event_based_hold=" << std::boolalpha
72 <<
", id=" << rhs.id() <<
", kind=" << rhs.kind()
75 if (!rhs.metadata_.empty()) {
77 << absl::StrJoin(rhs.metadata_,
", metadata.", absl::PairFormatter(
"="));
79 os <<
", metageneration=" << rhs.metageneration() <<
", name=" << rhs.name();
81 if (rhs.has_owner()) {
82 os <<
", owner.entity=" << rhs.owner().entity
83 <<
", owner.entity_id=" << rhs.owner().entity_id;
86 os <<
", retention_expiration_time="
88 <<
", self_link=" << rhs.self_link() <<
", size=" << rhs
.size()
89 <<
", storage_class=" << rhs.storage_class()
91 <<
", time_created=" << rhs.time_created().time_since_epoch().count()
93 <<
", time_storage_class_updated="
95 <<
", updated=" << rhs.updated().time_since_epoch().count();
103 internal::PatchBuilder tmp = impl_;
104 if (metadata_subpatch_dirty_) {
105 if (metadata_subpatch_.empty()) {
106 tmp.RemoveField(
"metadata");
108 tmp.AddSubPatch(
"metadata", metadata_subpatch_);
111 return tmp.ToString();
119 auto array = nlohmann::json::array();
120 for (
auto const& a : v) {
121 array.emplace_back(nlohmann::json{
122 {
"entity", a.entity()},
126 impl_.SetArrayField(
"acl", array.dump());
131 impl_.RemoveField(
"acl");
136 std::string
const& v) {
140 impl_.SetStringField(
"cacheControl", v);
145 impl_.RemoveField(
"cacheControl");
150 std::string
const& v) {
154 impl_.SetStringField(
"contentDisposition", v);
160 impl_.RemoveField(
"contentDisposition");
165 std::string
const& v) {
169 impl_.SetStringField(
"contentEncoding", v);
174 impl_.RemoveField(
"contentEncoding");
179 std::string
const& v) {
183 impl_.SetStringField(
"contentLanguage", v);
188 impl_.RemoveField(
"contentLanguage");
193 std::string
const& v) {
197 impl_.SetStringField(
"contentType", v);
202 impl_.RemoveField(
"contentType");
208 impl_.SetBoolField(
"eventBasedHold", v);
213 impl_.RemoveField(
"eventBasedHold");
218 std::string
const& key, std::string
const& value) {
219 metadata_subpatch_.SetStringField(key.c_str(), value);
220 metadata_subpatch_dirty_ =
true;
225 std::string
const& key) {
226 metadata_subpatch_.RemoveField(key.c_str());
227 metadata_subpatch_dirty_ =
true;
232 metadata_subpatch_.clear();
233 metadata_subpatch_dirty_ =
true;
239 impl_.SetBoolField(
"temporaryHold", v);
244 impl_.RemoveField(
"temporaryHold");
249 std::chrono::system_clock::time_point tp) {
250 impl_.SetStringField(
"customTime",
256 impl_.RemoveField(
"customTime");