/proc/self/cwd/opencensus/trace/internal/span_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/span_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 | SpanId::SpanId(const uint8_t *buf) { memcpy(rep_, buf, kSize); } |
27 | | |
28 | 219 | std::string SpanId::ToHex() const { |
29 | 219 | return absl::BytesToHexString( |
30 | 219 | absl::string_view(reinterpret_cast<const char *>(rep_), kSize)); |
31 | 219 | } |
32 | | |
33 | 0 | const void *SpanId::Value() const { return rep_; } |
34 | | |
35 | 0 | bool SpanId::operator==(const SpanId &that) const { |
36 | 0 | return memcmp(rep_, that.rep_, kSize) == 0; |
37 | 0 | } |
38 | | |
39 | 1.08k | bool SpanId::IsValid() const { |
40 | 1.08k | static_assert(kSize == 8, |
41 | 1.08k | "IsValid assumes the internal representation is 8 bytes."); |
42 | 1.08k | uint64_t tmp; |
43 | 1.08k | memcpy(&tmp, rep_, kSize); |
44 | 1.08k | return tmp != 0; |
45 | 1.08k | } |
46 | | |
47 | 860 | void SpanId::CopyTo(uint8_t *buf) const { memcpy(buf, rep_, kSize); } |
48 | | |
49 | | } // namespace trace |
50 | | } // namespace opencensus |