Coverage Report

Created: 2023-10-10 06:39

/proc/self/cwd/opencensus/trace/internal/trace_id.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2017, OpenCensus Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include "opencensus/trace/trace_id.h"
16
17
#include <cstring>
18
#include <string>
19
20
#include "absl/strings/escaping.h"
21
#include "absl/strings/string_view.h"
22
23
namespace opencensus {
24
namespace trace {
25
26
1.08k
TraceId::TraceId(const uint8_t *buf) { memcpy(rep_, buf, kSize); }
27
28
849
std::string TraceId::ToHex() const {
29
849
  return absl::BytesToHexString(
30
849
      absl::string_view(reinterpret_cast<const char *>(rep_), kSize));
31
849
}
32
33
0
const void *TraceId::Value() const { return rep_; }
34
35
0
bool TraceId::operator==(const TraceId &that) const {
36
0
  return memcmp(rep_, that.rep_, kSize) == 0;
37
0
}
38
39
1.56k
bool TraceId::IsValid() const {
40
1.56k
  static_assert(kSize == 16, "Internal representation must be 16 bytes.");
41
1.56k
  uint64_t tmp1;
42
1.56k
  uint64_t tmp2;
43
1.56k
  memcpy(&tmp1, &rep_[0], 8);
44
1.56k
  memcpy(&tmp2, &rep_[8], 8);
45
1.56k
  return (tmp1 != 0 || tmp2 != 0);
46
1.56k
}
47
48
230
void TraceId::CopyTo(uint8_t *buf) const { memcpy(buf, rep_, kSize); }
49
50
}  // namespace trace
51
}  // namespace opencensus