diff --git a/src/viam/sdk/common/client_helper.hpp b/src/viam/sdk/common/client_helper.hpp index d572307b7..2fb918c55 100644 --- a/src/viam/sdk/common/client_helper.hpp +++ b/src/viam/sdk/common/client_helper.hpp @@ -85,7 +85,7 @@ class ClientHelper { debug_key_ = *value.get(); } - proto_convert_details::to_proto{}(extra, request_.mutable_extra()); + proto_convert_details::to_proto_impl{}(extra, request_.mutable_extra()); return with(std::forward(rsc)); } diff --git a/src/viam/sdk/common/linear_algebra.cpp b/src/viam/sdk/common/linear_algebra.cpp index e464f0ee1..bc2301f74 100644 --- a/src/viam/sdk/common/linear_algebra.cpp +++ b/src/viam/sdk/common/linear_algebra.cpp @@ -36,13 +36,13 @@ Vector3& Vector3::set_z(double z) { namespace proto_convert_details { -void to_proto::operator()(const Vector3& self, common::v1::Vector3* proto) const { +void to_proto_impl::operator()(const Vector3& self, common::v1::Vector3* proto) const { proto->set_x(self.x()); proto->set_y(self.y()); proto->set_z(self.z()); } -Vector3 from_proto::operator()(const common::v1::Vector3* proto) const { +Vector3 from_proto_impl::operator()(const common::v1::Vector3* proto) const { return {proto->x(), proto->y(), proto->z()}; } diff --git a/src/viam/sdk/common/linear_algebra.hpp b/src/viam/sdk/common/linear_algebra.hpp index e9045f38f..58de611bb 100644 --- a/src/viam/sdk/common/linear_algebra.hpp +++ b/src/viam/sdk/common/linear_algebra.hpp @@ -41,12 +41,12 @@ struct Vector3 { namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const Vector3&, common::v1::Vector3*) const; }; template <> -struct from_proto { +struct from_proto_impl { Vector3 operator()(const common::v1::Vector3*) const; }; diff --git a/src/viam/sdk/common/pose.cpp b/src/viam/sdk/common/pose.cpp index 051f0712b..5780d4583 100644 --- a/src/viam/sdk/common/pose.cpp +++ b/src/viam/sdk/common/pose.cpp @@ -16,7 +16,7 @@ std::ostream& operator<<(std::ostream& os, const pose_in_frame& v) { namespace proto_convert_details { -void to_proto::operator()(const pose& self, common::v1::Pose* proto) const { +void to_proto_impl::operator()(const pose& self, common::v1::Pose* proto) const { proto->set_x(self.coordinates.x); proto->set_y(self.coordinates.y); proto->set_z(self.coordinates.z); @@ -26,7 +26,7 @@ void to_proto::operator()(const pose& self, common::v1::Pose* proto) const proto->set_theta(self.theta); } -pose from_proto::operator()(const common::v1::Pose* proto) const { +pose from_proto_impl::operator()(const common::v1::Pose* proto) const { pose pose; pose.coordinates.x = proto->x(); pose.coordinates.y = proto->y(); @@ -39,19 +39,19 @@ pose from_proto::operator()(const common::v1::Pose* proto) con return pose; } -void to_proto::operator()(const pose_in_frame& self, - common::v1::PoseInFrame* pif) const { +void to_proto_impl::operator()(const pose_in_frame& self, + common::v1::PoseInFrame* pif) const { *(pif->mutable_reference_frame()) = self.reference_frame; common::v1::Pose proto_pose; - to_proto{}(self.pose, &proto_pose); + to_proto_impl{}(self.pose, &proto_pose); *(pif->mutable_pose()) = std::move(proto_pose); }; -pose_in_frame from_proto::operator()( +pose_in_frame from_proto_impl::operator()( const common::v1::PoseInFrame* proto) const { pose_in_frame pif; pif.reference_frame = proto->reference_frame(); - pif.pose = from_proto{}(&(proto->pose())); + pif.pose = from_proto_impl{}(&(proto->pose())); return pif; } diff --git a/src/viam/sdk/common/pose.hpp b/src/viam/sdk/common/pose.hpp index 2eddd18ec..448c25eaf 100644 --- a/src/viam/sdk/common/pose.hpp +++ b/src/viam/sdk/common/pose.hpp @@ -50,22 +50,22 @@ struct pose_in_frame { namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const pose&, common::v1::Pose*) const; }; template <> -struct from_proto { +struct from_proto_impl { pose operator()(const common::v1::Pose*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const pose_in_frame&, common::v1::PoseInFrame*) const; }; template <> -struct from_proto { +struct from_proto_impl { pose_in_frame operator()(const common::v1::PoseInFrame*) const; }; diff --git a/src/viam/sdk/common/private/repeated_ptr_convert.hpp b/src/viam/sdk/common/private/repeated_ptr_convert.hpp index 030eba8c5..fe35099d5 100644 --- a/src/viam/sdk/common/private/repeated_ptr_convert.hpp +++ b/src/viam/sdk/common/private/repeated_ptr_convert.hpp @@ -10,42 +10,29 @@ namespace viam { namespace sdk { namespace impl { -struct to_repeated_field_ { - template > - auto operator()(const std::vector& v) const { - ::google::protobuf::RepeatedPtrField> result; - result.Reserve(v.size()); +template > +auto to_repeated_field(const std::vector& v) { + ::google::protobuf::RepeatedPtrField> result; + result.Reserve(v.size()); - for (const auto& elem : v) { - *(result.Add()) = v2::to_proto(elem); - } - - return result; + for (const auto& elem : v) { + *(result.Add()) = to_proto(elem); } -}; -struct from_repeated_field_ { - template > - auto operator()(const ::google::protobuf::RepeatedPtrField& v) const { - std::vector> result; - result.reserve(v.size()); + return result; +} - for (const auto& elem : v) { - result.push_back(v2::from_proto(elem)); - } +template > +auto from_repeated_field(const ::google::protobuf::RepeatedPtrField& v) { + std::vector> result; + result.reserve(v.size()); - return result; + for (const auto& elem : v) { + result.push_back(from_proto(elem)); } -}; - -namespace { - -constexpr auto& to_repeated_field = proto_convert_details::static_const::value; - -constexpr auto& from_repeated_field = - proto_convert_details::static_const::value; -} // namespace + return result; +} } // namespace impl } // namespace sdk diff --git a/src/viam/sdk/common/private/service_helper.hpp b/src/viam/sdk/common/private/service_helper.hpp index b9435bbb3..3212fe00f 100644 --- a/src/viam/sdk/common/private/service_helper.hpp +++ b/src/viam/sdk/common/private/service_helper.hpp @@ -51,7 +51,7 @@ class ServiceHelper : public ServiceHelperBase { } auto getExtra() const { - return request_->has_extra() ? v2::from_proto(request_->extra()) : ProtoStruct{}; + return request_->has_extra() ? from_proto(request_->extra()) : ProtoStruct{}; } private: diff --git a/src/viam/sdk/common/proto_convert.hpp b/src/viam/sdk/common/proto_convert.hpp index 1e2e82626..ed41f5fca 100644 --- a/src/viam/sdk/common/proto_convert.hpp +++ b/src/viam/sdk/common/proto_convert.hpp @@ -11,27 +11,17 @@ namespace sdk { namespace proto_convert_details { -// This is copied from range-v3 to allow the definition of callable object instances without -// ODR/linkage issues. It is obviated in C++17 and onwards by constexpr inline. -template -struct static_const { - static constexpr const T value{}; -}; - -template -constexpr const T static_const::value; - // This struct should be explicitly specialized with a // void operator()(const SdkType&, common::v1::ApiType*) const // to provide API/ABI insulated proto conversion template -struct to_proto; +struct to_proto_impl; // This struct should be explicitly specialized with a // SdkType operator()(const ProtoType*) const // to provided API/ABI insulated construction from proto template -struct from_proto; +struct from_proto_impl; // This is a helper type trait for deducing corresponding API types from a to_proto specialization. // We use boost::callable_traits to generate a tuple of the arguments to the to_proto call operator, @@ -40,60 +30,42 @@ template using ProtoArgType = std::remove_pointer_t< boost::mp11::mp_back>>; -// Implementation struct for the omni-to_proto callable defined below. -struct to_proto_impl { - template - auto operator()(const SdkType& t) const { - using ProtoReturnType = ProtoArgType>; - - ProtoReturnType ret; - to_proto{}(t, &ret); - - return ret; - } -}; - -// Implementation struct for the omni-from_proto callable defined below. -struct from_proto_impl { - template - auto operator()(const ProtoType& proto) const { // NOLINT(misc-no-recursion) - return from_proto{}(&proto); - } -}; - } // namespace proto_convert_details -namespace v2 { - -namespace { - -/// @brief Function object implementing conversion from an SDK type to an API type. -/// This callable works for any type with a proto_convert_details::to_proto specialization as -/// described above. -constexpr auto& to_proto = - proto_convert_details::static_const::value; - -/// @brief Function object implementing conversion from an API type to an SDK type. -/// This callable works for any type with a proto_convert_details::from_proto specialization as -/// described above. -constexpr auto& from_proto = - proto_convert_details::static_const::value; - -} // namespace - -} // namespace v2 +/// @brief Convert an SDK type to its corresponding API type. +/// @remark Only participates in overload resolution if to_proto_impl has been specialized. +template ))> +auto to_proto(const SdkType& t) { // NOLINT(misc-no-recursion) + namespace pcd = proto_convert_details; + using ProtoReturnType = pcd::ProtoArgType>; + + ProtoReturnType ret; + pcd::to_proto_impl{}(t, &ret); + + return ret; +} + +/// @brief Convert an API type to its corresponding SDK type. +/// @remark Only participates in overload resolution if from_proto_impl has been +/// specialized. +template ))> +auto from_proto(const ApiType& proto) { // NOLINT(misc-no-recursion) + return proto_convert_details::from_proto_impl{}(&proto); +} /// @brief Type alias for the API type corresponding to a given SDK type. /// This is the return type of calling to_proto on an instance of SdkType. template using EquivalentApiType = - proto_convert_details::ProtoArgType>; + proto_convert_details::ProtoArgType>; /// @brief Type alias for the SDK type corresponding to a given API type. /// This is the return type of calling from_proto on an instance of ApiType. template using EquivalentSdkType = - boost::callable_traits::return_type_t>; + boost::callable_traits::return_type_t>; } // namespace sdk } // namespace viam diff --git a/src/viam/sdk/common/proto_value.cpp b/src/viam/sdk/common/proto_value.cpp index 1521db29a..cffca13e1 100644 --- a/src/viam/sdk/common/proto_value.cpp +++ b/src/viam/sdk/common/proto_value.cpp @@ -237,24 +237,25 @@ void to_value(std::string s, Value* v) { void to_value(const ProtoList& vec, Value* v) { ::google::protobuf::ListValue l; for (const auto& val : vec) { - *l.add_values() = v2::to_proto(val); + *l.add_values() = to_proto(val); } *(v->mutable_list_value()) = std::move(l); } void to_value(const ProtoStruct& m, Value* v) { - *(v->mutable_struct_value()) = v2::to_proto(m); + *(v->mutable_struct_value()) = to_proto(m); } } // namespace proto_value_details namespace proto_convert_details { -void to_proto::operator()(const ProtoValue& self, google::protobuf::Value* v) const { +void to_proto_impl::operator()(const ProtoValue& self, + google::protobuf::Value* v) const { self.vtable_.to_value(self.self_.get(), v); } -ProtoValue from_proto::operator()( // NOLINT(misc-no-recursion) +ProtoValue from_proto_impl::operator()( // NOLINT(misc-no-recursion) const google::protobuf::Value* v) const { switch (v->kind_case()) { case Value::KindCase::kBoolValue: { @@ -270,13 +271,13 @@ ProtoValue from_proto::operator()( // NOLINT(misc-no-r ProtoList vec; vec.reserve(v->list_value().values_size()); for (const Value& list_val : v->list_value().values()) { - vec.push_back(v2::from_proto(list_val)); + vec.push_back(from_proto(list_val)); } return ProtoValue(std::move(vec)); } case Value::KindCase::kStructValue: { - return ProtoValue(v2::from_proto(v->struct_value())); + return ProtoValue(from_proto(v->struct_value())); } case Value::KindCase::KIND_NOT_SET: case Value::KindCase::kNullValue: @@ -285,19 +286,20 @@ ProtoValue from_proto::operator()( // NOLINT(misc-no-r } } -void to_proto::operator()(const ProtoStruct& self, google::protobuf::Struct* s) const { +void to_proto_impl::operator()(const ProtoStruct& self, + google::protobuf::Struct* s) const { for (const auto& kv : self) { s->mutable_fields()->insert( - google::protobuf::MapPair(kv.first, v2::to_proto(kv.second))); + google::protobuf::MapPair(kv.first, to_proto(kv.second))); } } -ProtoStruct from_proto::operator()( // NOLINT(misc-no-recursion) +ProtoStruct from_proto_impl::operator()( // NOLINT(misc-no-recursion) const google::protobuf::Struct* s) const { ProtoStruct result; for (const auto& val : s->fields()) { - result.emplace(val.first, v2::from_proto(val.second)); + result.emplace(val.first, from_proto(val.second)); } return result; diff --git a/src/viam/sdk/common/proto_value.hpp b/src/viam/sdk/common/proto_value.hpp index cc5102e80..9c9708bd0 100644 --- a/src/viam/sdk/common/proto_value.hpp +++ b/src/viam/sdk/common/proto_value.hpp @@ -54,7 +54,7 @@ struct all_moves_noexcept /// definition. class ProtoValue { public: - friend proto_convert_details::to_proto; + friend proto_convert_details::to_proto_impl; /// @brief Type discriminator constants for possible values stored in a ProtoValue. enum Kind { k_null = 0, k_bool = 1, k_double = 2, k_string = 3, k_list = 4, k_struct = 5 }; @@ -318,22 +318,22 @@ extern template ProtoStruct&& ProtoValue::get_unchecked() &&; namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const ProtoValue&, google::protobuf::Value*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const ProtoStruct&, google::protobuf::Struct*) const; }; template <> -struct from_proto { +struct from_proto_impl { ProtoValue operator()(const google::protobuf::Value*) const; }; template <> -struct from_proto { +struct from_proto_impl { ProtoStruct operator()(const google::protobuf::Struct*) const; }; diff --git a/src/viam/sdk/common/utils.cpp b/src/viam/sdk/common/utils.cpp index d6375cbde..5825c2e7f 100644 --- a/src/viam/sdk/common/utils.cpp +++ b/src/viam/sdk/common/utils.cpp @@ -30,7 +30,7 @@ bool operator==(const response_metadata& lhs, const response_metadata& rhs) { namespace proto_convert_details { -void to_proto::operator()(time_pt tp, google::protobuf::Timestamp* result) const { +void to_proto_impl::operator()(time_pt tp, google::protobuf::Timestamp* result) const { const std::chrono::nanoseconds since_epoch = tp.time_since_epoch(); const auto sec_floor = std::chrono::duration_cast(since_epoch); @@ -40,14 +40,14 @@ void to_proto::operator()(time_pt tp, google::protobuf::Timestamp* resu result->set_nanos(static_cast(nano_part.count())); } -time_pt from_proto::operator()( +time_pt from_proto_impl::operator()( const google::protobuf::Timestamp* timestamp) const { return time_pt{std::chrono::seconds{timestamp->seconds()} + std::chrono::nanoseconds{timestamp->nanos()}}; } -void to_proto::operator()(std::chrono::microseconds duration, - google::protobuf::Duration* proto) const { +void to_proto_impl::operator()(std::chrono::microseconds duration, + google::protobuf::Duration* proto) const { namespace sc = std::chrono; const sc::seconds seconds = sc::duration_cast(duration); @@ -57,7 +57,7 @@ void to_proto::operator()(std::chrono::microseconds d proto->set_seconds(seconds.count()); } -std::chrono::microseconds from_proto::operator()( +std::chrono::microseconds from_proto_impl::operator()( const google::protobuf::Duration* proto) const { namespace sc = std::chrono; const sc::seconds seconds_part{proto->seconds()}; @@ -74,14 +74,14 @@ std::chrono::microseconds from_proto::operator()( return from_seconds + from_nanos; } -void to_proto::operator()(const response_metadata& self, - common::v1::ResponseMetadata* proto) const { - *(proto->mutable_captured_at()) = v2::to_proto(self.captured_at); +void to_proto_impl::operator()(const response_metadata& self, + common::v1::ResponseMetadata* proto) const { + *(proto->mutable_captured_at()) = to_proto(self.captured_at); } -response_metadata from_proto::operator()( +response_metadata from_proto_impl::operator()( const common::v1::ResponseMetadata* proto) const { - return {v2::from_proto(proto->captured_at())}; + return {from_proto(proto->captured_at())}; } } // namespace proto_convert_details diff --git a/src/viam/sdk/common/utils.hpp b/src/viam/sdk/common/utils.hpp index 37ae3314a..f5067de55 100644 --- a/src/viam/sdk/common/utils.hpp +++ b/src/viam/sdk/common/utils.hpp @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -48,32 +49,32 @@ bool operator==(const response_metadata& lhs, const response_metadata& rhs); namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(time_pt, google::protobuf::Timestamp*) const; }; template <> -struct from_proto { +struct from_proto_impl { time_pt operator()(const google::protobuf::Timestamp*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(std::chrono::microseconds, google::protobuf::Duration*) const; }; template <> -struct from_proto { +struct from_proto_impl { std::chrono::microseconds operator()(const google::protobuf::Duration*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const response_metadata&, common::v1::ResponseMetadata*) const; }; template <> -struct from_proto { +struct from_proto_impl { response_metadata operator()(const common::v1::ResponseMetadata*) const; }; diff --git a/src/viam/sdk/common/world_state.cpp b/src/viam/sdk/common/world_state.cpp index 8b4fb7503..030a29931 100644 --- a/src/viam/sdk/common/world_state.cpp +++ b/src/viam/sdk/common/world_state.cpp @@ -36,43 +36,44 @@ bool operator==(const WorldState& lhs, const WorldState& rhs) { namespace proto_convert_details { -void to_proto::operator()( +void to_proto_impl::operator()( const WorldState::geometries_in_frame& self, common::v1::GeometriesInFrame* proto) const { *(proto->mutable_geometries()) = impl::to_repeated_field(self.geometries); *(proto->mutable_reference_frame()) = self.reference_frame; } -WorldState::geometries_in_frame from_proto::operator()( +WorldState::geometries_in_frame from_proto_impl::operator()( const common::v1::GeometriesInFrame* proto) const { return {impl::from_repeated_field(proto->geometries()), proto->reference_frame()}; } -void to_proto::operator()(const WorldState::transform& self, - common::v1::Transform* proto) const { +void to_proto_impl::operator()(const WorldState::transform& self, + common::v1::Transform* proto) const { *(proto->mutable_reference_frame()) = self.reference_frame; - *(proto->mutable_pose_in_observer_frame()) = v2::to_proto(self.pose_in_observer_frame); + *(proto->mutable_pose_in_observer_frame()) = to_proto(self.pose_in_observer_frame); if (self.physical_object) { - *(proto->mutable_physical_object()) = v2::to_proto(*self.physical_object); + *(proto->mutable_physical_object()) = to_proto(*self.physical_object); } } -WorldState::transform from_proto::operator()( +WorldState::transform from_proto_impl::operator()( const common::v1::Transform* proto) const { WorldState::transform result{proto->reference_frame(), - v2::from_proto(proto->pose_in_observer_frame())}; + from_proto(proto->pose_in_observer_frame())}; if (proto->has_physical_object()) { - result.physical_object = v2::from_proto(proto->physical_object()); + result.physical_object = from_proto(proto->physical_object()); } return result; } -void to_proto::operator()(const WorldState& self, common::v1::WorldState* proto) const { +void to_proto_impl::operator()(const WorldState& self, + common::v1::WorldState* proto) const { *(proto->mutable_obstacles()) = impl::to_repeated_field(self.obstacles()); *(proto->mutable_transforms()) = impl::to_repeated_field(self.transforms()); } -WorldState from_proto::operator()( +WorldState from_proto_impl::operator()( const common::v1::WorldState* proto) const { return WorldState(impl::from_repeated_field(proto->obstacles()), impl::from_repeated_field(proto->transforms())); diff --git a/src/viam/sdk/common/world_state.hpp b/src/viam/sdk/common/world_state.hpp index aa9fe62b2..17b51e411 100644 --- a/src/viam/sdk/common/world_state.hpp +++ b/src/viam/sdk/common/world_state.hpp @@ -54,32 +54,32 @@ class WorldState { namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const WorldState::geometries_in_frame&, common::v1::GeometriesInFrame*) const; }; template <> -struct from_proto { +struct from_proto_impl { WorldState::geometries_in_frame operator()(const common::v1::GeometriesInFrame*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const WorldState::transform&, common::v1::Transform*) const; }; template <> -struct from_proto { +struct from_proto_impl { WorldState::transform operator()(const common::v1::Transform*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const WorldState&, common::v1::WorldState*) const; }; template <> -struct from_proto { +struct from_proto_impl { WorldState operator()(const common::v1::WorldState*) const; }; diff --git a/src/viam/sdk/components/private/arm_client.cpp b/src/viam/sdk/components/private/arm_client.cpp index ea889d1e4..619580ad4 100644 --- a/src/viam/sdk/components/private/arm_client.cpp +++ b/src/viam/sdk/components/private/arm_client.cpp @@ -17,12 +17,12 @@ ArmClient::ArmClient(std::string name, std::shared_ptr channel) pose ArmClient::get_end_position(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetEndPosition) .with(extra) - .invoke([&](auto& response) { return v2::from_proto(response.pose()); }); + .invoke([&](auto& response) { return from_proto(response.pose()); }); } void ArmClient::move_to_position(const pose& pose, const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::MoveToPosition) - .with(extra, [&](auto& request) { *request.mutable_to() = v2::to_proto(pose); }) + .with(extra, [&](auto& request) { *request.mutable_to() = to_proto(pose); }) .invoke(); } @@ -83,8 +83,8 @@ void ArmClient::stop(const ProtoStruct& extra) { ProtoStruct ArmClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } Arm::KinematicsData ArmClient::get_kinematics(const ProtoStruct& extra) { @@ -109,7 +109,7 @@ Arm::KinematicsData ArmClient::get_kinematics(const ProtoStruct& extra) { std::vector ArmClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/arm_server.cpp b/src/viam/sdk/components/private/arm_server.cpp index 7e1be85c9..3c1970412 100644 --- a/src/viam/sdk/components/private/arm_server.cpp +++ b/src/viam/sdk/components/private/arm_server.cpp @@ -16,7 +16,7 @@ ::grpc::Status ArmServer::GetEndPosition( return make_service_helper( "ArmServer::GetEndPosition", this, request)([&](auto& helper, auto& arm) { const pose p = arm->get_end_position(helper.getExtra()); - *response->mutable_pose() = v2::to_proto(p); + *response->mutable_pose() = to_proto(p); }); } @@ -26,7 +26,7 @@ ::grpc::Status ArmServer::MoveToPosition( ::viam::component::arm::v1::MoveToPositionResponse*) noexcept { return make_service_helper( "ArmServer::MoveToPosition", this, request)([&](auto& helper, auto& arm) { - arm->move_to_position(v2::from_proto(request->to()), helper.getExtra()); + arm->move_to_position(from_proto(request->to()), helper.getExtra()); }); } @@ -98,8 +98,8 @@ ::grpc::Status ArmServer::DoCommand(::grpc::ServerContext*, const ::viam::common::v1::DoCommandRequest* request, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper("ArmServer::DoCommand", this, request)([&](auto&, auto& arm) { - const ProtoStruct result = arm->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = arm->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } @@ -143,7 +143,7 @@ ::grpc::Status ArmServer::GetGeometries( "ArmServer::GetGeometries", this, request)([&](auto& helper, auto& arm) { const std::vector geometries = arm->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } diff --git a/src/viam/sdk/components/private/base_client.cpp b/src/viam/sdk/components/private/base_client.cpp index 93623d04c..03be9d2cb 100644 --- a/src/viam/sdk/components/private/base_client.cpp +++ b/src/viam/sdk/components/private/base_client.cpp @@ -53,8 +53,8 @@ void BaseClient::set_power(const Vector3& linear, return make_client_helper(this, *stub_, &StubType::SetPower) .with(extra, [&](auto& request) { - *request.mutable_linear() = v2::to_proto(linear); - *request.mutable_angular() = v2::to_proto(angular); + *request.mutable_linear() = to_proto(linear); + *request.mutable_angular() = to_proto(angular); }) .invoke(); } @@ -65,8 +65,8 @@ void BaseClient::set_velocity(const Vector3& linear, return make_client_helper(this, *stub_, &StubType::SetVelocity) .with(extra, [&](auto& request) { - *request.mutable_linear() = v2::to_proto(linear); - *request.mutable_angular() = v2::to_proto(angular); + *request.mutable_linear() = to_proto(linear); + *request.mutable_angular() = to_proto(angular); }) .invoke(); } @@ -84,7 +84,7 @@ bool BaseClient::is_moving() { std::vector BaseClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } Base::properties BaseClient::get_properties(const ProtoStruct& extra) { @@ -99,8 +99,8 @@ Base::properties BaseClient::get_properties(const ProtoStruct& extra) { ProtoStruct BaseClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/base_server.cpp b/src/viam/sdk/components/private/base_server.cpp index 2a2cdd130..e7bbfbc91 100644 --- a/src/viam/sdk/components/private/base_server.cpp +++ b/src/viam/sdk/components/private/base_server.cpp @@ -40,8 +40,8 @@ ::grpc::Status BaseServer::SetPower(::grpc::ServerContext*, ::viam::component::base::v1::SetPowerResponse*) noexcept { return make_service_helper( "BaseServer::SetPower", this, request)([&](auto& helper, auto& base) { - auto linear = v2::from_proto(request->linear()); - auto angular = v2::from_proto(request->angular()); + auto linear = from_proto(request->linear()); + auto angular = from_proto(request->angular()); base->set_power(linear, angular, helper.getExtra()); }); } @@ -52,8 +52,8 @@ ::grpc::Status BaseServer::SetVelocity( ::viam::component::base::v1::SetVelocityResponse*) noexcept { return make_service_helper( "BaseServer::SetVelocity", this, request)([&](auto& helper, auto& base) { - auto linear = v2::from_proto(request->linear()); - auto angular = v2::from_proto(request->angular()); + auto linear = from_proto(request->linear()); + auto angular = from_proto(request->angular()); base->set_velocity(linear, angular, helper.getExtra()); }); } @@ -83,7 +83,7 @@ ::grpc::Status BaseServer::GetGeometries( "BaseServer::GetGeometries", this, request)([&](auto& helper, auto& base) { const std::vector geometries = base->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } @@ -106,8 +106,8 @@ ::grpc::Status BaseServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "BaseServer::DoCommand", this, request)([&](auto&, auto& base) { - const ProtoStruct result = base->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = base->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } diff --git a/src/viam/sdk/components/private/board_client.cpp b/src/viam/sdk/components/private/board_client.cpp index 467be22fa..7bd7a6935 100644 --- a/src/viam/sdk/components/private/board_client.cpp +++ b/src/viam/sdk/components/private/board_client.cpp @@ -20,6 +20,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + viam::component::board::v1::Status to_proto(const Board::status& status) { viam::component::board::v1::Status proto; for (const auto& analog : status.analog_reader_values) { @@ -105,8 +108,8 @@ void BoardClient::set_pwm_frequency(const std::string& pin, ProtoStruct BoardClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } // TODO(RSDK-6048) update `client_wrapper` to allow for requests without a `mutable_name()` method, @@ -119,7 +122,7 @@ Board::analog_response BoardClient::read_analog(const std::string& analog_reader request.set_board_name(this->name()); request.set_analog_reader_name(analog_reader_name); - *request.mutable_extra() = v2::to_proto(extra); + *request.mutable_extra() = to_proto(extra); const grpc::Status status = stub_->ReadAnalogReader(ctx, request, &response); if (!status.ok()) { @@ -149,7 +152,7 @@ Board::digital_value BoardClient::read_digital_interrupt(const std::string& digi request.set_board_name(this->name()); request.set_digital_interrupt_name(digital_interrupt_name); - *request.mutable_extra() = v2::to_proto(extra); + *request.mutable_extra() = to_proto(extra); const grpc::Status status = stub_->GetDigitalInterruptValue(ctx, request, &response); if (!status.ok()) { @@ -182,7 +185,7 @@ void BoardClient::set_power_mode(power_mode power_mode, [&](auto& request) { request.set_power_mode(to_proto(power_mode)); if (duration.has_value()) { - *request.mutable_duration() = v2::to_proto(duration.get()); + *request.mutable_duration() = to_proto(duration.get()); } }) .invoke(); @@ -191,7 +194,7 @@ void BoardClient::set_power_mode(power_mode power_mode, std::vector BoardClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); }; } // namespace impl diff --git a/src/viam/sdk/components/private/board_server.cpp b/src/viam/sdk/components/private/board_server.cpp index c352b7589..9576e9bcd 100644 --- a/src/viam/sdk/components/private/board_server.cpp +++ b/src/viam/sdk/components/private/board_server.cpp @@ -12,6 +12,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + Board::status from_proto(const viam::component::board::v1::Status& proto) { Board::status status; for (const auto& analog : proto.analogs()) { @@ -105,8 +108,8 @@ ::grpc::Status BoardServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "BoardServer::DoCommand", this, request)([&](auto&, auto& board) { - const ProtoStruct result = board->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = board->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } @@ -128,7 +131,7 @@ ::grpc::Status BoardServer::ReadAnalogReader( ProtoStruct extra; if (request->has_extra()) { - extra = v2::from_proto(request->extra()); + extra = from_proto(request->extra()); } const Board::analog_response result = board->read_analog(request->analog_reader_name(), extra); @@ -158,7 +161,7 @@ ::grpc::Status BoardServer::WriteAnalog( ProtoStruct extra; if (request->has_extra()) { - extra = v2::from_proto(request->extra()); + extra = from_proto(request->extra()); } board->write_analog(request->pin(), request->value(), extra); @@ -183,7 +186,7 @@ ::grpc::Status BoardServer::GetDigitalInterruptValue( ProtoStruct extra; if (request->has_extra()) { - extra = v2::from_proto(request->extra()); + extra = from_proto(request->extra()); } const Board::digital_value result = @@ -226,7 +229,7 @@ ::grpc::Status BoardServer::SetPowerMode( return make_service_helper( "BoardServer::SetPowerMode", this, request)([&](auto& helper, auto& board) { if (request->has_duration()) { - auto duration = v2::from_proto(request->duration()); + auto duration = from_proto(request->duration()); board->set_power_mode(from_proto(request->power_mode()), helper.getExtra(), duration); } else { board->set_power_mode(from_proto(request->power_mode()), helper.getExtra()); @@ -242,7 +245,7 @@ ::grpc::Status BoardServer::GetGeometries( "BoardServer::GetGeometries", this, request)([&](auto& helper, auto& board) { const std::vector geometries = board->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } diff --git a/src/viam/sdk/components/private/camera_client.cpp b/src/viam/sdk/components/private/camera_client.cpp index 0818bfb39..ec09856fc 100644 --- a/src/viam/sdk/components/private/camera_client.cpp +++ b/src/viam/sdk/components/private/camera_client.cpp @@ -18,6 +18,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + std::string format_to_MIME_string(viam::component::camera::v1::Format format) { switch (format) { case viam::component::camera::v1::FORMAT_RAW_RGBA: @@ -56,7 +59,7 @@ Camera::image_collection from_proto(const viam::component::camera::v1::GetImages images.push_back(raw_image); } image_collection.images = std::move(images); - image_collection.metadata = v2::from_proto(proto.response_metadata()); + image_collection.metadata = from_proto(proto.response_metadata()); return image_collection; } @@ -106,8 +109,8 @@ CameraClient::CameraClient(std::string name, std::shared_ptr chan ProtoStruct CameraClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); }; Camera::raw_image CameraClient::get_image(std::string mime_type, const ProtoStruct& extra) { @@ -134,7 +137,7 @@ Camera::point_cloud CameraClient::get_point_cloud(std::string mime_type, const P std::vector CameraClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); }; Camera::properties CameraClient::get_properties() { diff --git a/src/viam/sdk/components/private/camera_server.cpp b/src/viam/sdk/components/private/camera_server.cpp index c5d32b691..2ef91da21 100644 --- a/src/viam/sdk/components/private/camera_server.cpp +++ b/src/viam/sdk/components/private/camera_server.cpp @@ -42,8 +42,8 @@ ::grpc::Status CameraServer::DoCommand(::grpc::ServerContext*, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "CameraServer::DoCommand", this, request)([&](auto&, auto& camera) { - const ProtoStruct result = camera->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = camera->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } @@ -94,7 +94,7 @@ ::grpc::Status CameraServer::GetImages( proto_image.set_image(img_string); *response->mutable_images()->Add() = std::move(proto_image); } - *response->mutable_response_metadata() = v2::to_proto(image_coll.metadata); + *response->mutable_response_metadata() = to_proto(image_coll.metadata); }); } @@ -132,7 +132,7 @@ ::grpc::Status CameraServer::GetGeometries( "CameraServer::GetGeometries", this, request)([&](auto& helper, auto& camera) { const std::vector geometries = camera->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } diff --git a/src/viam/sdk/components/private/encoder_client.cpp b/src/viam/sdk/components/private/encoder_client.cpp index 320b095bd..7ccbc3fa9 100644 --- a/src/viam/sdk/components/private/encoder_client.cpp +++ b/src/viam/sdk/components/private/encoder_client.cpp @@ -18,6 +18,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + viam::component::encoder::v1::GetPositionResponse to_proto(const Encoder::position& position) { viam::component::encoder::v1::GetPositionResponse proto; proto.set_value(position.value); @@ -67,13 +70,13 @@ Encoder::properties EncoderClient::get_properties(const ProtoStruct& extra) { std::vector EncoderClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); }; ProtoStruct EncoderClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/encoder_server.cpp b/src/viam/sdk/components/private/encoder_server.cpp index 14273cd2f..be9e95ee3 100644 --- a/src/viam/sdk/components/private/encoder_server.cpp +++ b/src/viam/sdk/components/private/encoder_server.cpp @@ -12,6 +12,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + EncoderServer::EncoderServer(std::shared_ptr manager) : ResourceServer(std::move(manager)) {} @@ -56,7 +59,7 @@ ::grpc::Status EncoderServer::GetGeometries( "EncoderServer::GetGeometries", this, request)([&](auto& helper, auto& encoder) { const std::vector geometries = encoder->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } @@ -66,8 +69,8 @@ ::grpc::Status EncoderServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "EncoderServer::DoCommand", this, request)([&](auto&, auto& encoder) { - const ProtoStruct result = encoder->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = encoder->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } diff --git a/src/viam/sdk/components/private/gantry_client.cpp b/src/viam/sdk/components/private/gantry_client.cpp index 028c1c55f..7021dd5bc 100644 --- a/src/viam/sdk/components/private/gantry_client.cpp +++ b/src/viam/sdk/components/private/gantry_client.cpp @@ -65,14 +65,14 @@ void GantryClient::stop(const ProtoStruct& extra) { ProtoStruct GantryClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } std::vector GantryClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/gantry_server.cpp b/src/viam/sdk/components/private/gantry_server.cpp index e0e59dde6..a4c921c67 100644 --- a/src/viam/sdk/components/private/gantry_server.cpp +++ b/src/viam/sdk/components/private/gantry_server.cpp @@ -75,8 +75,8 @@ ::grpc::Status GantryServer::DoCommand(::grpc::ServerContext*, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "GantryServer::DoCommand", this, request)([&](auto&, auto& gantry) { - const ProtoStruct result = gantry->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = gantry->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } @@ -88,7 +88,7 @@ ::grpc::Status GantryServer::GetGeometries( "GantryServer::GetGeometries", this, request)([&](auto& helper, auto& gantry) { const std::vector geometries = gantry->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } diff --git a/src/viam/sdk/components/private/generic_client.cpp b/src/viam/sdk/components/private/generic_client.cpp index ec062a860..2bb654539 100644 --- a/src/viam/sdk/components/private/generic_client.cpp +++ b/src/viam/sdk/components/private/generic_client.cpp @@ -23,14 +23,14 @@ GenericComponentClient::GenericComponentClient(std::string name, ProtoStruct GenericComponentClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } std::vector GenericComponentClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/generic_server.cpp b/src/viam/sdk/components/private/generic_server.cpp index b226082ed..1a4777ff2 100644 --- a/src/viam/sdk/components/private/generic_server.cpp +++ b/src/viam/sdk/components/private/generic_server.cpp @@ -17,8 +17,8 @@ ::grpc::Status GenericComponentServer::DoCommand( ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "GenericComponentServer::DoCommand", this, request)([&](auto&, auto& generic) { - const ProtoStruct result = generic->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = generic->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } ::grpc::Status GenericComponentServer::GetGeometries( @@ -29,7 +29,7 @@ ::grpc::Status GenericComponentServer::GetGeometries( "GenericComponentServer::GetGeometries", this, request)([&](auto& helper, auto& generic) { const std::vector geometries = generic->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } diff --git a/src/viam/sdk/components/private/gripper_client.cpp b/src/viam/sdk/components/private/gripper_client.cpp index 6e77fd52a..439517bff 100644 --- a/src/viam/sdk/components/private/gripper_client.cpp +++ b/src/viam/sdk/components/private/gripper_client.cpp @@ -38,14 +38,14 @@ void GripperClient::stop(const ProtoStruct& extra) { ProtoStruct GripperClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } std::vector GripperClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/gripper_server.cpp b/src/viam/sdk/components/private/gripper_server.cpp index 3963c7fb4..9205d96fe 100644 --- a/src/viam/sdk/components/private/gripper_server.cpp +++ b/src/viam/sdk/components/private/gripper_server.cpp @@ -46,8 +46,8 @@ ::grpc::Status GripperServer::DoCommand(::grpc::ServerContext*, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "GripperServer::DoCommand", this, request)([&](auto&, auto& gripper) { - const ProtoStruct result = gripper->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = gripper->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } @@ -59,7 +59,7 @@ ::grpc::Status GripperServer::GetGeometries( "GripperServer::GetGeometries", this, request)([&](auto& helper, auto& gripper) { const std::vector geometries = gripper->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } diff --git a/src/viam/sdk/components/private/motor_client.cpp b/src/viam/sdk/components/private/motor_client.cpp index bad14ccc6..e0f112b6a 100644 --- a/src/viam/sdk/components/private/motor_client.cpp +++ b/src/viam/sdk/components/private/motor_client.cpp @@ -16,6 +16,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + Motor::position from_proto(const viam::component::motor::v1::GetPositionResponse& proto) { return proto.position(); } @@ -102,7 +105,7 @@ Motor::power_status MotorClient::get_power_status(const ProtoStruct& extra) { std::vector MotorClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } bool MotorClient::is_moving() { @@ -113,8 +116,8 @@ bool MotorClient::is_moving() { ProtoStruct MotorClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/motor_server.cpp b/src/viam/sdk/components/private/motor_server.cpp index 7b7fd3a55..dca942fe2 100644 --- a/src/viam/sdk/components/private/motor_server.cpp +++ b/src/viam/sdk/components/private/motor_server.cpp @@ -118,7 +118,7 @@ ::grpc::Status MotorServer::GetGeometries( "MotorServer::GetGeometries", this, request)([&](auto& helper, auto& motor) { const std::vector geometries = motor->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } @@ -128,8 +128,8 @@ ::grpc::Status MotorServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "MotorServer::GetGeometries", this, request)([&](auto&, auto& motor) { - const ProtoStruct result = motor->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = motor->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } diff --git a/src/viam/sdk/components/private/movement_sensor_client.cpp b/src/viam/sdk/components/private/movement_sensor_client.cpp index 40eeddcde..ec9b19ee0 100644 --- a/src/viam/sdk/components/private/movement_sensor_client.cpp +++ b/src/viam/sdk/components/private/movement_sensor_client.cpp @@ -17,6 +17,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + MovementSensor::compassheading from_proto( const viam::component::movementsensor::v1::GetCompassHeadingResponse& proto) { MovementSensor::compassheading compassheading; @@ -27,7 +30,7 @@ MovementSensor::compassheading from_proto( MovementSensor::position from_proto( const viam::component::movementsensor::v1::GetPositionResponse& proto) { MovementSensor::position position; - position.coordinate = v2::from_proto(proto.coordinate()); + position.coordinate = from_proto(proto.coordinate()); position.altitude_m = proto.altitude_m(); return position; } @@ -63,13 +66,13 @@ using namespace viam::component::movementsensor::v1; Vector3 MovementSensorClient::get_linear_velocity(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetLinearVelocity) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response.linear_velocity()); }); + .invoke([](auto& response) { return from_proto(response.linear_velocity()); }); } Vector3 MovementSensorClient::get_angular_velocity(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetAngularVelocity) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response.angular_velocity()); }); + .invoke([](auto& response) { return from_proto(response.angular_velocity()); }); } MovementSensor::compassheading MovementSensorClient::get_compass_heading(const ProtoStruct& extra) { @@ -112,19 +115,19 @@ std::unordered_map MovementSensorClient::get_accuracy( Vector3 MovementSensorClient::get_linear_acceleration(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetLinearAcceleration) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response.linear_acceleration()); }); + .invoke([](auto& response) { return from_proto(response.linear_acceleration()); }); } ProtoStruct MovementSensorClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } std::vector MovementSensorClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/movement_sensor_server.cpp b/src/viam/sdk/components/private/movement_sensor_server.cpp index a0317a4f6..21c02fede 100644 --- a/src/viam/sdk/components/private/movement_sensor_server.cpp +++ b/src/viam/sdk/components/private/movement_sensor_server.cpp @@ -33,7 +33,7 @@ ::grpc::Status MovementSensorServer::GetLinearVelocity( this, request)([&](auto& helper, auto& movementsensor) { const Vector3 result = movementsensor->get_linear_velocity(helper.getExtra()); - *response->mutable_linear_velocity() = v2::to_proto(result); + *response->mutable_linear_velocity() = to_proto(result); }); } @@ -45,7 +45,7 @@ ::grpc::Status MovementSensorServer::GetAngularVelocity( this, request)([&](auto& helper, auto& movementsensor) { const Vector3 result = movementsensor->get_angular_velocity(helper.getExtra()); - *response->mutable_angular_velocity() = v2::to_proto(result); + *response->mutable_angular_velocity() = to_proto(result); }); } @@ -80,7 +80,7 @@ ::grpc::Status MovementSensorServer::GetPosition(::grpc::ServerContext*, return make_service_helper("MovementSensorServer::GetPosition", this, request)( [&](auto& helper, auto& movementsensor) { const MovementSensor::position result = movementsensor->get_position(helper.getExtra()); - *response->mutable_coordinate() = v2::to_proto(result.coordinate); + *response->mutable_coordinate() = to_proto(result.coordinate); response->set_altitude_m(result.altitude_m); }); } @@ -121,7 +121,7 @@ ::grpc::Status MovementSensorServer::GetLinearAcceleration( this, request)([&](auto& helper, auto& movementsensor) { const Vector3 result = movementsensor->get_linear_acceleration(helper.getExtra()); - *response->mutable_linear_acceleration() = v2::to_proto(result); + *response->mutable_linear_acceleration() = to_proto(result); }); } @@ -131,8 +131,8 @@ ::grpc::Status MovementSensorServer::DoCommand( viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "MovementSensorServer::DoCommand", this, request)([&](auto&, auto& movementsensor) { - const ProtoStruct result = movementsensor->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = movementsensor->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } @@ -145,7 +145,7 @@ ::grpc::Status MovementSensorServer::GetGeometries( request)([&](auto& helper, auto& movementsensor) { const auto geometries = movementsensor->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } diff --git a/src/viam/sdk/components/private/pose_tracker_client.cpp b/src/viam/sdk/components/private/pose_tracker_client.cpp index 25e1f3490..234244ef6 100644 --- a/src/viam/sdk/components/private/pose_tracker_client.cpp +++ b/src/viam/sdk/components/private/pose_tracker_client.cpp @@ -25,7 +25,7 @@ PoseTracker::pose_map PoseTrackerClient::get_poses(const std::vector PoseTrackerClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } ProtoStruct PoseTrackerClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/pose_tracker_server.cpp b/src/viam/sdk/components/private/pose_tracker_server.cpp index 4a7e5afdf..5ba2f93fa 100644 --- a/src/viam/sdk/components/private/pose_tracker_server.cpp +++ b/src/viam/sdk/components/private/pose_tracker_server.cpp @@ -25,7 +25,7 @@ ::grpc::Status PoseTrackerServer::GetPoses( {request->body_names().begin(), request->body_names().end()}, helper.getExtra()); for (const auto& pair : result) { - response->mutable_body_poses()->insert({pair.first, v2::to_proto(pair.second)}); + response->mutable_body_poses()->insert({pair.first, to_proto(pair.second)}); } }); } @@ -36,8 +36,8 @@ ::grpc::Status PoseTrackerServer::DoCommand( viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "PoseTrackerServer::DoCommand", this, request)([&](auto&, auto& pose_tracker) { - const ProtoStruct result = pose_tracker->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = pose_tracker->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } @@ -50,7 +50,7 @@ ::grpc::Status PoseTrackerServer::GetGeometries( const std::vector geometries = pose_tracker->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } diff --git a/src/viam/sdk/components/private/power_sensor_client.cpp b/src/viam/sdk/components/private/power_sensor_client.cpp index 4c064b9ca..556dbf1a3 100644 --- a/src/viam/sdk/components/private/power_sensor_client.cpp +++ b/src/viam/sdk/components/private/power_sensor_client.cpp @@ -21,6 +21,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + PowerSensor::voltage from_proto(const GetVoltageResponse& proto) { PowerSensor::voltage v; v.volts = proto.volts(); @@ -64,7 +67,7 @@ ProtoStruct PowerSensorClient::get_readings(const ProtoStruct& extra) { .invoke([](auto& response) { ProtoStruct result; for (const auto& r : response.readings()) { - result.emplace(r.first, v2::from_proto(r.second)); + result.emplace(r.first, from_proto(r.second)); } return result; }); @@ -72,8 +75,8 @@ ProtoStruct PowerSensorClient::get_readings(const ProtoStruct& extra) { ProtoStruct PowerSensorClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/power_sensor_server.cpp b/src/viam/sdk/components/private/power_sensor_server.cpp index e9f5ccc00..713a30be9 100644 --- a/src/viam/sdk/components/private/power_sensor_server.cpp +++ b/src/viam/sdk/components/private/power_sensor_server.cpp @@ -66,7 +66,7 @@ ::grpc::Status PowerSensorServer::GetReadings( return make_service_helper( "PowerSensorServer::GetReadings", this, request)([&](auto& helper, auto& powersensor) { *(response->mutable_readings()) = - v2::to_proto(powersensor->get_readings(helper.getExtra())).fields(); + to_proto(powersensor->get_readings(helper.getExtra())).fields(); }); } @@ -76,8 +76,8 @@ ::grpc::Status PowerSensorServer::DoCommand( viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "PowerSensorServer::DoCommand", this, request)([&](auto&, auto& powersensor) { - const ProtoStruct result = powersensor->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = powersensor->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } diff --git a/src/viam/sdk/components/private/sensor_client.cpp b/src/viam/sdk/components/private/sensor_client.cpp index b28811dd1..b1b7bce6c 100644 --- a/src/viam/sdk/components/private/sensor_client.cpp +++ b/src/viam/sdk/components/private/sensor_client.cpp @@ -29,7 +29,7 @@ ProtoStruct SensorClient::get_readings(const ProtoStruct& extra) { .invoke([](auto& response) { ProtoStruct result; for (const auto& r : response.readings()) { - result.emplace(r.first, v2::from_proto(r.second)); + result.emplace(r.first, from_proto(r.second)); } return result; }); @@ -37,14 +37,14 @@ ProtoStruct SensorClient::get_readings(const ProtoStruct& extra) { ProtoStruct SensorClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } std::vector SensorClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/sensor_server.cpp b/src/viam/sdk/components/private/sensor_server.cpp index 2a8cd3755..f39e55080 100644 --- a/src/viam/sdk/components/private/sensor_server.cpp +++ b/src/viam/sdk/components/private/sensor_server.cpp @@ -21,7 +21,7 @@ ::grpc::Status SensorServer::GetReadings(::grpc::ServerContext*, return make_service_helper( "SensorServer::GetReadings", this, request)([&](auto& helper, auto& sensor) { *(response->mutable_readings()) = - v2::to_proto(sensor->get_readings(helper.getExtra())).fields(); + to_proto(sensor->get_readings(helper.getExtra())).fields(); }); } @@ -30,8 +30,8 @@ ::grpc::Status SensorServer::DoCommand(grpc::ServerContext*, DoCommandResponse* response) noexcept { return make_service_helper( "SensorServer::DoCommand", this, request)([&](auto&, auto& sensor) { - const ProtoStruct result = sensor->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = sensor->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } @@ -42,7 +42,7 @@ ::grpc::Status SensorServer::GetGeometries(::grpc::ServerContext*, "SensorServer::GetGeometries", this, request)([&](auto& helper, auto& sensor) { const auto geometries = sensor->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } diff --git a/src/viam/sdk/components/private/servo_client.cpp b/src/viam/sdk/components/private/servo_client.cpp index eb5004e84..189e4d86a 100644 --- a/src/viam/sdk/components/private/servo_client.cpp +++ b/src/viam/sdk/components/private/servo_client.cpp @@ -18,6 +18,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + Servo::position from_proto(const viam::component::servo::v1::GetPositionResponse& proto) { return proto.position_deg(); } @@ -52,13 +55,13 @@ bool ServoClient::is_moving() { std::vector ServoClient::get_geometries(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetGeometries) .with(extra) - .invoke([](auto& response) { return v2::from_proto(response); }); + .invoke([](auto& response) { return from_proto(response); }); } ProtoStruct ServoClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/servo_server.cpp b/src/viam/sdk/components/private/servo_server.cpp index 83f31ad60..2cd7db754 100644 --- a/src/viam/sdk/components/private/servo_server.cpp +++ b/src/viam/sdk/components/private/servo_server.cpp @@ -57,7 +57,7 @@ ::grpc::Status ServoServer::GetGeometries( "ServoServer::GetGeometries", this, request)([&](auto& helper, auto& servo) { const std::vector geometries = servo->get_geometries(helper.getExtra()); for (const auto& geometry : geometries) { - *response->mutable_geometries()->Add() = v2::to_proto(geometry); + *response->mutable_geometries()->Add() = to_proto(geometry); } }); } @@ -67,8 +67,8 @@ ::grpc::Status ServoServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "ServoServer::GetGeometries", this, request)([&](auto&, auto& servo) { - const ProtoStruct result = servo->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = servo->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } diff --git a/src/viam/sdk/config/resource.cpp b/src/viam/sdk/config/resource.cpp index 4402af7d7..f566a0bae 100644 --- a/src/viam/sdk/config/resource.cpp +++ b/src/viam/sdk/config/resource.cpp @@ -122,14 +122,14 @@ void ResourceConfig::fix_api() { namespace proto_convert_details { -void to_proto::operator()( +void to_proto_impl::operator()( const ResourceLevelServiceConfig& self, app::v1::ResourceLevelServiceConfig* proto) const { *proto->mutable_type() = self.type; - *proto->mutable_attributes() = v2::to_proto(self.attributes); + *proto->mutable_attributes() = to_proto(self.attributes); } -void to_proto::operator()(const ResourceConfig& self, - app::v1::ComponentConfig* proto) const { +void to_proto_impl::operator()(const ResourceConfig& self, + app::v1::ComponentConfig* proto) const { *proto->mutable_service_configs() = impl::to_repeated_field(self.service_config()); *proto->mutable_name() = self.name(); @@ -137,23 +137,23 @@ void to_proto::operator()(const ResourceConfig& self, *proto->mutable_type() = self.type(); *proto->mutable_api() = self.api().to_string(); *proto->mutable_model() = self.model().to_string(); - *proto->mutable_attributes() = v2::to_proto(self.attributes()); + *proto->mutable_attributes() = to_proto(self.attributes()); *proto->mutable_depends_on() = ::google::protobuf::RepeatedPtrField( self.depends_on().begin(), self.depends_on().end()); - *proto->mutable_frame() = v2::to_proto(self.frame()); + *proto->mutable_frame() = to_proto(self.frame()); } -ResourceConfig from_proto::operator()( +ResourceConfig from_proto_impl::operator()( const app::v1::ComponentConfig* proto) const { return ResourceConfig(proto->type(), proto->name(), proto->namespace_(), - v2::from_proto(proto->attributes()), + from_proto(proto->attributes()), proto->api(), Model::from_str(proto->model()), - proto->has_frame() ? v2::from_proto(proto->frame()) : LinkConfig{}); + proto->has_frame() ? from_proto(proto->frame()) : LinkConfig{}); } } // namespace proto_convert_details diff --git a/src/viam/sdk/config/resource.hpp b/src/viam/sdk/config/resource.hpp index 4fcaf1725..c5822135e 100644 --- a/src/viam/sdk/config/resource.hpp +++ b/src/viam/sdk/config/resource.hpp @@ -69,17 +69,17 @@ class ResourceConfig { namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const ResourceLevelServiceConfig&, app::v1::ResourceLevelServiceConfig*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const ResourceConfig&, app::v1::ComponentConfig*) const; }; template <> -struct from_proto { +struct from_proto_impl { ResourceConfig operator()(const app::v1::ComponentConfig*) const; }; diff --git a/src/viam/sdk/module/handler_map.cpp b/src/viam/sdk/module/handler_map.cpp index 3d58555c6..4d2ba34bf 100644 --- a/src/viam/sdk/module/handler_map.cpp +++ b/src/viam/sdk/module/handler_map.cpp @@ -33,8 +33,8 @@ std::ostream& operator<<(std::ostream& os, const HandlerMap_& hm) { namespace proto_convert_details { -void to_proto::operator()(const HandlerMap_& self, - module::v1::HandlerMap* proto) const { +void to_proto_impl::operator()(const HandlerMap_& self, + module::v1::HandlerMap* proto) const { for (const auto& h : self.handles()) { viam::module::v1::HandlerDefinition hd; for (const auto& model : h.second) { @@ -43,7 +43,7 @@ void to_proto::operator()(const HandlerMap_& self, viam::robot::v1::ResourceRPCSubtype rpc_subtype; - *rpc_subtype.mutable_subtype() = v2::to_proto(Name(h.first.api(), "", "")); + *rpc_subtype.mutable_subtype() = to_proto(Name(h.first.api(), "", "")); *rpc_subtype.mutable_proto_service() = h.first.proto_service_name(); *hd.mutable_subtype() = rpc_subtype; @@ -51,7 +51,7 @@ void to_proto::operator()(const HandlerMap_& self, } } -HandlerMap_ from_proto::operator()( +HandlerMap_ from_proto_impl::operator()( const module::v1::HandlerMap* proto) const { HandlerMap_ hm; diff --git a/src/viam/sdk/module/handler_map.hpp b/src/viam/sdk/module/handler_map.hpp index 057577ac9..efee2c002 100644 --- a/src/viam/sdk/module/handler_map.hpp +++ b/src/viam/sdk/module/handler_map.hpp @@ -33,12 +33,12 @@ std::ostream& operator<<(std::ostream& os, const HandlerMap_& hm); namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const HandlerMap_&, module::v1::HandlerMap*) const; }; template <> -struct from_proto { +struct from_proto_impl { HandlerMap_ operator()(const module::v1::HandlerMap*) const; }; diff --git a/src/viam/sdk/module/service.cpp b/src/viam/sdk/module/service.cpp index 7a5cfa6b1..53f1fe9bc 100644 --- a/src/viam/sdk/module/service.cpp +++ b/src/viam/sdk/module/service.cpp @@ -51,7 +51,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service { const ::viam::module::v1::AddResourceRequest* request, ::viam::module::v1::AddResourceResponse*) override { const viam::app::v1::ComponentConfig& proto = request->config(); - const ResourceConfig cfg = v2::from_proto(proto); + const ResourceConfig cfg = from_proto(proto); const std::lock_guard lock(parent.lock_); std::shared_ptr res; @@ -79,7 +79,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service { const ::viam::module::v1::ReconfigureResourceRequest* request, ::viam::module::v1::ReconfigureResourceResponse*) override { const viam::app::v1::ComponentConfig& proto = request->config(); - ResourceConfig cfg = v2::from_proto(proto); + ResourceConfig cfg = from_proto(proto); const Dependencies deps = parent.get_dependencies_(&request->dependencies(), cfg.name()); @@ -128,7 +128,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service { const ::viam::module::v1::ValidateConfigRequest* request, ::viam::module::v1::ValidateConfigResponse* response) override { const viam::app::v1::ComponentConfig& proto = request->config(); - ResourceConfig cfg = v2::from_proto(proto); + ResourceConfig cfg = from_proto(proto); const std::shared_ptr reg = Registry::lookup_model(cfg.api(), cfg.model()); @@ -179,7 +179,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service { const ::viam::module::v1::ReadyRequest* request, ::viam::module::v1::ReadyResponse* response) override { const std::lock_guard lock(parent.lock_); - const viam::module::v1::HandlerMap hm = v2::to_proto(parent.module_->handles()); + const viam::module::v1::HandlerMap hm = to_proto(parent.module_->handles()); *response->mutable_handlermap() = hm; parent.parent_addr_ = request->parent_address(); response->set_ready(parent.module_->ready()); diff --git a/src/viam/sdk/referenceframe/frame.cpp b/src/viam/sdk/referenceframe/frame.cpp index d93ec36b4..9b119c2d8 100644 --- a/src/viam/sdk/referenceframe/frame.cpp +++ b/src/viam/sdk/referenceframe/frame.cpp @@ -36,19 +36,18 @@ const std::string& LinkConfig::get_parent() const { namespace proto_convert_details { -void to_proto::operator()(const LinkConfig& self, app::v1::Frame* proto) const { +void to_proto_impl::operator()(const LinkConfig& self, app::v1::Frame* proto) const { *(proto->mutable_parent()) = self.get_parent(); - *(proto->mutable_geometry()) = v2::to_proto(self.get_geometry_config()); - *(proto->mutable_orientation()) = v2::to_proto(self.get_orientation()); - *(proto->mutable_translation()) = v2::to_proto(self.get_translation()); + *(proto->mutable_geometry()) = to_proto(self.get_geometry_config()); + *(proto->mutable_orientation()) = to_proto(self.get_orientation()); + *(proto->mutable_translation()) = to_proto(self.get_translation()); } -LinkConfig from_proto::operator()(const app::v1::Frame* proto) const { - return LinkConfig( - v2::from_proto(proto->translation()), - proto->has_orientation() ? v2::from_proto(proto->orientation()) : Orientation{}, - proto->has_geometry() ? v2::from_proto(proto->geometry()) : GeometryConfig{}, - proto->parent()); +LinkConfig from_proto_impl::operator()(const app::v1::Frame* proto) const { + return LinkConfig(from_proto(proto->translation()), + proto->has_orientation() ? from_proto(proto->orientation()) : Orientation{}, + proto->has_geometry() ? from_proto(proto->geometry()) : GeometryConfig{}, + proto->parent()); } } // namespace proto_convert_details diff --git a/src/viam/sdk/referenceframe/frame.hpp b/src/viam/sdk/referenceframe/frame.hpp index 9d5dfd3ca..6f0b4dc83 100644 --- a/src/viam/sdk/referenceframe/frame.hpp +++ b/src/viam/sdk/referenceframe/frame.hpp @@ -38,12 +38,12 @@ class LinkConfig { namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const LinkConfig&, app::v1::Frame*) const; }; template <> -struct from_proto { +struct from_proto_impl { LinkConfig operator()(const app::v1::Frame*) const; }; diff --git a/src/viam/sdk/resource/resource_api.cpp b/src/viam/sdk/resource/resource_api.cpp index 120b51a2c..3fb340105 100644 --- a/src/viam/sdk/resource/resource_api.cpp +++ b/src/viam/sdk/resource/resource_api.cpp @@ -120,7 +120,7 @@ Name Name::from_string(std::string name) { namespace proto_convert_details { -void to_proto::operator()(const Name& self, common::v1::ResourceName* proto) const { +void to_proto_impl::operator()(const Name& self, common::v1::ResourceName* proto) const { *proto->mutable_namespace_() = self.api().type_namespace(); if (self.remote_name().empty()) { *proto->mutable_name() = self.name(); @@ -131,7 +131,8 @@ void to_proto::operator()(const Name& self, common::v1::ResourceName* prot *proto->mutable_subtype() = self.api().resource_subtype(); } -Name from_proto::operator()(const common::v1::ResourceName* proto) const { +Name from_proto_impl::operator()( + const common::v1::ResourceName* proto) const { auto name_parts = long_name_to_remote_and_short(proto->name()); return Name({proto->namespace_(), proto->type(), proto->subtype()}, diff --git a/src/viam/sdk/resource/resource_api.hpp b/src/viam/sdk/resource/resource_api.hpp index a73a26190..7c7db218f 100644 --- a/src/viam/sdk/resource/resource_api.hpp +++ b/src/viam/sdk/resource/resource_api.hpp @@ -84,12 +84,12 @@ class Name { namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const Name&, common::v1::ResourceName*) const; }; template <> -struct from_proto { +struct from_proto_impl { Name operator()(const common::v1::ResourceName*) const; }; diff --git a/src/viam/sdk/robot/client.cpp b/src/viam/sdk/robot/client.cpp index ffe1bd832..25613ac88 100644 --- a/src/viam/sdk/robot/client.cpp +++ b/src/viam/sdk/robot/client.cpp @@ -46,12 +46,11 @@ using viam::robot::v1::RobotService; // NOLINTNEXTLINE const std::string kStreamRemoved("Stream removed"); -namespace { RobotClient::frame_system_config from_proto(const FrameSystemConfig& proto) { RobotClient::frame_system_config fsconfig; - fsconfig.frame = v2::from_proto(proto.frame()); + fsconfig.frame = from_proto(proto.frame()); if (proto.has_kinematics()) { - fsconfig.kinematics = v2::from_proto(proto.kinematics()); + fsconfig.kinematics = from_proto(proto.kinematics()); } return fsconfig; } @@ -64,19 +63,18 @@ RobotClient::operation from_proto(const Operation& proto) { op.session_id = proto.session_id(); } if (proto.has_arguments()) { - op.arguments = v2::from_proto(proto.arguments()); + op.arguments = from_proto(proto.arguments()); } if (proto.has_started()) { - op.started = v2::from_proto(proto.started()); + op.started = from_proto(proto.started()); } return op; } -} // namespace bool operator==(const RobotClient::frame_system_config& lhs, const RobotClient::frame_system_config& rhs) { - return lhs.frame == rhs.frame && v2::to_proto(lhs.kinematics).SerializeAsString() == - v2::to_proto(rhs.kinematics).SerializeAsString(); + return lhs.frame == rhs.frame && to_proto(lhs.kinematics).SerializeAsString() == + to_proto(rhs.kinematics).SerializeAsString(); } bool operator==(const RobotClient::operation& lhs, const RobotClient::operation& rhs) { @@ -171,7 +169,7 @@ void RobotClient::refresh() { std::unordered_map> new_resources; std::vector current_resources; for (const auto& name : resp.resources()) { - current_resources.push_back(v2::from_proto(name)); + current_resources.push_back(from_proto(name)); if (name.subtype() == "remote") { continue; } @@ -311,7 +309,7 @@ pose_in_frame RobotClient::transform_pose( viam::robot::v1::TransformPoseResponse resp; ClientContext ctx; - *req.mutable_source() = v2::to_proto(query); + *req.mutable_source() = to_proto(query); *req.mutable_destination() = std::move(destination); *req.mutable_supplemental_transforms() = sdk::impl::to_repeated_field(additional_transforms); @@ -320,7 +318,7 @@ pose_in_frame RobotClient::transform_pose( BOOST_LOG_TRIVIAL(error) << "Error getting PoseInFrame: " << response.error_message(); } - return v2::from_proto(resp.pose()); + return from_proto(resp.pose()); } std::shared_ptr RobotClient::resource_by_name(const Name& name) { @@ -344,9 +342,9 @@ void RobotClient::stop_all(const std::unordered_map& extra) { for (const auto& xtra : extra) { const Name& name = xtra.first; const ProtoStruct& params = xtra.second; - const google::protobuf::Struct s = v2::to_proto(params); + const google::protobuf::Struct s = to_proto(params); viam::robot::v1::StopExtraParameters stop; - *stop.mutable_name() = v2::to_proto(name); + *stop.mutable_name() = to_proto(name); *stop.mutable_params() = s; *ep->Add() = stop; } diff --git a/src/viam/sdk/services/private/generic_client.cpp b/src/viam/sdk/services/private/generic_client.cpp index dabe414ec..50efa1a8b 100644 --- a/src/viam/sdk/services/private/generic_client.cpp +++ b/src/viam/sdk/services/private/generic_client.cpp @@ -22,8 +22,8 @@ GenericServiceClient::GenericServiceClient(std::string name, std::shared_ptr( "GenericServiceServer::DoCommand", this, request)([&](auto&, auto& generic) { - const ProtoStruct result = generic->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = generic->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); } diff --git a/src/viam/sdk/services/private/mlmodel_client.cpp b/src/viam/sdk/services/private/mlmodel_client.cpp index 6792885df..be8cf40c1 100644 --- a/src/viam/sdk/services/private/mlmodel_client.cpp +++ b/src/viam/sdk/services/private/mlmodel_client.cpp @@ -49,7 +49,7 @@ std::shared_ptr MLModelServiceClient::infer( auto* const req = pb::Arena::VIAM_SDK_PB_CREATE_MESSAGE(arena.get()); req->set_name(this->name()); - *req->mutable_extra() = v2::to_proto(extra); + *req->mutable_extra() = to_proto(extra); auto* const resp = pb::Arena::VIAM_SDK_PB_CREATE_MESSAGE(arena.get()); ClientContext ctx; @@ -93,7 +93,7 @@ struct MLModelService::metadata MLModelServiceClient::metadata(const ProtoStruct // Encode metadata args into a `MetadataRequest` viam::service::mlmodel::v1::MetadataRequest req; *req.mutable_name() = name(); - *req.mutable_extra() = v2::to_proto(extra); + *req.mutable_extra() = to_proto(extra); // Invoke the stub ClientContext ctx; @@ -150,7 +150,7 @@ struct MLModelService::metadata MLModelServiceClient::metadata(const ProtoStruct } } if (s.has_extra()) { - ti.extra = v2::from_proto(s.extra()); + ti.extra = from_proto(s.extra()); } } }; diff --git a/src/viam/sdk/services/private/mlmodel_server.cpp b/src/viam/sdk/services/private/mlmodel_server.cpp index a19b1864a..550c54690 100644 --- a/src/viam/sdk/services/private/mlmodel_server.cpp +++ b/src/viam/sdk/services/private/mlmodel_server.cpp @@ -142,7 +142,7 @@ ::grpc::Status MLModelServiceServer::Metadata( break; } } - *new_entry.mutable_extra() = v2::to_proto(s.extra); + *new_entry.mutable_extra() = to_proto(s.extra); } return ::grpc::Status(); }; diff --git a/src/viam/sdk/services/private/motion_client.cpp b/src/viam/sdk/services/private/motion_client.cpp index 9252e9c60..8dbccc13a 100644 --- a/src/viam/sdk/services/private/motion_client.cpp +++ b/src/viam/sdk/services/private/motion_client.cpp @@ -17,10 +17,13 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + service::motion::v1::ObstacleDetector to_proto(const obstacle_detector& od) { service::motion::v1::ObstacleDetector proto; - *proto.mutable_vision_service() = v2::to_proto(od.vision_service); - *proto.mutable_camera() = v2::to_proto(od.camera); + *proto.mutable_vision_service() = to_proto(od.vision_service); + *proto.mutable_camera() = to_proto(od.camera); return proto; } @@ -109,7 +112,7 @@ Motion::plan_status from_proto(const service::motion::v1::PlanStatus& proto) { if (proto.has_reason()) { mps.reason = proto.reason(); } - mps.timestamp = v2::from_proto(proto.timestamp()); + mps.timestamp = from_proto(proto.timestamp()); return mps; } @@ -127,7 +130,7 @@ std::vector from_proto( Motion::plan_status_with_id from_proto(const service::motion::v1::PlanStatusWithID& proto) { Motion::plan_status_with_id pswi; pswi.execution_id = proto.execution_id(); - pswi.component_name = v2::from_proto(proto.component_name()); + pswi.component_name = from_proto(proto.component_name()); pswi.plan_id = proto.plan_id(); pswi.status = from_proto(proto.status()); @@ -141,7 +144,7 @@ Motion::steps steps_from_proto( for (const auto& ps : proto) { step step; for (const auto& component : ps.step()) { - step.emplace(component.first, v2::from_proto(component.second.pose())); + step.emplace(component.first, from_proto(component.second.pose())); } steps.push_back(std::move(step)); } @@ -153,7 +156,7 @@ Motion::plan plan_from_proto(const service::motion::v1::Plan& proto) { Motion::plan plan; plan.id = proto.id(); plan.execution_id = proto.execution_id(); - plan.component_name = v2::from_proto(proto.component_name()); + plan.component_name = from_proto(proto.component_name()); plan.steps = steps_from_proto(proto.steps()); return plan; } @@ -189,13 +192,13 @@ bool MotionClient::move(const pose_in_frame& destination, return make_client_helper(this, *stub_, &StubType::Move) .with(extra, [&](auto& request) { - *request.mutable_component_name() = v2::to_proto(component_name); - *request.mutable_destination() = v2::to_proto(destination); + *request.mutable_component_name() = to_proto(component_name); + *request.mutable_destination() = to_proto(destination); if (constraints) { *request.mutable_constraints() = to_proto(*constraints); } if (world_state) { - *request.mutable_world_state() = v2::to_proto(*world_state); + *request.mutable_world_state() = to_proto(*world_state); } }) .invoke([](auto& response) { return response.success(); }); @@ -211,12 +214,12 @@ std::string MotionClient::move_on_map( return make_client_helper(this, *stub_, &StubType::MoveOnMap) .with(extra, [&](auto& request) { - *request.mutable_destination() = v2::to_proto(destination); - *request.mutable_component_name() = v2::to_proto(component_name); - *request.mutable_slam_service_name() = v2::to_proto(slam_name); + *request.mutable_destination() = to_proto(destination); + *request.mutable_component_name() = to_proto(component_name); + *request.mutable_slam_service_name() = to_proto(slam_name); for (const auto& obstacle : obstacles) { - *request.mutable_obstacles()->Add() = v2::to_proto(obstacle); + *request.mutable_obstacles()->Add() = to_proto(obstacle); } if (motion_configuration) { @@ -238,9 +241,9 @@ std::string MotionClient::move_on_globe( return make_client_helper(this, *stub_, &StubType::MoveOnGlobe) .with(extra, [&](auto& request) { - *request.mutable_destination() = v2::to_proto(destination); - *request.mutable_component_name() = v2::to_proto(component_name); - *request.mutable_movement_sensor_name() = v2::to_proto(movement_sensor_name); + *request.mutable_destination() = to_proto(destination); + *request.mutable_component_name() = to_proto(component_name); + *request.mutable_movement_sensor_name() = to_proto(movement_sensor_name); if (heading && !isnan(*heading)) { request.set_heading(*heading); @@ -265,17 +268,17 @@ pose_in_frame MotionClient::get_pose( return make_client_helper(this, *stub_, &StubType::GetPose) .with(extra, [&](auto& request) { - *request.mutable_component_name() = v2::to_proto(component_name); + *request.mutable_component_name() = to_proto(component_name); *request.mutable_destination_frame() = destination_frame; *request.mutable_supplemental_transforms() = impl::to_repeated_field(supplemental_transforms); }) - .invoke([](auto& response) { return v2::from_proto(response.pose()); }); + .invoke([](auto& response) { return from_proto(response.pose()); }); } void MotionClient::stop_plan(const Name& name, const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::StopPlan) - .with(extra, [&](auto& request) { *request.mutable_component_name() = v2::to_proto(name); }) + .with(extra, [&](auto& request) { *request.mutable_component_name() = to_proto(name); }) .invoke(); } @@ -287,7 +290,7 @@ std::pair> Motio return make_client_helper(this, *stub_, &StubType::GetPlan) .with(extra, [&](auto& request) { - *request.mutable_component_name() = v2::to_proto(component_name); + *request.mutable_component_name() = to_proto(component_name); request.set_last_plan_only(last_plan_only); if (execution_id) { *request.mutable_execution_id() = *execution_id; @@ -348,8 +351,8 @@ std::vector MotionClient::list_active_plan_statuses ProtoStruct MotionClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/services/private/motion_server.cpp b/src/viam/sdk/services/private/motion_server.cpp index ae09190ad..e393cfca3 100644 --- a/src/viam/sdk/services/private/motion_server.cpp +++ b/src/viam/sdk/services/private/motion_server.cpp @@ -16,6 +16,9 @@ namespace viam { namespace sdk { namespace impl { +using sdk::from_proto; +using sdk::to_proto; + service::motion::v1::PlanState to_proto(const Motion::plan_state& state) { switch (state) { case Motion::plan_state::k_failed: { @@ -39,7 +42,7 @@ service::motion::v1::PlanState to_proto(const Motion::plan_state& state) { service::motion::v1::PlanStatus to_proto(const Motion::plan_status& ps) { service::motion::v1::PlanStatus proto; - *proto.mutable_timestamp() = v2::to_proto(ps.timestamp); + *proto.mutable_timestamp() = to_proto(ps.timestamp); if (ps.reason) { *proto.mutable_reason() = *ps.reason; } @@ -52,7 +55,7 @@ service::motion::v1::PlanStep to_proto(const Motion::steps::step& step) { service::motion::v1::PlanStep proto; for (const auto& kv : step) { service::motion::v1::ComponentState cs; - *cs.mutable_pose() = v2::to_proto(kv.second); + *cs.mutable_pose() = to_proto(kv.second); proto.mutable_step()->insert({kv.first, cs}); } @@ -62,7 +65,7 @@ service::motion::v1::PlanStep to_proto(const Motion::steps::step& step) { service::motion::v1::Plan to_proto(const Motion::plan& plan) { service::motion::v1::Plan proto; *proto.mutable_id() = plan.id; - *proto.mutable_component_name() = v2::to_proto(plan.component_name); + *proto.mutable_component_name() = to_proto(plan.component_name); *proto.mutable_execution_id() = plan.execution_id; for (const auto& step : plan.steps.steps) { *proto.mutable_steps()->Add() = to_proto(step); @@ -86,7 +89,7 @@ service::motion::v1::PlanStatusWithID to_proto(const Motion::plan_status_with_id service::motion::v1::PlanStatusWithID proto; *proto.mutable_execution_id() = pswi.execution_id; - *proto.mutable_component_name() = v2::to_proto(pswi.component_name); + *proto.mutable_component_name() = to_proto(pswi.component_name); *proto.mutable_plan_id() = pswi.plan_id; *proto.mutable_status() = to_proto(pswi.status); @@ -95,8 +98,8 @@ service::motion::v1::PlanStatusWithID to_proto(const Motion::plan_status_with_id obstacle_detector from_proto(const service::motion::v1::ObstacleDetector& proto) { obstacle_detector oc; - oc.vision_service = v2::from_proto(proto.vision_service()); - oc.camera = v2::from_proto(proto.camera()); + oc.vision_service = from_proto(proto.vision_service()); + oc.camera = from_proto(proto.camera()); return oc; } @@ -178,7 +181,7 @@ ::grpc::Status MotionServer::Move(::grpc::ServerContext*, "MotionServer::Move", this, request)([&](auto& helper, auto& motion) { std::shared_ptr ws; if (request->has_world_state()) { - ws = std::make_shared(v2::from_proto(request->world_state())); + ws = std::make_shared(from_proto(request->world_state())); } std::shared_ptr constraints; @@ -186,8 +189,8 @@ ::grpc::Status MotionServer::Move(::grpc::ServerContext*, constraints = std::make_shared(from_proto(request->constraints())); } - const bool success = motion->move(v2::from_proto(request->destination()), - v2::from_proto(request->component_name()), + const bool success = motion->move(from_proto(request->destination()), + from_proto(request->component_name()), std::move(ws), std::move(constraints), helper.getExtra()); @@ -201,9 +204,9 @@ ::grpc::Status MotionServer::MoveOnMap( ::viam::service::motion::v1::MoveOnMapResponse* response) noexcept { return make_service_helper( "MotionServer::MoveOnMap", this, request)([&](auto& helper, auto& motion) { - const auto destination = v2::from_proto(request->destination()); - const auto component_name = v2::from_proto(request->component_name()); - const auto slam_name = v2::from_proto(request->slam_service_name()); + const auto destination = from_proto(request->destination()); + const auto component_name = from_proto(request->component_name()); + const auto slam_name = from_proto(request->slam_service_name()); std::shared_ptr mc; if (request->has_motion_configuration()) { @@ -213,7 +216,7 @@ ::grpc::Status MotionServer::MoveOnMap( std::vector obstacles; for (const auto& obstacle : request->obstacles()) { - obstacles.push_back(v2::from_proto(obstacle)); + obstacles.push_back(from_proto(obstacle)); } const std::string execution_id = motion->move_on_map( @@ -229,9 +232,9 @@ ::grpc::Status MotionServer::MoveOnGlobe( ::viam::service::motion::v1::MoveOnGlobeResponse* response) noexcept { return make_service_helper( "MotionServer::MoveOnGlobe", this, request)([&](auto& helper, auto& motion) { - const auto destination = v2::from_proto(request->destination()); - const auto component_name = v2::from_proto(request->component_name()); - const auto movement_sensor_name = v2::from_proto(request->movement_sensor_name()); + const auto destination = from_proto(request->destination()); + const auto component_name = from_proto(request->component_name()); + const auto movement_sensor_name = from_proto(request->movement_sensor_name()); const std::vector obstacles = impl::from_repeated_field(request->obstacles()); const std::vector bounding_regions = impl::from_repeated_field(request->bounding_regions()); @@ -266,15 +269,15 @@ ::grpc::Status MotionServer::GetPose( ::viam::service::motion::v1::GetPoseResponse* response) noexcept { return make_service_helper( "MotionServer::GetPose", this, request)([&](auto& helper, auto& motion) { - const auto& component_name = v2::from_proto(request->component_name()); + const auto& component_name = from_proto(request->component_name()); const std::string& destination_frame = request->destination_frame(); std::vector supplemental_transforms; for (const auto& proto_transform : request->supplemental_transforms()) { - supplemental_transforms.push_back(v2::from_proto(proto_transform)); + supplemental_transforms.push_back(from_proto(proto_transform)); } const pose_in_frame pose = motion->get_pose( component_name, destination_frame, supplemental_transforms, helper.getExtra()); - *response->mutable_pose() = v2::to_proto(pose); + *response->mutable_pose() = to_proto(pose); }); }; @@ -284,7 +287,7 @@ ::grpc::Status MotionServer::GetPlan( ::viam::service::motion::v1::GetPlanResponse* response) noexcept { return make_service_helper( "MotionServer::GetPlan", this, request)([&](auto& helper, auto& motion) { - const auto& component_name = v2::from_proto(request->component_name()); + const auto& component_name = from_proto(request->component_name()); Motion::plan_with_status plan; std::vector replan_history; const bool last_plan_only(request->last_plan_only()); @@ -337,7 +340,7 @@ ::grpc::Status MotionServer::StopPlan(::grpc::ServerContext*, ::viam::service::motion::v1::StopPlanResponse*) noexcept { return make_service_helper( "MotionServer::StopPlan", this, request)([&](auto& helper, auto& motion) { - const auto& component_name = v2::from_proto(request->component_name()); + const auto& component_name = from_proto(request->component_name()); motion->stop_plan(component_name, helper.getExtra()); }); @@ -348,8 +351,8 @@ ::grpc::Status MotionServer::DoCommand(::grpc::ServerContext*, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "MotionServer::DoCommand", this, request)([&](auto&, auto& motion) { - const ProtoStruct result = motion->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = motion->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); }; diff --git a/src/viam/sdk/services/private/navigation_client.cpp b/src/viam/sdk/services/private/navigation_client.cpp index 5b9bb73db..efcf7e1b8 100644 --- a/src/viam/sdk/services/private/navigation_client.cpp +++ b/src/viam/sdk/services/private/navigation_client.cpp @@ -19,16 +19,16 @@ namespace sdk { namespace proto_convert_details { template <> -struct from_proto { +struct from_proto_impl { Navigation::Path operator()(const service::navigation::v1::Path* proto) const { return {proto->destination_waypoint_id(), impl::from_repeated_field(proto->geopoints())}; } }; template <> -struct from_proto { +struct from_proto_impl { Navigation::Waypoint operator()(const service::navigation::v1::Waypoint* proto) const { - return {proto->id(), v2::from_proto(proto->location())}; + return {proto->id(), from_proto(proto->location())}; } }; @@ -45,7 +45,7 @@ NavigationClient::NavigationClient(std::string name, std::shared_ptr NavigationClient::get_waypoints(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetWaypoints) - .with([&](auto& request) { *request.mutable_extra() = v2::to_proto(extra); }) + .with([&](auto& request) { *request.mutable_extra() = to_proto(extra); }) .invoke([](auto& response) { return impl::from_repeated_field(response.waypoints()); }); } void NavigationClient::add_waypoint(const geo_point& location, const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::AddWaypoint) .with([&](auto& request) { - *request.mutable_location() = v2::to_proto(location); - *request.mutable_extra() = v2::to_proto(extra); + *request.mutable_location() = to_proto(location); + *request.mutable_extra() = to_proto(extra); }) .invoke([](auto& response) {}); } @@ -88,20 +88,20 @@ void NavigationClient::remove_waypoint(const std::string id, const ProtoStruct& return make_client_helper(this, *stub_, &StubType::RemoveWaypoint) .with([&](auto& request) { *request.mutable_id() = id; - *request.mutable_extra() = v2::to_proto(extra); + *request.mutable_extra() = to_proto(extra); }) .invoke([](auto& response) {}); } std::vector NavigationClient::get_obstacles(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetObstacles) - .with([&](auto& request) { *request.mutable_extra() = v2::to_proto(extra); }) + .with([&](auto& request) { *request.mutable_extra() = to_proto(extra); }) .invoke([](auto& response) { return impl::from_repeated_field(response.obstacles()); }); } std::vector NavigationClient::get_paths(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetPaths) - .with([&](auto& request) { *request.mutable_extra() = v2::to_proto(extra); }) + .with([&](auto& request) { *request.mutable_extra() = to_proto(extra); }) .invoke([](auto& response) { return impl::from_repeated_field(response.paths()); }); } @@ -113,8 +113,8 @@ NavigationClient::Properties NavigationClient::get_properties() { ProtoStruct NavigationClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) - .invoke([](auto& response) { return v2::from_proto(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = to_proto(command); }) + .invoke([](auto& response) { return from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/services/private/navigation_server.cpp b/src/viam/sdk/services/private/navigation_server.cpp index 75664b8c4..8ca034765 100644 --- a/src/viam/sdk/services/private/navigation_server.cpp +++ b/src/viam/sdk/services/private/navigation_server.cpp @@ -17,7 +17,7 @@ namespace sdk { namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const Navigation::Path& self, service::navigation::v1::Path* proto) const { *(proto->mutable_destination_waypoint_id()) = self.destination_waypoint_id; *(proto->mutable_geopoints()) = impl::to_repeated_field(self.geopoints); @@ -25,11 +25,11 @@ struct to_proto { }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const Navigation::Waypoint& self, service::navigation::v1::Waypoint* proto) const { *(proto->mutable_id()) = self.id; - *(proto->mutable_location()) = v2::to_proto(self.location); + *(proto->mutable_location()) = to_proto(self.location); } }; @@ -63,7 +63,7 @@ ::grpc::Status NavigationServer::GetLocation(::grpc::ServerContext*, return make_service_helper( "NavigationServer::GetLocation", this, request)([&](auto& helper, auto& nav) { const auto& loc = nav->get_location(helper.getExtra()); - *response->mutable_location() = v2::to_proto(loc.location); + *response->mutable_location() = to_proto(loc.location); response->set_compass_heading(loc.compass_heading); }); } @@ -83,7 +83,7 @@ ::grpc::Status NavigationServer::AddWaypoint(::grpc::ServerContext*, AddWaypointResponse*) noexcept { return make_service_helper( "NavigationServer::AddWaypoint", this, request)([&](auto& helper, auto& nav) { - nav->add_waypoint(v2::from_proto(request->location()), helper.getExtra()); + nav->add_waypoint(from_proto(request->location()), helper.getExtra()); }); } @@ -129,8 +129,8 @@ ::grpc::Status NavigationServer::DoCommand( ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "NavigationServer::DoCommand", this, request)([&](auto&, auto& motion) { - const ProtoStruct result = motion->do_command(v2::from_proto(request->command())); - *response->mutable_result() = v2::to_proto(result); + const ProtoStruct result = motion->do_command(from_proto(request->command())); + *response->mutable_result() = to_proto(result); }); }; diff --git a/src/viam/sdk/spatialmath/geometry.cpp b/src/viam/sdk/spatialmath/geometry.cpp index 5f05b85f3..6dbc4b0a0 100644 --- a/src/viam/sdk/spatialmath/geometry.cpp +++ b/src/viam/sdk/spatialmath/geometry.cpp @@ -112,67 +112,67 @@ bool operator==(const geo_geometry& lhs, const geo_geometry& rhs) { namespace proto_convert_details { -void to_proto::operator()(const box& self, common::v1::RectangularPrism* proto) const { - *(proto->mutable_dims_mm()) = v2::to_proto(Vector3{self.x, self.y, self.z}); +void to_proto_impl::operator()(const box& self, common::v1::RectangularPrism* proto) const { + *(proto->mutable_dims_mm()) = to_proto(Vector3{self.x, self.y, self.z}); } -box from_proto::operator()( +box from_proto_impl::operator()( const common::v1::RectangularPrism* proto) const { const auto& dims = proto->dims_mm(); return {dims.x(), dims.y(), dims.z()}; } -void to_proto::operator()(const sphere& self, common::v1::Sphere* proto) const { +void to_proto_impl::operator()(const sphere& self, common::v1::Sphere* proto) const { proto->set_radius_mm(self.radius); } -sphere from_proto::operator()(const common::v1::Sphere* proto) const { +sphere from_proto_impl::operator()(const common::v1::Sphere* proto) const { return {proto->radius_mm()}; } -void to_proto::operator()(const capsule& self, common::v1::Capsule* proto) const { +void to_proto_impl::operator()(const capsule& self, common::v1::Capsule* proto) const { proto->set_radius_mm(self.radius); proto->set_length_mm(self.length); } -capsule from_proto::operator()(const common::v1::Capsule* proto) const { +capsule from_proto_impl::operator()(const common::v1::Capsule* proto) const { return {proto->radius_mm(), proto->length_mm()}; } -void to_proto::operator()(const GeometryConfig& self, - common::v1::Geometry* proto) const { +void to_proto_impl::operator()(const GeometryConfig& self, + common::v1::Geometry* proto) const { struct Visitor { common::v1::Geometry& geometry; void operator()(const box& b) { - *geometry.mutable_box() = v2::to_proto(b); + *geometry.mutable_box() = to_proto(b); } void operator()(const sphere& s) { - *geometry.mutable_sphere() = v2::to_proto(s); + *geometry.mutable_sphere() = to_proto(s); } void operator()(const capsule& c) { - *geometry.mutable_capsule() = v2::to_proto(c); + *geometry.mutable_capsule() = to_proto(c); } }; boost::apply_visitor(Visitor{*proto}, self.get_geometry_specifics()); *(proto->mutable_label()) = self.get_label(); - *(proto->mutable_center()) = v2::to_proto(self.get_pose()); + *(proto->mutable_center()) = to_proto(self.get_pose()); } -GeometryConfig from_proto::operator()( +GeometryConfig from_proto_impl::operator()( const common::v1::Geometry* proto) const { auto get_specifics = [proto]() -> geometry_specifics { switch (proto->geometry_type_case()) { case viam::common::v1::Geometry::GeometryTypeCase::kBox: - return v2::from_proto(proto->box()); + return from_proto(proto->box()); case viam::common::v1::Geometry::GeometryTypeCase::kSphere: - return v2::from_proto(proto->sphere()); + return from_proto(proto->sphere()); case viam::common::v1::Geometry::GeometryTypeCase::kCapsule: - return v2::from_proto(proto->capsule()); + return from_proto(proto->capsule()); case viam::common::v1::Geometry::GeometryTypeCase:: GEOMETRY_TYPE_NOT_SET: // fallthrough default: @@ -180,15 +180,17 @@ GeometryConfig from_proto::operator()( } }; - return GeometryConfig(v2::from_proto(proto->center()), get_specifics(), proto->label()); + return GeometryConfig(from_proto(proto->center()), get_specifics(), proto->label()); } -void to_proto::operator()(const geo_point& self, common::v1::GeoPoint* proto) const { +void to_proto_impl::operator()(const geo_point& self, + common::v1::GeoPoint* proto) const { proto->set_latitude(self.latitude); proto->set_longitude(self.longitude); } -geo_point from_proto::operator()(const common::v1::GeoPoint* proto) const { +geo_point from_proto_impl::operator()( + const common::v1::GeoPoint* proto) const { geo_point result; result.latitude = proto->latitude(); result.longitude = proto->longitude(); @@ -196,18 +198,18 @@ geo_point from_proto::operator()(const common::v1::GeoPoin return result; } -void to_proto::operator()(const geo_geometry& self, - common::v1::GeoGeometry* proto) const { - *(proto->mutable_location()) = v2::to_proto(self.location); +void to_proto_impl::operator()(const geo_geometry& self, + common::v1::GeoGeometry* proto) const { + *(proto->mutable_location()) = to_proto(self.location); *(proto->mutable_geometries()) = impl::to_repeated_field(self.geometries); } -geo_geometry from_proto::operator()( +geo_geometry from_proto_impl::operator()( const common::v1::GeoGeometry* proto) const { - return {v2::from_proto(proto->location()), impl::from_repeated_field(proto->geometries())}; + return {from_proto(proto->location()), impl::from_repeated_field(proto->geometries())}; } -std::vector from_proto::operator()( +std::vector from_proto_impl::operator()( const common::v1::GetGeometriesResponse* proto) const { return impl::from_repeated_field(proto->geometries()); } diff --git a/src/viam/sdk/spatialmath/geometry.hpp b/src/viam/sdk/spatialmath/geometry.hpp index 2935676d3..2f3c0a124 100644 --- a/src/viam/sdk/spatialmath/geometry.hpp +++ b/src/viam/sdk/spatialmath/geometry.hpp @@ -95,67 +95,67 @@ struct geo_geometry { namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const box&, common::v1::RectangularPrism*) const; }; template <> -struct from_proto { +struct from_proto_impl { box operator()(const common::v1::RectangularPrism*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const sphere&, common::v1::Sphere*) const; }; template <> -struct from_proto { +struct from_proto_impl { sphere operator()(const common::v1::Sphere*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const capsule&, common::v1::Capsule*) const; }; template <> -struct from_proto { +struct from_proto_impl { capsule operator()(const common::v1::Capsule*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const GeometryConfig&, common::v1::Geometry*) const; }; template <> -struct from_proto { +struct from_proto_impl { GeometryConfig operator()(const common::v1::Geometry*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const geo_point&, common::v1::GeoPoint*) const; }; template <> -struct from_proto { +struct from_proto_impl { geo_point operator()(const common::v1::GeoPoint*) const; }; template <> -struct to_proto { +struct to_proto_impl { void operator()(const geo_geometry&, common::v1::GeoGeometry*) const; }; template <> -struct from_proto { +struct from_proto_impl { geo_geometry operator()(const common::v1::GeoGeometry*) const; }; template <> -struct from_proto { +struct from_proto_impl { std::vector operator()(const common::v1::GetGeometriesResponse*) const; }; diff --git a/src/viam/sdk/spatialmath/orientation.cpp b/src/viam/sdk/spatialmath/orientation.cpp index 12da26d35..2079da80c 100644 --- a/src/viam/sdk/spatialmath/orientation.cpp +++ b/src/viam/sdk/spatialmath/orientation.cpp @@ -41,7 +41,8 @@ OrientationType get_type(const Orientation& o) { namespace proto_convert_details { -void to_proto::operator()(const Orientation& self, app::v1::Orientation* o) const { +void to_proto_impl::operator()(const Orientation& self, + app::v1::Orientation* o) const { struct Visitor { void operator()(const axis_angles& a) { app::v1::Orientation_AxisAngles aa; @@ -93,7 +94,8 @@ void to_proto::operator()(const Orientation& self, app::v1::Orienta boost::apply_visitor(Visitor{*o}, self); } -Orientation from_proto::operator()(const app::v1::Orientation* proto) const { +Orientation from_proto_impl::operator()( + const app::v1::Orientation* proto) const { switch (proto->type_case()) { case app::v1::Orientation::TypeCase::kAxisAngles: { axis_angles aa; diff --git a/src/viam/sdk/spatialmath/orientation.hpp b/src/viam/sdk/spatialmath/orientation.hpp index 1ce7dca17..6cd3e086c 100644 --- a/src/viam/sdk/spatialmath/orientation.hpp +++ b/src/viam/sdk/spatialmath/orientation.hpp @@ -29,11 +29,11 @@ OrientationType get_type(const Orientation&); namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const Orientation&, app::v1::Orientation*) const; }; template <> -struct from_proto { +struct from_proto_impl { Orientation operator()(const app::v1::Orientation*) const; }; diff --git a/src/viam/sdk/spatialmath/orientation_types.cpp b/src/viam/sdk/spatialmath/orientation_types.cpp index 1b981bc8c..265dbc048 100644 --- a/src/viam/sdk/spatialmath/orientation_types.cpp +++ b/src/viam/sdk/spatialmath/orientation_types.cpp @@ -7,13 +7,15 @@ namespace sdk { namespace proto_convert_details { -void to_proto::operator()(const translation& self, app::v1::Translation* t) const { +void to_proto_impl::operator()(const translation& self, + app::v1::Translation* t) const { t->set_x(self.x); t->set_y(self.y); t->set_z(self.z); } -translation from_proto::operator()(const app::v1::Translation* proto) const { +translation from_proto_impl::operator()( + const app::v1::Translation* proto) const { return {proto->x(), proto->y(), proto->z()}; } diff --git a/src/viam/sdk/spatialmath/orientation_types.hpp b/src/viam/sdk/spatialmath/orientation_types.hpp index 2cde64cfb..e8b03d3d6 100644 --- a/src/viam/sdk/spatialmath/orientation_types.hpp +++ b/src/viam/sdk/spatialmath/orientation_types.hpp @@ -49,12 +49,12 @@ struct translation { namespace proto_convert_details { template <> -struct to_proto { +struct to_proto_impl { void operator()(const translation&, app::v1::Translation*) const; }; template <> -struct from_proto { +struct from_proto_impl { translation operator()(const app::v1::Translation*) const; }; diff --git a/src/viam/sdk/tests/mocks/mock_robot.cpp b/src/viam/sdk/tests/mocks/mock_robot.cpp index ce0e18572..2aa15ef8e 100644 --- a/src/viam/sdk/tests/mocks/mock_robot.cpp +++ b/src/viam/sdk/tests/mocks/mock_robot.cpp @@ -58,7 +58,7 @@ pose default_pose(int offset) { } Pose default_proto_pose(int offset = 0) { - return v2::to_proto(default_pose(offset)); + return to_proto(default_pose(offset)); } std::vector mock_operations_response() { @@ -211,7 +211,7 @@ std::vector MockRobotService::generate_metadata_() { std::vector metadata; for (const auto& key_and_val : resource_manager()->resources()) { for (const Name& name : registered_models_for_resource(key_and_val.second)) { - metadata.push_back(v2::to_proto(name)); + metadata.push_back(to_proto(name)); } } return metadata; @@ -240,7 +240,7 @@ ::grpc::Status MockRobotService::StopAll(::grpc::ServerContext*, std::unordered_map extra; for (const auto& ex : request->extra()) { const google::protobuf::Struct& struct_ = ex.params(); - const ProtoStruct value_map = v2::from_proto(struct_); + const ProtoStruct value_map = from_proto(struct_); const std::string name = ex.name().SerializeAsString(); extra.emplace(name, value_map); } @@ -250,7 +250,7 @@ ::grpc::Status MockRobotService::StopAll(::grpc::ServerContext*, for (const auto& r : resource_manager()->resources()) { const std::shared_ptr resource = r.second; - const ResourceName rn = v2::to_proto(resource->get_resource_name()); + const ResourceName rn = to_proto(resource->get_resource_name()); const std::string rn_ = rn.SerializeAsString(); if (extra.find(rn_) != extra.end()) { try { diff --git a/src/viam/sdk/tests/test_common.cpp b/src/viam/sdk/tests/test_common.cpp index ca4b87398..9dfcfcbd3 100644 --- a/src/viam/sdk/tests/test_common.cpp +++ b/src/viam/sdk/tests/test_common.cpp @@ -26,9 +26,9 @@ BOOST_AUTO_TEST_CASE(test_zero) { Duration input; input.set_nanos(0); input.set_seconds(0); - auto converted = v2::from_proto(input); + auto converted = from_proto(input); BOOST_CHECK_EQUAL(converted.count(), 0); - auto reconverted = v2::to_proto(converted); + auto reconverted = to_proto(converted); BOOST_CHECK_EQUAL(reconverted.nanos(), 0); BOOST_CHECK_EQUAL(reconverted.seconds(), 0); } @@ -37,9 +37,9 @@ BOOST_AUTO_TEST_CASE(test_rounding_negative) { Duration input; input.set_nanos(-100); input.set_seconds(0); - auto converted = v2::from_proto(input); + auto converted = from_proto(input); BOOST_CHECK_EQUAL(converted.count(), -1); - auto reconverted = v2::to_proto(converted); + auto reconverted = to_proto(converted); BOOST_CHECK_EQUAL(reconverted.nanos(), -1000); BOOST_CHECK_EQUAL(reconverted.seconds(), 0); } @@ -48,9 +48,9 @@ BOOST_AUTO_TEST_CASE(test_rounding_positive) { Duration input; input.set_nanos(999); input.set_seconds(0); - auto converted = v2::from_proto(input); + auto converted = from_proto(input); BOOST_CHECK_EQUAL(converted.count(), 1); - auto reconverted = v2::to_proto(converted); + auto reconverted = to_proto(converted); BOOST_CHECK_EQUAL(reconverted.nanos(), 1000); BOOST_CHECK_EQUAL(reconverted.seconds(), 0); } @@ -60,9 +60,9 @@ BOOST_AUTO_TEST_CASE(test_mixed_sign_rounding) { // Should round to -1 μs input.set_nanos(-500); input.set_seconds(1); - auto converted = v2::from_proto(input); + auto converted = from_proto(input); BOOST_CHECK_EQUAL(converted.count(), 1e6 - 1); - auto reconverted = v2::to_proto(converted); + auto reconverted = to_proto(converted); BOOST_CHECK_EQUAL(reconverted.nanos(), 1e9 - 1000); BOOST_CHECK_EQUAL(reconverted.seconds(), 0); } @@ -72,9 +72,9 @@ BOOST_AUTO_TEST_CASE(test_medium_positive) { // Should round to 2 μs input.set_nanos(1500); input.set_seconds(1000); - auto converted = v2::from_proto(input); + auto converted = from_proto(input); BOOST_CHECK_EQUAL(converted.count(), 1000 * 1e6 + 2); - auto reconverted = v2::to_proto(converted); + auto reconverted = to_proto(converted); BOOST_CHECK_EQUAL(reconverted.nanos(), 2000); BOOST_CHECK_EQUAL(reconverted.seconds(), 1000); } @@ -87,9 +87,9 @@ BOOST_AUTO_TEST_CASE(test_large_positive) { // compliant with the proto spec int64_t max_seconds = 10e3 * 365 * 24 * 60 * 60; input.set_seconds(max_seconds); - auto converted = v2::from_proto(input); + auto converted = from_proto(input); BOOST_CHECK_EQUAL(converted.count(), 1e6 * max_seconds + 2); - auto reconverted = v2::to_proto(converted); + auto reconverted = to_proto(converted); BOOST_CHECK_EQUAL(reconverted.nanos(), 2000); BOOST_CHECK_EQUAL(reconverted.seconds(), max_seconds); } diff --git a/src/viam/sdk/tests/test_proto_value.cpp b/src/viam/sdk/tests/test_proto_value.cpp index 320002854..5bd269ccf 100644 --- a/src/viam/sdk/tests/test_proto_value.cpp +++ b/src/viam/sdk/tests/test_proto_value.cpp @@ -91,9 +91,9 @@ BOOST_AUTO_TEST_CASE(test_object_equality) { BOOST_CHECK(v1_copy_to_change == v3); } - Value converted = v2::to_proto(v3); - auto roundtrip = v2::from_proto(converted); - Value value_roundtrip = v2::to_proto(roundtrip); + Value converted = to_proto(v3); + auto roundtrip = from_proto(converted); + Value value_roundtrip = to_proto(roundtrip); BOOST_CHECK(v3.kind() == roundtrip.kind()); @@ -215,9 +215,9 @@ BOOST_AUTO_TEST_CASE(test_nested_objects) { ProtoValue map_proto(map); - Value val = v2::to_proto(map_proto); - auto roundtrip = v2::from_proto(val); - Value val2 = v2::to_proto(roundtrip); + Value val = to_proto(map_proto); + auto roundtrip = from_proto(val); + Value val2 = to_proto(roundtrip); BOOST_CHECK(map_proto == roundtrip); @@ -243,13 +243,13 @@ BOOST_AUTO_TEST_CASE(test_manual_list_conversion) { Value protoval; set_proto_value(protoval, test_val); - auto from_value = v2::from_proto(protoval); + auto from_value = from_proto(protoval); BOOST_CHECK(val == from_value); - Value converted_to_value = v2::to_proto(val); + Value converted_to_value = to_proto(val); BOOST_CHECK(protoval.ShortDebugString() == converted_to_value.ShortDebugString()); - auto roundtrip = v2::from_proto(converted_to_value); + auto roundtrip = from_proto(converted_to_value); BOOST_CHECK(val == roundtrip); }); @@ -286,10 +286,10 @@ BOOST_AUTO_TEST_CASE(test_manual_list_conversion) { Value v; *v.mutable_list_value() = lv; - Value value_from_proto = v2::to_proto(proto); + Value value_from_proto = to_proto(proto); BOOST_CHECK(v.ShortDebugString() == value_from_proto.ShortDebugString()); - auto roundtrip = v2::from_proto(value_from_proto); + auto roundtrip = from_proto(value_from_proto); BOOST_CHECK(proto == roundtrip); } @@ -314,9 +314,9 @@ BOOST_AUTO_TEST_CASE(test_manual_map_conversion) { Value v; *v.mutable_struct_value() = proto_struct; - auto from_proto = v2::from_proto(v); + auto from_proto_ = from_proto(v); ProtoValue from_map(m); - BOOST_CHECK(from_proto == from_map); + BOOST_CHECK(from_proto_ == from_map); const ProtoStruct* ptr = from_map.get(); BOOST_REQUIRE(ptr); diff --git a/src/viam/sdk/tests/test_resource.cpp b/src/viam/sdk/tests/test_resource.cpp index 50bb07715..68e6b47b5 100644 --- a/src/viam/sdk/tests/test_resource.cpp +++ b/src/viam/sdk/tests/test_resource.cpp @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(test_name) { BOOST_CHECK_EQUAL(name1.name(), "name"); BOOST_CHECK_EQUAL(name1.short_name(), "remote:name"); BOOST_CHECK_EQUAL(name1.to_string(), "ns:service:st/remote:name"); - BOOST_CHECK_EQUAL(v2::from_proto(v2::to_proto(name1)), name1); + BOOST_CHECK_EQUAL(from_proto(to_proto(name1)), name1); Name name2(API::from_string("ns:service:st"), "remote1:remote2", "name"); BOOST_CHECK_EQUAL(name2.api().to_string(), "ns:service:st"); @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(test_name) { BOOST_CHECK_EQUAL(name2.name(), "name"); BOOST_CHECK_EQUAL(name2.short_name(), "remote1:remote2:name"); BOOST_CHECK_EQUAL(name2.to_string(), "ns:service:st/remote1:remote2:name"); - BOOST_CHECK_EQUAL(v2::from_proto(v2::to_proto(name2)), name2); + BOOST_CHECK_EQUAL(from_proto(to_proto(name2)), name2); Name name3 = Name::from_string("ns:component:st/name"); BOOST_CHECK_EQUAL(name3.api().to_string(), "ns:component:st"); @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(test_name) { BOOST_CHECK_EQUAL(name3.name(), "name"); BOOST_CHECK_EQUAL(name3.short_name(), "name"); BOOST_CHECK_EQUAL(name3.to_string(), "ns:component:st/name"); - BOOST_CHECK_EQUAL(v2::from_proto(v2::to_proto(name3)), name3); + BOOST_CHECK_EQUAL(from_proto(to_proto(name3)), name3); BOOST_CHECK_THROW(Name::from_string("ns:service:#st/remote:name"), Exception); } @@ -135,24 +135,24 @@ BOOST_AUTO_TEST_CASE(test_linkconfig) { *frame.mutable_orientation() = o; *frame.mutable_translation() = t; - LinkConfig lc = v2::from_proto(frame); + LinkConfig lc = from_proto(frame); BOOST_CHECK_EQUAL(lc.get_parent(), "parent"); BOOST_CHECK_EQUAL(lc.get_translation().x, t.x()); BOOST_CHECK_EQUAL(lc.get_translation().y, t.y()); BOOST_CHECK_EQUAL(lc.get_translation().z, t.z()); GeometryConfig gcfg = lc.get_geometry_config(); BOOST_CHECK_EQUAL(gcfg.get_label(), "label"); - BOOST_CHECK_EQUAL(gcfg.get_pose(), v2::from_proto(pose)); + BOOST_CHECK_EQUAL(gcfg.get_pose(), from_proto(pose)); BOOST_CHECK_EQUAL(gcfg.get_geometry_type(), GeometryType::box); - common::v1::Geometry gs = v2::to_proto(gcfg); + common::v1::Geometry gs = to_proto(gcfg); BOOST_ASSERT(gs.has_box()); BOOST_CHECK_EQUAL(gs.box().dims_mm().x(), box.dims_mm().x()); BOOST_CHECK_EQUAL(gs.box().dims_mm().y(), box.dims_mm().y()); BOOST_CHECK_EQUAL(gs.box().dims_mm().z(), box.dims_mm().z()); - viam::app::v1::Frame proto_lc = v2::to_proto(lc); + viam::app::v1::Frame proto_lc = to_proto(lc); BOOST_CHECK_EQUAL(proto_lc.parent(), "parent"); BOOST_CHECK_EQUAL(proto_lc.translation().x(), t.x()); BOOST_CHECK_EQUAL(proto_lc.translation().y(), t.y()); @@ -236,7 +236,7 @@ BOOST_AUTO_TEST_CASE(test_resource) { *frame.mutable_translation() = t; *proto_cfg.mutable_frame() = frame; - ResourceConfig resource2 = v2::from_proto(proto_cfg); + ResourceConfig resource2 = from_proto(proto_cfg); BOOST_CHECK_EQUAL(resource2.name(), "name"); BOOST_CHECK_EQUAL(resource2.namespace_(), "ns"); BOOST_CHECK_EQUAL(resource2.type(), "type"); @@ -247,13 +247,13 @@ BOOST_AUTO_TEST_CASE(test_resource) { Value value; for (const auto& key_and_value : resource2.attributes()) { key = key_and_value.first; - value = v2::to_proto(key_and_value.second); + value = to_proto(key_and_value.second); } BOOST_CHECK_EQUAL(key, "a"); BOOST_CHECK_EQUAL(value.number_value(), 1); *proto_cfg.mutable_api() = "ns:component:test"; - BOOST_CHECK_THROW(v2::from_proto(proto_cfg), Exception); + BOOST_CHECK_THROW(from_proto(proto_cfg), Exception); } } // namespace sdktests diff --git a/src/viam/sdk/tests/test_robot.cpp b/src/viam/sdk/tests/test_robot.cpp index a9047328d..8a57adac3 100644 --- a/src/viam/sdk/tests/test_robot.cpp +++ b/src/viam/sdk/tests/test_robot.cpp @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(test_frame_system_config) { proto1.frame().pose_in_observer_frame().pose().o_x()); BOOST_CHECK_EQUAL(config1.frame.pose_in_observer_frame.pose.theta, proto1.frame().pose_in_observer_frame().pose().theta()); - BOOST_CHECK_EQUAL(v2::to_proto(config1.kinematics).SerializeAsString(), + BOOST_CHECK_EQUAL(to_proto(config1.kinematics).SerializeAsString(), proto1.kinematics().SerializeAsString()); BOOST_CHECK_EQUAL(config2.frame.reference_frame, proto2.frame().reference_frame()); @@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(test_frame_system_config) { proto2.frame().pose_in_observer_frame().pose().o_x()); BOOST_CHECK_EQUAL(config2.frame.pose_in_observer_frame.pose.theta, proto2.frame().pose_in_observer_frame().pose().theta()); - BOOST_CHECK_EQUAL(v2::to_proto(config2.kinematics).SerializeAsString(), + BOOST_CHECK_EQUAL(to_proto(config2.kinematics).SerializeAsString(), proto2.kinematics().SerializeAsString()); }); }