Viam C++ SDK current
Loading...
Searching...
No Matches
proto_utils.hpp
1
5#pragma once
6
7#include <viam/api/common/v1/common.pb.h>
8
9namespace viam {
10namespace sdk {
11namespace impl {
12
15template <typename Src, typename Dst>
16void vecToRepeatedPtr(const std::vector<Src>& vec, google::protobuf::RepeatedPtrField<Dst>& dest) {
17 dest.Clear();
18 dest.Reserve(vec.size());
19 for (auto& x : vec) {
20 *dest.Add() = x.to_proto();
21 }
22}
23
26template <typename Src, typename Dst>
27void vecToRepeatedPtr(const std::vector<Src>& vec,
28 google::protobuf::RepeatedPtrField<Dst>& dest,
29 Dst to_proto(const Src&)) {
30 dest.Clear();
31 dest.Reserve(vec.size());
32 for (auto& x : vec) {
33 *dest.Add() = to_proto(x);
34 }
35}
36
39template <typename Src, typename Dst>
40void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src, std::vector<Dst>& vec) {
41 vec.clear();
42 vec.reserve(src.size());
43 for (auto& x : src) {
44 vec.push_back(Dst::from_proto(x));
45 }
46}
47
50template <typename Src, typename Dst>
51void repeatedPtrToVec(const google::protobuf::RepeatedPtrField<Src>& src,
52 std::vector<Dst>& vec,
53 Dst from_proto(const Src&)) {
54 vec.clear();
55 vec.reserve(src.size());
56 for (auto& x : src) {
57 vec.push_back(from_proto(x));
58 }
59}
60
61} // namespace impl
62} // namespace sdk
63} // namespace viam