NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/includes/opentelemetry/trace/span_id.h
Go to the documentation of this file.
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <cstdint>
7 #include <cstring>
8 
9 #include "opentelemetry/nostd/span.h"
10 #include "opentelemetry/version.h"
11 
13 namespace trace
14 {
15 
16 class SpanId final
17 {
18 public:
19  // The size in bytes of the SpanId.
20  static constexpr int kSize = 8;
21 
22  // An invalid SpanId (all zeros).
23  SpanId() noexcept : rep_{0} {}
24 
25  // Creates a SpanId with the given ID.
26  explicit SpanId(nostd::span<const uint8_t, kSize> id) noexcept { memcpy(rep_, id.data(), kSize); }
27 
28  // Populates the buffer with the lowercase base16 representation of the ID.
29  void ToLowerBase16(nostd::span<char, 2 * kSize> buffer) const noexcept
30  {
31  constexpr char kHex[] = "0123456789abcdef";
32  for (int i = 0; i < kSize; ++i)
33  {
34  buffer[i * 2 + 0] = kHex[(rep_[i] >> 4) & 0xF];
35  buffer[i * 2 + 1] = kHex[(rep_[i] >> 0) & 0xF];
36  }
37  }
38 
39  // Returns a nostd::span of the ID.
41  {
43  }
44 
45  bool operator==(const SpanId &that) const noexcept { return memcmp(rep_, that.rep_, kSize) == 0; }
46 
47  bool operator!=(const SpanId &that) const noexcept { return !(*this == that); }
48 
49  // Returns false if the SpanId is all zeros.
50  bool IsValid() const noexcept
51  {
52  static constexpr uint8_t kEmptyRep[kSize] = {0};
53  return memcmp(rep_, kEmptyRep, kSize) != 0;
54  }
55 
56  // Copies the opaque SpanId data to dest.
57  void CopyBytesTo(nostd::span<uint8_t, kSize> dest) const noexcept
58  {
59  memcpy(dest.data(), rep_, kSize);
60  }
61 
62 private:
63  uint8_t rep_[kSize];
64 };
65 
66 } // namespace trace
trace::SpanId::operator==
bool operator==(const SpanId &that) const noexcept
Definition: 9.2/includes/opentelemetry/trace/span_id.h:45
trace
Definition: includes/opentelemetry/context/context_value.h:18
trace::SpanId::kSize
static constexpr int kSize
Definition: includes/opentelemetry/trace/span_id.h:20
trace::SpanId::SpanId
SpanId(nostd::span< const uint8_t, kSize > id) noexcept
Definition: 9.2/includes/opentelemetry/trace/span_id.h:26
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
nostd::span
Back port of std::span.
Definition: includes/opentelemetry/nostd/span.h:51
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
trace::SpanId::CopyBytesTo
void CopyBytesTo(nostd::span< uint8_t, kSize > dest) const noexcept
Definition: 9.2/includes/opentelemetry/trace/span_id.h:57
trace::SpanId::ToLowerBase16
void ToLowerBase16(nostd::span< char, 2 *kSize > buffer) const noexcept
Definition: 9.2/includes/opentelemetry/trace/span_id.h:29
trace::SpanId::SpanId
SpanId() noexcept
Definition: 9.2/includes/opentelemetry/trace/span_id.h:23
trace::SpanId::Id
nostd::span< const uint8_t, kSize > Id() const noexcept
Definition: 9.2/includes/opentelemetry/trace/span_id.h:40
trace::SpanId
Definition: includes/opentelemetry/trace/span_id.h:16
data
JSAMPIMAGE data
Definition: sources/libs/nvll_batch_jpeg_encode/oss/jpeglib.h:967
trace::SpanId::IsValid
bool IsValid() const noexcept
Definition: 9.2/includes/opentelemetry/trace/span_id.h:50
trace::SpanId::operator!=
bool operator!=(const SpanId &that) const noexcept
Definition: 9.2/includes/opentelemetry/trace/span_id.h:47