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 kBuiltin = "builtin";
40
41using time_pt = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
42
44 time_pt captured_at;
45};
46
47bool operator==(const response_metadata& lhs, const response_metadata& rhs);
48
49namespace proto_convert_details {
50
51template <>
52struct to_proto_impl<time_pt> {
53 void operator()(time_pt, google::protobuf::Timestamp*) const;
54};
55
56template <>
57struct from_proto_impl<google::protobuf::Timestamp> {
58 time_pt operator()(const google::protobuf::Timestamp*) const;
59};
60
61template <>
62struct to_proto_impl<std::chrono::microseconds> {
63 void operator()(std::chrono::microseconds, google::protobuf::Duration*) const;
64};
65
66template <>
67struct from_proto_impl<google::protobuf::Duration> {
68 std::chrono::microseconds operator()(const google::protobuf::Duration*) const;
69};
70
71template <>
73 void operator()(const response_metadata&, common::v1::ResponseMetadata*) const;
74};
75
76template <>
77struct from_proto_impl<common::v1::ResponseMetadata> {
78 response_metadata operator()(const common::v1::ResponseMetadata*) const;
79};
80
81} // namespace proto_convert_details
82
83std::vector<unsigned char> string_to_bytes(std::string const& s);
84std::string bytes_to_string(std::vector<unsigned char> const& b);
85
88std::pair<std::string, std::string> long_name_to_remote_and_short(const std::string& long_name);
89
91ProtoStruct debug_map();
92
95ProtoStruct debug_map(std::string debug_key);
96
99void add_debug_entry(ProtoStruct& map, std::string debug_key);
100
102void add_debug_entry(ProtoStruct& map);
103
107ProtoStruct with_debug_entry(ProtoStruct&& map, std::string debug_key);
108
111ProtoStruct with_debug_entry(ProtoStruct&& map);
112
121void set_logger_severity_from_args(int argc, char** argv);
122
126bool from_dm_from_extra(const ProtoStruct& extra);
127
128} // namespace sdk
129} // namespace viam
Definition utils.hpp:43