]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/SpanContext.cpp
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / SpanContext.cpp
CommitLineData
f67539c2
TL
1/*
2 * Copyright (c) 2017 Uber Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "jaegertracing/SpanContext.h"
18
19#include "jaegertracing/utils/HexParsing.h"
20
21namespace jaegertracing {
22
23SpanContext SpanContext::fromStream(std::istream& in)
24{
25 SpanContext spanContext;
26 spanContext._traceID = TraceID::fromStream(in);
27 if (!spanContext._traceID.isValid()) {
28 return SpanContext();
29 }
30
31 char ch = '\0';
32 if (!in.get(ch) || ch != ':') {
33 return SpanContext();
34 }
35
36 constexpr auto kMaxUInt64Chars = static_cast<size_t>(16);
37 auto buffer = utils::HexParsing::readSegment(in, kMaxUInt64Chars, ':');
38 if (buffer.empty()) {
39 return SpanContext();
40 }
41 spanContext._spanID = utils::HexParsing::decodeHex<uint64_t>(buffer);
42
43 if (!in.get(ch) || ch != ':') {
44 return SpanContext();
45 }
46
47 buffer = utils::HexParsing::readSegment(in, kMaxUInt64Chars, ':');
48 if (buffer.empty()) {
49 return SpanContext();
50 }
51 spanContext._parentID = utils::HexParsing::decodeHex<uint64_t>(buffer);
52
53 if (!in.get(ch) || ch != ':') {
54 return SpanContext();
55 }
56
57 constexpr auto kMaxByteChars = static_cast<size_t>(2);
58 buffer = utils::HexParsing::readSegment(in, kMaxByteChars, ':');
59 if (buffer.empty()) {
60 return SpanContext();
61 }
62 spanContext._flags = utils::HexParsing::decodeHex<unsigned char>(buffer);
63
64 in.clear();
65 return spanContext;
66}
67
68} // namespace jaegertracing