blob: 7cf33869cb2bcb0f2b14ab6d9feaaf2fd64b5fe9 [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 |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);
} // namespace cobalt
#endif // COBALT_SRC_LIB_PRIVACY_PRIVATE_INDEX_DECODING_H_