-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of ssh://github.com/viamrobotics/viam-cpp-sdk int…
…o make-proto-conversions-private
- Loading branch information
Showing
24 changed files
with
989 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/// @file common/proto_utils.hpp | ||
/// | ||
/// @brief Utils that require generated proto includes. These should be #included | ||
/// in cpp implementation files, but not in wrapper headers consumed by third party code. | ||
#pragma once | ||
|
||
#include <viam/api/common/v1/common.pb.h> | ||
|
||
namespace viam { | ||
namespace sdk { | ||
namespace impl { | ||
|
||
/// @brief Copies elements from a protobuf repeated pointer array into a std::vector. Src type | ||
/// must have a `to_proto` method. | ||
template <typename Src, typename Dst> | ||
void vecToRepeatedPtr(const std::vector<Src>& vec, google::protobuf::RepeatedPtrField<Dst>& dest) { | ||
dest.Clear(); | ||
dest.Reserve(vec.size()); | ||
for (auto& x : vec) { | ||
*dest.Add() = x.to_proto(); | ||
} | ||
} | ||
|
||
/// @brief Non-member to_proto() version. (necessary for moving generated types out of wrapper | ||
/// headers). Takes explicit `to_proto`. | ||
template <typename Src, typename Dst> | ||
void vecToRepeatedPtr(const std::vector<Src>& vec, | ||
google::protobuf::RepeatedPtrField<Dst>& dest, | ||
Dst to_proto(const Src&)) { | ||
dest.Clear(); | ||
dest.Reserve(vec.size()); | ||
for (auto& x : vec) { | ||
*dest.Add() = to_proto(x); | ||
} | ||
} | ||
|
||
/// @brief Copies elements from a std::vector into a protobuf repeated pointer array. Dst type | ||
/// must have a `from_proto` static method. | ||
template <typename Src, typename Dst> | ||
void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src, std::vector<Dst>& vec) { | ||
vec.clear(); | ||
vec.reserve(src.size()); | ||
for (auto& x : src) { | ||
vec.push_back(Dst::from_proto(x)); | ||
} | ||
} | ||
|
||
/// @brief Non-member from_proto() version. (necessary for moving generated types out of wrapper | ||
/// headers). Takes explicit `from_proto`. | ||
template <typename Src, typename Dst> | ||
void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src, | ||
std::vector<Dst>& vec, | ||
Dst from_proto(const Src&)) { | ||
vec.clear(); | ||
vec.reserve(src.size()); | ||
for (auto& x : src) { | ||
vec.push_back(from_proto(x)); | ||
} | ||
} | ||
|
||
} // namespace impl | ||
} // namespace sdk | ||
} // namespace viam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <viam/sdk/services/navigation.hpp> | ||
|
||
#include <viam/api/service/navigation/v1/navigation.pb.h> | ||
#include <viam/sdk/common/private/proto_utils.hpp> | ||
#include <viam/sdk/common/utils.hpp> | ||
|
||
namespace viam { | ||
namespace sdk { | ||
|
||
Navigation::Navigation(std::string name) : Service(std::move(name)){}; | ||
|
||
API Navigation::api() const { | ||
return API::get<Navigation>(); | ||
} | ||
|
||
API API::traits<Navigation>::api() { | ||
return {kRDK, kService, "navigation"}; | ||
} | ||
|
||
} // namespace sdk | ||
} // namespace viam |
Oops, something went wrong.