Remove the obsolete packed_event_codes library.

Packed event codes were only used with Cobalt 1.0 metrics.

Change-Id: Id736a5ac02b32ee59f935905c2e457fca755df65
Reviewed-on: https://fuchsia-review.googlesource.com/c/cobalt/+/850118
Fuchsia-Auto-Submit: Cameron Dale <camrdale@google.com>
Reviewed-by: Steve Fung <stevefung@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
diff --git a/src/logger/BUILD.gn b/src/logger/BUILD.gn
index f61bff9..2b69b08 100644
--- a/src/logger/BUILD.gn
+++ b/src/logger/BUILD.gn
@@ -136,7 +136,6 @@
     "$cobalt_root/src/pb",
     "$cobalt_root/src/public/lib:status",
     "$cobalt_root/src/registry:cobalt_registry_proto",
-    "$cobalt_root/src/registry:packed_event_codes",
   ]
 }
 
diff --git a/src/logger/event_loggers.cc b/src/logger/event_loggers.cc
index ede510b..705a53e 100644
--- a/src/logger/event_loggers.cc
+++ b/src/logger/event_loggers.cc
@@ -205,25 +205,6 @@
 Status EventLogger::ValidateEventCodes(const MetricDefinition& metric,
                                        const RepeatedField<uint32_t>& event_codes,
                                        const std::string& full_metric_name) {
-  // Special case: Users of the version of the Log*() method that takes
-  // a single event code as opposed to a vector of event codes use the
-  // convention of passing a zero value for the single event code in the
-  // case that the metric does not have any metric dimensions defined. We have
-  // no way of distinguishing here that case from the case in which the user
-  // invoked the other version of the method and explicitly passed a vector of
-  // length one containing a single zero event code. Therefore we must accept
-  // a single 0 event code when there are no metric dimensions defined.
-  // The packing of multiple event codes into a single integer field in an
-  // Observation (see config/packed_event_codes.h) does not distinguish
-  // between a single event code with value 0 and an empty list of event codes.
-  // Therefore the server also cannot tell the difference between these two
-  // cases just by looking at an Observation and relies on the metric definition
-  // to distinguish them. Consequently there is no harm in us passing the
-  // single zero value to the Encoder: It will produce the same Observation
-  // whether or not we do.
-  if (metric.metric_dimensions_size() == 0 && event_codes.size() == 1 && event_codes.Get(0) == 0) {
-    return Status::OkStatus();
-  }
   // When new dimensions are added to a metric, they can only be appended, not deleted or inserted.
   // Because of this, and because metric definitions may change before the matching code does, we
   // want to accept events where fewer than the expected number of event_codes have been provided.
diff --git a/src/registry/BUILD.gn b/src/registry/BUILD.gn
index bfdfc22..49c9279 100644
--- a/src/registry/BUILD.gn
+++ b/src/registry/BUILD.gn
@@ -86,32 +86,8 @@
   configs += [ "$cobalt_root:cobalt_config" ]
 }
 
-source_set("packed_event_codes") {
-  sources = [
-    "packed_event_codes.cc",
-    "packed_event_codes.h",
-  ]
-
-  configs += [ "$cobalt_root:cobalt_config" ]
-}
-source_set("packed_event_codes_test") {
-  testonly = true
-
-  sources = [ "packed_event_codes_test.cc" ]
-
-  deps = [
-    ":packed_event_codes",
-    "//third_party/googletest:gtest",
-  ]
-
-  configs += [ "$cobalt_root:cobalt_config" ]
-}
-
 group("tests") {
   testonly = true
 
-  deps = [
-    ":packed_event_codes_test",
-    ":project_configs_test",
-  ]
+  deps = [ ":project_configs_test" ]
 }
diff --git a/src/registry/packed_event_codes.cc b/src/registry/packed_event_codes.cc
deleted file mode 100644
index 7c63116..0000000
--- a/src/registry/packed_event_codes.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2019 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.
-
-#include "src/registry/packed_event_codes.h"
-
-namespace cobalt::config {
-
-namespace {
-
-// Used to mask off the version portion of the packed_event_codes.
-constexpr uint64_t kVersionHeaderMask = (0b1111ull << kVersionHeaderOffset);
-
-uint32_t ReadVersion(uint64_t packed_event_codes) {
-  return (packed_event_codes & kVersionHeaderMask) >> kVersionHeaderOffset;
-}
-
-}  // namespace
-
-std::vector<uint32_t> UnpackEventCodes(uint64_t packed_event_codes) {
-  uint64_t mask;
-  uint64_t num_event_codes;
-  uint64_t event_code_size;
-
-  switch (ReadVersion(packed_event_codes)) {
-    case 0:
-      mask = kEventCodeMask;
-      num_event_codes = kV0NumEventCodes;
-      event_code_size = kV0EventCodeSize;
-      break;
-    case 1:
-      mask = kV1EventCodeMask;
-      num_event_codes = kV1NumEventCodes;
-      event_code_size = kV1EventCodeSize;
-      break;
-    default:
-      return ((std::vector<uint32_t>){0, 0, 0, 0, 0});
-  }
-
-  std::vector<uint32_t> event_codes(num_event_codes);
-  for (uint64_t i = 0; i < num_event_codes; i++) {
-    event_codes[i] = static_cast<unsigned int>(
-        (packed_event_codes & (mask << (event_code_size * i))) >> (event_code_size * i));
-  }
-  return event_codes;
-}
-
-}  // namespace cobalt::config
diff --git a/src/registry/packed_event_codes.h b/src/registry/packed_event_codes.h
deleted file mode 100644
index b8c3506..0000000
--- a/src/registry/packed_event_codes.h
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2019 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.
-//
-// This file contains the code to pack/unpack a list of event_codes into a
-// single uint64_t. This is necessary for supporting multiple event codes
-// because the event_code field in Observation is not repeated.
-//
-// NOTE: This is the ONLY supported way of packing/unpacking multiplexed
-// event_codes into/out of the Observation proto.
-//
-// The encoding is a simple fixed-length encoding where each of the 5 allowed
-// metric_dimensions are placed into their own 10 bit section of the uint64_t.
-//
-// There are currently 2 encodings defined:
-//
-// Version 0 supports 5 10 bit dimensions, and the bit layout is as follows:
-//
-// 0xVVVV__________55555555554444444444333333333322222222221111111111
-//
-// Version 1 supports 4 15 bit dimensions, and the bit layout is as follows:
-//
-// 0xVVVV444444444444444333333333333333222222222222222111111111111111
-//
-// Version 0 should always be preferred unless an event has a dimension value
-// that cannot be represented in 10 bits. In which case Version 2 may be used if
-// there are fewer than 5 dimensions provided.
-//
-// Where the first element in the event_codes array is placed in the least
-// significant bits, and the last element is placed at the most significant
-// bits.
-//
-// The leading 4 bits (denoted by V) are reserved for a version header, which
-// will start at version 0 for the scheme described above.
-//
-// Bits denoted by _ are reserved and not used by this encoding version, and
-// should be set to 0.
-//
-#ifndef COBALT_SRC_REGISTRY_PACKED_EVENT_CODES_H_
-#define COBALT_SRC_REGISTRY_PACKED_EVENT_CODES_H_
-
-#include <cstdint>
-#include <vector>
-
-namespace cobalt::config {
-
-// This is the mask for pulling event codes out of packed event codes.
-constexpr uint64_t kEventCodeMask = 0b1111111111;
-constexpr uint64_t kV1EventCodeMask = 0b111111111111111;
-
-constexpr uint64_t kVersionHeaderOffset = 60;
-
-constexpr uint64_t kV0NumEventCodes = 5;
-constexpr uint64_t kV0MaxEventCodeSize = 1024;
-constexpr uint64_t kV0EventCodeSize = 10;
-
-constexpr uint64_t kV1NumEventCodes = 4;
-constexpr uint64_t kV1EventCodeSize = 15;
-
-// UnpackEventCodes pulls a vector of elements out of the supplied
-// |packed_event_codes|.
-//
-// If the version header is 0, the number of elements unpacked will always be 5.
-// If the version header is 1, the number of elements unpacked will always be 4.
-//
-// If the version header of the packed_event_codes does not match a known
-// version, the resulting vector will be filled with 5 zeroes.
-std::vector<uint32_t> UnpackEventCodes(uint64_t packed_event_codes);
-
-// PackEventCodes_v1 converts an Iterator of uint32_t (|event_codes|) and packs
-// them into a single unit64_t using the v1 scheme described above.
-//
-// |Iterator| Any generic type over which we can iterate. Each element of the
-//            iterator should be a uint32_t.
-//
-// |event_codes| An Iterator of uint32_t of any length (although any elements
-//               past the 4th one will be ignored)
-template <class Iterator>
-uint64_t PackEventCodes_v1(const Iterator& event_codes) {
-  uint64_t i = 0;
-  uint64_t packed_event_codes = 1ull << kVersionHeaderOffset;
-  for (auto code : event_codes) {
-    // If the supplied iterator has more than 4 elements, we ignore them.
-    if (i >= kV1NumEventCodes) {
-      break;
-    }
-    packed_event_codes |=
-        ((static_cast<uint64_t>(code) & kV1EventCodeMask) << (kV1EventCodeSize * i));
-    i += 1;
-  }
-  return packed_event_codes;
-}
-
-// PackEventCodes converts an Iterator of uint32_t (|event_codes|) and packs
-// them into a single uint64_t using the scheme described above.
-//
-// |Iterator| Any generic type over which we can iterate. Each element of the
-//            iterator should be a uint32_t.
-//
-// |event_codes| An Iterator of uint32_t of any length (although any elements
-//               past the 5th one will be ignored).
-template <class Iterator>
-uint64_t PackEventCodes(const Iterator& event_codes) {
-  uint64_t i = 0;
-  uint64_t packed_event_codes = 0;
-  for (auto code : event_codes) {
-    // If the supplied iterator has more than 5 elements, we ignore them.
-    if (i >= kV0NumEventCodes) {
-      break;
-    }
-    if (code >= kV0MaxEventCodeSize) {
-      // We need to fall back to a v1 encoder
-      return PackEventCodes_v1(event_codes);
-    }
-    packed_event_codes |=
-        ((static_cast<uint64_t>(code) & kEventCodeMask) << (kV0EventCodeSize * i));
-    i += 1;
-  }
-  return packed_event_codes;
-}
-
-}  // namespace cobalt::config
-
-#endif  // COBALT_SRC_REGISTRY_PACKED_EVENT_CODES_H_
diff --git a/src/registry/packed_event_codes_test.cc b/src/registry/packed_event_codes_test.cc
deleted file mode 100644
index f72dde7..0000000
--- a/src/registry/packed_event_codes_test.cc
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright 2019 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.
-
-#include "src/registry/packed_event_codes.h"
-
-#include <gtest/gtest.h>
-
-namespace cobalt::config {
-
-TEST(PackEventCodes, AllowsEmptyIterator) {
-  ASSERT_EQ(PackEventCodes((std::vector<uint32_t>){}), 0u);
-}
-
-TEST(PackEventCodes, AcceptsSingleElement) {
-  ASSERT_EQ(PackEventCodes((std::vector<uint32_t>){939}), 939u);
-}
-
-TEST(PackEventCodes, AcceptsFiveElements) {
-  ASSERT_EQ(PackEventCodes((std::vector<uint32_t>){
-                0b1111100000,
-                0b1110011100,
-                0b1101111011,
-                0b1111010110,
-                0b1010110101,
-            }),
-            0b10101101011111010110110111101111100111001111100000u);
-}
-
-TEST(PackEventCodes, IgnoresExtraElements) {
-  ASSERT_EQ(PackEventCodes((std::vector<uint32_t>){
-                0b1111100000,
-                0b1110011100,
-                0b1101111011,
-                0b1111010110,
-                0b1010110101,
-
-                // These two should be ignored.
-                0b1010101010,
-                0b1101101111,
-            }),
-            0b10101101011111010110110111101111100111001111100000u);
-}
-
-TEST(PackEventCodes, DoesNotOverflow) {
-  ASSERT_EQ(PackEventCodes((std::vector<uint32_t>){32769}), 0x1000000000000001u);
-  ASSERT_EQ(PackEventCodes((std::vector<uint32_t>){0, 32769}), 0x1000000000008000u);
-  ASSERT_EQ(PackEventCodes((std::vector<uint32_t>){0, 0, 32769}), 0x1000000040000000u);
-  ASSERT_EQ(PackEventCodes((std::vector<uint32_t>){0, 0, 0, 32769}), 0x1000200000000000u);
-}
-
-TEST(PackEventCodes, UpgradesToV1) {
-  ASSERT_EQ(PackEventCodes(std::vector<uint32_t>{1023}), 1023u);
-  // Sets version field and encodes using 15 bits.
-  ASSERT_EQ(PackEventCodes(std::vector<uint32_t>{1024}), 0x1000000000000400u);
-}
-
-TEST(UnpackEventCodes, AcceptsNullEventCodes) {
-  ASSERT_EQ(UnpackEventCodes(0), ((std::vector<uint32_t>){0, 0, 0, 0, 0}));
-}
-
-TEST(UnpackEventCodes, DecodesSingleElement) {
-  ASSERT_EQ(UnpackEventCodes(939u), ((std::vector<uint32_t>){939, 0, 0, 0, 0}));
-}
-
-TEST(UnpackEventCodes, UnpacksFiveElements) {
-  ASSERT_EQ(UnpackEventCodes(0b10101101011111010110110111101111100111001111100000u),
-            ((std::vector<uint32_t>){
-                0b1111100000,
-                0b1110011100,
-                0b1101111011,
-                0b1111010110,
-                0b1010110101,
-            }));
-}
-
-TEST(UnpackEventCodes, UnpacksFourV1Elements) {
-  ASSERT_EQ(UnpackEventCodes(0b1101101010010101101011111010110110111101111100111001111100000u),
-            ((std::vector<uint32_t>){
-                0b111001111100000u,
-                0b110111101111100u,
-                0b101011111010110u,
-                0b101101010010101u,
-            }));
-}
-
-TEST(UnpackEventCodes, ReturnsZeroesOnUnknownVersion) {
-  ASSERT_EQ(
-      // This packed_event_codes has a version of 2, which we don't know how to
-      // decode.
-      UnpackEventCodes(0x200ABCDEF1234567), ((std::vector<uint32_t>){0, 0, 0, 0, 0}));
-}
-
-TEST(BackAndForth, PackUnpackIsStable) {
-  // TODO(fxbug.dev/87101): Look into clearing up this test.
-  std::vector<std::vector<uint32_t>> tests = {
-      {0, 0, 0, 0, 0},        {100, 0, 0, 0, 0},        {100, 200, 0, 0, 0},
-      {100, 200, 300, 0, 0},  {100, 200, 300, 400, 0},  {100, 200, 300, 400, 500},
-      {1024 - 1, 0, 0, 0, 0}, {1024, 0, 0, 0},          {1024, 3005, 0, 0},
-      {1024, 3005, 4010, 0},  {1024, 3005, 4010, 30000}};
-
-  for (const auto &test : tests) {
-    ASSERT_EQ(UnpackEventCodes(PackEventCodes(test)), test);
-  }
-}
-
-}  // namespace cobalt::config