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