Viam C++ SDK current
Loading...
Searching...
No Matches
utils.hpp
1#pragma once
2
3#include <chrono>
4#include <memory>
5
6#include <boost/optional/optional.hpp>
7
8#include <viam/sdk/common/proto_convert.hpp>
9#include <viam/sdk/common/proto_value.hpp>
10#include <viam/sdk/components/component.hpp>
11#include <viam/sdk/resource/resource_api.hpp>
12
13namespace google {
14namespace protobuf {
15
16class Duration;
17class Timestamp;
18
19} // namespace protobuf
20} // namespace google
21
22namespace viam {
23namespace common {
24namespace v1 {
25
26class ResponseMetadata;
27
28}
29} // namespace common
30} // namespace viam
31
32namespace viam {
33namespace sdk {
34
35const std::string kComponent = "component";
36const std::string kResource = "resource";
37const std::string kService = "service";
38const std::string kRDK = "rdk";
39const std::string kRDKInternal = "rdk-internal";
40const std::string kBuiltin = "builtin";
41
42using time_pt = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
43
45 time_pt captured_at = {};
46};
47
48bool operator==(const response_metadata& lhs, const response_metadata& rhs);
49
50namespace proto_convert_details {
51
52template <>
53struct to_proto_impl<time_pt> {
54 void operator()(time_pt, google::protobuf::Timestamp*) const;
55};
56
57template <>
58struct from_proto_impl<google::protobuf::Timestamp> {
59 time_pt operator()(const google::protobuf::Timestamp*) const;
60};
61
62template <>
63struct to_proto_impl<std::chrono::microseconds> {
64 void operator()(std::chrono::microseconds, google::protobuf::Duration*) const;
65};
66
67template <>
68struct from_proto_impl<google::protobuf::Duration> {
69 std::chrono::microseconds operator()(const google::protobuf::Duration*) const;
70};
71
72template <>
74 void operator()(const response_metadata&, common::v1::ResponseMetadata*) const;
75};
76
77template <>
78struct from_proto_impl<common::v1::ResponseMetadata> {
79 response_metadata operator()(const common::v1::ResponseMetadata*) const;
80};
81
82} // namespace proto_convert_details
83
84std::vector<unsigned char> string_to_bytes(std::string const& s);
85std::string bytes_to_string(std::vector<unsigned char> const& b);
86
89std::pair<std::string, std::string> long_name_to_remote_and_short(const std::string& long_name);
90
92ProtoStruct debug_map();
93
96ProtoStruct debug_map(std::string debug_key);
97
100void add_debug_entry(ProtoStruct& map, std::string debug_key);
101
103void add_debug_entry(ProtoStruct& map);
104
108ProtoStruct with_debug_entry(ProtoStruct&& map, std::string debug_key);
109
112ProtoStruct with_debug_entry(ProtoStruct&& map);
113
117bool from_dm_from_extra(const ProtoStruct& extra);
118
123boost::optional<std::string> get_env(const char* var);
124
127bool is_env_var_true(const char* var);
128
131bool is_env_var_false(const char* var);
132
133} // namespace sdk
134} // namespace viam
Definition utils.hpp:44