blob: 1aba4816f2a55af758e7072c8d4d89074e154aed [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COBALT_SRC_LIB_PRIVACY_PRIVATE_INDEX_DECODING_H_
#define COBALT_SRC_LIB_PRIVACY_PRIVATE_INDEX_DECODING_H_
#include <google/protobuf/repeated_field.h>
#include "src/lib/util/status.h"
#include "src/registry/metric_definition.pb.h"
namespace cobalt {
// A value which represents either a sum or a count. Used when decoding observations for
// FleetwideMeans reports.
struct SumOrCount {
enum SumOrCountType { SUM, COUNT };
SumOrCountType type;
int64_t sum = 0;
uint64_t count = 0;
};
// Populates |event_vector| with the event vector which corresponds to |index| according to the
// contents of |metric_dimensions| and returns an OK status, or returns an error status if |index|
// does not represent a valid event vector according to |metric_dimensions|.
util::Status DecodePrivateIndexAsEventVector(
uint64_t index,
const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
std::vector<uint32_t>* event_vector);
// Populates |event_vector| and |integer_value| with the event vector and integer value which
// correspond to |index| according to |metric_dimensions|, |min_value|, |max_value|, and
// |num_index_points|, or returns an error status if |index| does not represent a valid
// (event_vector, integer_value) pair.
util::Status DecodePrivateIndexAsInteger(
uint64_t index,
const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
int64_t min_value, int64_t max_value, uint64_t num_index_points,
std::vector<uint32_t>* event_vector, int64_t* integer_value);
// Populates |event_vector| and |double_value| with the event vector and numeric value which
// correspond to |index| according to |metric_dimensions|, |min_value|, |max_value|, and
// |num_index_points|, or returns an error status if |index| does not represent a valid
// (event_vector, double_value) pair.
util::Status DecodePrivateIndexAsDouble(
uint64_t index,
const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
int64_t min_value, int64_t max_value, uint64_t num_index_points,
std::vector<uint32_t>* event_vector, double* double_value);
// Populates |event_vector| and |sum_or_count| with the event vector and SumAndCount which
// correspond to |index| according to |metric_dimensions|, |min_value|, |max_value|, |max_count| and
// |num_index_points|, or returns an error status if |index| does not represent a valid
// (event_vector, sum) or (event_vector, count) pair.
//
// After a successful call, |sum_or_count| will be a SumOrCount struct whose |type| field is set to
// either SUM or COUNT. If the |type| is SUM, then the |sum| field is populated with a signed int
// representing a sum; if the |type| is COUNT, then the |count| field is populated with an unsigned
// int representing a count.
util::Status DecodePrivateIndexAsSumOrCount(
uint64_t index,
const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
int64_t min_value, int64_t max_value, uint64_t max_count, uint64_t num_index_points,
std::vector<uint32_t>* event_vector, SumOrCount* sum_or_count);
// Populates |event_vector| and |bucket_index| with the event vector and histogram bucket index
// which correspond to |index| according to |metric_dimensions| and |max_bucket_index|, or returns
// an error status if |index| does not represent a valid (event_vector, bucket_index) pair.
util::Status DecodePrivateIndexAsHistogramBucketIndex(
uint64_t index,
const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
uint32_t max_bucket_index, std::vector<uint32_t>* event_vector, uint32_t* bucket_index);
// Populates |event_vector|, |bucket_index|, and |bucket_count| with the event vector, histogram
// bucket index, and bucket count which correspond to |index| according to |metric_dimensions|,
// |max_bucket_index|, |max_count|, and |num_index_points|, or else returns an error status if
// |index| does not represent a valid (event_vector, bucket_index, bucket_count) tuple.
util::Status DecodePrivateIndexAsHistogramBucketIndexAndCount(
uint64_t index,
const google::protobuf::RepeatedPtrField<MetricDefinition::MetricDimension>& metric_dimensions,
uint32_t max_bucket_index, uint64_t max_count, uint64_t num_index_points,
std::vector<uint32_t>* event_vector, uint32_t* bucket_index, uint64_t* bucket_count);
} // namespace cobalt
#endif // COBALT_SRC_LIB_PRIVACY_PRIVATE_INDEX_DECODING_H_