Viam C++ SDK current
Loading...
Searching...
No Matches
repeated_ptr_convert.hpp
1#pragma once
2
3#include <vector>
4
5#include <google/protobuf/repeated_field.h>
6
7#include <viam/sdk/common/proto_convert.hpp>
8
9namespace viam {
10namespace sdk {
11namespace impl {
12
13template <typename T, typename = EquivalentApiType<T>>
14auto to_repeated_field(const std::vector<T>& v) {
16 result.Reserve(v.size());
17
18 for (const auto& elem : v) {
19 *(result.Add()) = to_proto(elem);
20 }
21
22 return result;
23}
24
25template <typename T, typename = EquivalentSdkType<T>>
26auto from_repeated_field(const ::google::protobuf::RepeatedPtrField<T>& v) {
27 std::vector<EquivalentSdkType<T>> result;
28 result.reserve(v.size());
29
30 for (const auto& elem : v) {
31 result.push_back(from_proto(elem));
32 }
33
34 return result;
35}
36
37} // namespace impl
38} // namespace sdk
39} // namespace viam
Definition service.hpp:15