]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/Tag.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / Tag.cpp
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/Tag.h"
18 #include "jaegertracing/thrift-gen/jaeger_types.h"
19
20 namespace jaegertracing {
21 class ThriftVisitor {
22 public:
23 using result_type = void;
24
25 explicit ThriftVisitor(thrift::Tag& tag)
26 : _tag(tag)
27 {
28 }
29
30 void operator()(const std::string& value) const { setString(value); }
31
32 void operator()(const char* value) const { setString(value); }
33
34 void operator()(double value) const
35 {
36 _tag.__set_vType(thrift::TagType::DOUBLE);
37 _tag.__set_vDouble(value);
38 }
39
40 void operator()(bool value) const
41 {
42 _tag.__set_vType(thrift::TagType::BOOL);
43 _tag.__set_vBool(value);
44 }
45
46 void operator()(int64_t value) const { setLong(value); }
47
48 void operator()(uint64_t value) const { setLong(value); }
49
50 template <typename Arg>
51 void operator()(Arg&& value) const
52 {
53 // No-op
54 }
55
56 private:
57 void setString(opentracing::string_view value) const
58 {
59 _tag.__set_vType(thrift::TagType::STRING);
60 _tag.__set_vStr(value);
61 }
62
63 void setLong(int64_t value) const
64 {
65 _tag.__set_vType(thrift::TagType::LONG);
66 _tag.__set_vLong(value);
67 }
68
69 thrift::Tag& _tag;
70 };
71
72 void Tag::thrift(thrift::Tag& tag) const
73 {
74 tag.__set_key(_key);
75 ThriftVisitor visitor(tag);
76 opentracing::util::apply_visitor(visitor, _value);
77 }
78
79 } // namespace jaegertracing