// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary // source code may only be used and distributed under the Widevine License // Agreement. // // This file contains the declarations for the EventMetric class and related // types. #ifndef WVCDM_METRICS_ATTRIBUTE_HANDLER_H_ #define WVCDM_METRICS_ATTRIBUTE_HANDLER_H_ #include #include "log.h" #include "wv_metrics.pb.h" namespace wvcdm { namespace metrics { // This method is used to set the value of a single proto field. // Specializations handle setting each value. template void SetAttributeField(const F& value, drm_metrics::Attributes* attributes); // This class handles serializing the attributes for metric types that breakdown // into multiple buckets. The template parameters should be specified in pairs. // E.g. I1 and F1 should match. I1 should specify the field number in the proto // and F1 should specify the type of the field to be set. template class AttributeHandler { public: // This method returns the serialized attribute proto for the given field // values. The order of the field values must match the order in the // template. std::string GetSerializedAttributes(F1 field1, F2 field2, F3 field3, F4 field4) const { drm_metrics::Attributes attributes; SetAttributeField(field1, &attributes); SetAttributeField(field2, &attributes); SetAttributeField(field3, &attributes); SetAttributeField(field4, &attributes); std::string serialized_attributes; if (!attributes.SerializeToString(&serialized_attributes)) { LOGE("Failed to serialize attribute proto."); return ""; } return serialized_attributes; } }; } // namespace metrics } // namespace wvcdm #endif // WVCDM_METRICS_ATTRIBUTE_HANDLER_H_