Viam C++ SDK current
Loading...
Searching...
No Matches
utils.hpp
1#pragma once
2
3#include <boost/optional/optional.hpp>
4#include <grpcpp/client_context.h>
5
6#include <viam/api/common/v1/common.pb.h>
7
8#include <viam/sdk/common/proto_value.hpp>
9#include <viam/sdk/components/component.hpp>
10#include <viam/sdk/resource/resource_api.hpp>
11
12namespace viam {
13namespace sdk {
14
15const std::string kComponent = "component";
16const std::string kResource = "resource";
17const std::string kService = "service";
18const std::string kRDK = "rdk";
19const std::string kBuiltin = "builtin";
20
22 std::chrono::time_point<long long, std::chrono::nanoseconds> captured_at;
23
24 static response_metadata from_proto(const viam::common::v1::ResponseMetadata& proto);
25 static viam::common::v1::ResponseMetadata to_proto(const response_metadata& metadata);
26};
27
28bool operator==(const response_metadata& lhs, const response_metadata& rhs);
29
32std::chrono::time_point<long long, std::chrono::nanoseconds> timestamp_to_time_pt(
33 const google::protobuf::Timestamp& timestamp);
34
37google::protobuf::Timestamp time_pt_to_timestamp(
38 const std::chrono::time_point<long long, std::chrono::nanoseconds>& time_pt);
39
40std::vector<unsigned char> string_to_bytes(std::string const& s);
41std::string bytes_to_string(std::vector<unsigned char> const& b);
42
43std::chrono::microseconds from_proto(const google::protobuf::Duration& proto);
44google::protobuf::Duration to_proto(const std::chrono::microseconds& duration);
45
46// the authority on a grpc::ClientContext is sometimes set to an invalid uri on mac, causing
47// `rust-utils` to fail to process gRPC requests. This class provides a convenience wrapper around a
48// grpc ClientContext that allows us to make any necessary modifications to authority or else where
49// to avoid runtime issues.
50// For more details, see https://viam.atlassian.net/browse/RSDK-5194.
52 public:
54 operator grpc::ClientContext*();
55 operator const grpc::ClientContext*() const;
56 void set_debug_key(const std::string& debug_key);
57
58 private:
59 void set_client_ctx_authority_();
60 void add_viam_client_version_();
61 grpc::ClientContext wrapped_context_;
62};
63
66std::pair<std::string, std::string> long_name_to_remote_and_short(const std::string& long_name);
67
69ProtoStruct debug_map();
70
73ProtoStruct debug_map(std::string debug_key);
74
77void add_debug_entry(ProtoStruct& map, std::string debug_key);
78
80void add_debug_entry(ProtoStruct& map);
81
85ProtoStruct with_debug_entry(ProtoStruct&& map, std::string debug_key);
86
89ProtoStruct with_debug_entry(ProtoStruct&& map);
90
99void set_logger_severity_from_args(int argc, char** argv);
100
104bool from_dm_from_extra(const ProtoStruct& extra);
105
106} // namespace sdk
107} // namespace viam
Definition utils.hpp:51
Definition utils.hpp:21