Skip to content

Commit 8382629

Browse files
committed
remove proto_utils.hpp
1 parent 42552ff commit 8382629

File tree

4 files changed

+48
-111
lines changed

4 files changed

+48
-111
lines changed

src/viam/sdk/common/private/proto_utils.hpp

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/viam/sdk/services/navigation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <viam/sdk/services/navigation.hpp>
22

3-
#include <viam/sdk/common/private/proto_utils.hpp>
43
#include <viam/sdk/common/utils.hpp>
54

65
namespace viam {

src/viam/sdk/services/private/navigation_client.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,35 @@
88
#include <viam/api/service/navigation/v1/navigation.pb.h>
99

1010
#include <viam/sdk/common/client_helper.hpp>
11-
#include <viam/sdk/common/private/proto_utils.hpp>
11+
#include <viam/sdk/common/proto_convert_vector.hpp>
1212
#include <viam/sdk/common/proto_value.hpp>
1313
#include <viam/sdk/common/utils.hpp>
1414
#include <viam/sdk/services/navigation.hpp>
1515

1616
namespace viam {
1717
namespace sdk {
18-
namespace impl {
1918

20-
using namespace viam::service::navigation::v1;
19+
namespace proto_convert_details {
2120

22-
Navigation::Waypoint from_proto(const viam::service::navigation::v1::Waypoint& proto) {
23-
return Navigation::Waypoint{proto.id(), v2::from_proto(proto.location())};
24-
}
21+
template <>
22+
struct from_proto<service::navigation::v1::Path> {
23+
Navigation::Path operator()(const service::navigation::v1::Path* proto) const {
24+
return {proto->destination_waypoint_id(), v2::from_proto(proto->geopoints())};
25+
}
26+
};
2527

26-
Navigation::Path from_proto(const viam::service::navigation::v1::Path& proto) {
27-
Navigation::Path ret{proto.destination_waypoint_id()};
28-
repeatedPtrToVec(proto.geopoints(), ret.geopoints);
29-
return ret;
30-
}
28+
template <>
29+
struct from_proto<service::navigation::v1::Waypoint> {
30+
Navigation::Waypoint operator()(const service::navigation::v1::Waypoint* proto) const {
31+
return {proto->id(), v2::from_proto(proto->location())};
32+
}
33+
};
34+
35+
} // namespace proto_convert_details
36+
37+
namespace impl {
38+
39+
using namespace viam::service::navigation::v1;
3140

3241
NavigationClient::NavigationClient(std::string name, std::shared_ptr<grpc::Channel> channel)
3342
: Navigation(std::move(name)),
@@ -63,11 +72,7 @@ Navigation::LocationResponse NavigationClient::get_location(const ProtoStruct& e
6372
std::vector<Navigation::Waypoint> NavigationClient::get_waypoints(const ProtoStruct& extra) {
6473
return make_client_helper(this, *stub_, &StubType::GetWaypoints)
6574
.with([&](auto& request) { *request.mutable_extra() = map_to_struct(extra); })
66-
.invoke([](auto& response) {
67-
std::vector<Navigation::Waypoint> ret;
68-
repeatedPtrToVec(response.waypoints(), ret, from_proto);
69-
return ret;
70-
});
75+
.invoke([](auto& response) { return v2::from_proto(response.waypoints()); });
7176
}
7277

7378
void NavigationClient::add_waypoint(const geo_point& location, const ProtoStruct& extra) {
@@ -91,21 +96,13 @@ void NavigationClient::remove_waypoint(const std::string id, const ProtoStruct&
9196
std::vector<geo_geometry> NavigationClient::get_obstacles(const ProtoStruct& extra) {
9297
return make_client_helper(this, *stub_, &StubType::GetObstacles)
9398
.with([&](auto& request) { *request.mutable_extra() = map_to_struct(extra); })
94-
.invoke([](auto& response) {
95-
std::vector<geo_geometry> ret;
96-
repeatedPtrToVec(response.obstacles(), ret);
97-
return ret;
98-
});
99+
.invoke([](auto& response) { return v2::from_proto(response.obstacles()); });
99100
}
100101

101102
std::vector<NavigationClient::Path> NavigationClient::get_paths(const ProtoStruct& extra) {
102103
return make_client_helper(this, *stub_, &StubType::GetPaths)
103104
.with([&](auto& request) { *request.mutable_extra() = map_to_struct(extra); })
104-
.invoke([](auto& response) {
105-
std::vector<Path> ret;
106-
repeatedPtrToVec(response.paths(), ret, from_proto);
107-
return ret;
108-
});
105+
.invoke([](auto& response) { return v2::from_proto(response.paths()); });
109106
}
110107

111108
NavigationClient::Properties NavigationClient::get_properties() {

src/viam/sdk/services/private/navigation_server.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <grpcpp/support/status.h>
44

55
#include <viam/sdk/common/pose.hpp>
6-
#include <viam/sdk/common/private/proto_utils.hpp>
76
#include <viam/sdk/common/proto_value.hpp>
87
#include <viam/sdk/common/service_helper.hpp>
98
#include <viam/sdk/common/utils.hpp>
@@ -13,23 +12,31 @@
1312

1413
namespace viam {
1514
namespace sdk {
16-
namespace impl {
1715

18-
using namespace service::navigation::v1;
16+
namespace proto_convert_details {
1917

20-
viam::service::navigation::v1::Waypoint to_proto(const Navigation::Waypoint& wp) {
21-
viam::service::navigation::v1::Waypoint ret;
22-
*ret.mutable_id() = wp.id;
23-
*ret.mutable_location() = v2::to_proto(wp.location);
24-
return ret;
25-
}
18+
template <>
19+
struct to_proto<Navigation::Path> {
20+
void operator()(const Navigation::Path& self, service::navigation::v1::Path* proto) const {
21+
*(proto->mutable_destination_waypoint_id()) = self.destination_waypoint_id;
22+
*(proto->mutable_geopoints()) = v2::to_proto(self.geopoints);
23+
}
24+
};
2625

27-
viam::service::navigation::v1::Path to_proto(const Navigation::Path& p) {
28-
viam::service::navigation::v1::Path ret;
29-
*ret.mutable_destination_waypoint_id() = p.destination_waypoint_id;
30-
vecToRepeatedPtr(p.geopoints, *ret.mutable_geopoints());
31-
return ret;
32-
}
26+
template <>
27+
struct to_proto<Navigation::Waypoint> {
28+
void operator()(const Navigation::Waypoint& self,
29+
service::navigation::v1::Waypoint* proto) const {
30+
*(proto->mutable_id()) = self.id;
31+
*(proto->mutable_location()) = v2::to_proto(self.location);
32+
}
33+
};
34+
35+
} // namespace proto_convert_details
36+
37+
namespace impl {
38+
39+
using namespace service::navigation::v1;
3340

3441
::grpc::Status NavigationServer::GetMode(::grpc::ServerContext*,
3542
const GetModeRequest* request,
@@ -65,8 +72,7 @@ ::grpc::Status NavigationServer::GetWaypoints(::grpc::ServerContext*,
6572
GetWaypointsResponse* response) noexcept {
6673
return make_service_helper<Navigation>(
6774
"NavigationServer::GetWaypoints", this, request)([&](auto& helper, auto& nav) {
68-
const auto waypoints = nav->get_waypoints(helper.getExtra());
69-
vecToRepeatedPtr(waypoints, *response->mutable_waypoints(), to_proto);
75+
*(response->mutable_waypoints()) = v2::to_proto(nav->get_waypoints(helper.getExtra()));
7076
});
7177
}
7278

@@ -91,8 +97,7 @@ ::grpc::Status NavigationServer::GetObstacles(::grpc::ServerContext*,
9197
GetObstaclesResponse* response) noexcept {
9298
return make_service_helper<Navigation>(
9399
"NavigationServer::GetObstacles", this, request)([&](auto& helper, auto& nav) {
94-
const auto obstacles = nav->get_obstacles(helper.getExtra());
95-
vecToRepeatedPtr(obstacles, *response->mutable_obstacles());
100+
*(response->mutable_obstacles()) = v2::to_proto(nav->get_obstacles(helper.getExtra()));
96101
});
97102
}
98103

@@ -101,8 +106,7 @@ ::grpc::Status NavigationServer::GetPaths(::grpc::ServerContext*,
101106
GetPathsResponse* response) noexcept {
102107
return make_service_helper<Navigation>(
103108
"NavigationServer::GetPaths", this, request)([&](auto& helper, auto& nav) {
104-
const auto paths = nav->get_paths(helper.getExtra());
105-
vecToRepeatedPtr(paths, *response->mutable_paths(), to_proto);
109+
*response->mutable_paths() = v2::to_proto(nav->get_paths(helper.getExtra()));
106110
});
107111
}
108112

0 commit comments

Comments
 (0)