Skip to content

Commit c6ab72d

Browse files
authored
RSDK-6634 - remove resource proto conversions from public headers (#328)
1 parent 7c8487c commit c6ab72d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+740
-1045
lines changed

src/viam/examples/modules/complex/proto/buf.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ deps:
44
- remote: buf.build
55
owner: googleapis
66
repository: googleapis
7-
commit: e7f8d366f5264595bcc4cd4139af9973
8-
digest: shake256:e5e5f1c12f82e028ea696faa43b4f9dc6258a6d1226282962a8c8b282e10946281d815884f574bd279ebd9cd7588629beb3db17b892af6c33b56f92f8f67f509
7+
commit: c0913f24652a4cfc95f77d97443a5005
8+
digest: shake256:0ef3248c6235d420fe61f373154adcde6b94e3297f82472b1d8d8c3747240b61b4a10405e2a6f8ac1c98816ac6e690ea7871024aa5ae0e035cd540214667ceed

src/viam/sdk/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ target_sources(viamsdk
7676
components/private/board_server.cpp
7777
components/private/camera_client.cpp
7878
components/private/camera_server.cpp
79+
components/private/encoder.cpp
7980
components/private/encoder_client.cpp
8081
components/private/encoder_server.cpp
8182
components/private/gantry_client.cpp

src/viam/sdk/components/arm.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@ API API::traits<Arm>::api() {
1111
return {kRDK, kComponent, "arm"};
1212
}
1313

14-
Arm::KinematicsData Arm::from_proto(const viam::common::v1::GetKinematicsResponse& proto) {
15-
std::vector<unsigned char> bytes(proto.kinematics_data().begin(),
16-
proto.kinematics_data().end());
17-
switch (proto.format()) {
18-
case common::v1::KinematicsFileFormat::KINEMATICS_FILE_FORMAT_SVA:
19-
return Arm::KinematicsDataSVA(std::move(bytes));
20-
case common::v1::KinematicsFileFormat::KINEMATICS_FILE_FORMAT_URDF:
21-
return Arm::KinematicsDataURDF(std::move(bytes));
22-
case common::v1::KinematicsFileFormat::KINEMATICS_FILE_FORMAT_UNSPECIFIED: // fallthrough
23-
default:
24-
return Arm::KinematicsDataUnspecified{};
25-
}
26-
}
27-
2814
Arm::Arm(std::string name) : Component(std::move(name)) {}
2915

3016
} // namespace sdk

src/viam/sdk/components/arm.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <boost/optional/optional.hpp>
99
#include <boost/variant/variant.hpp>
1010

11-
#include <viam/api/common/v1/common.pb.h>
12-
1311
#include <viam/sdk/common/pose.hpp>
1412
#include <viam/sdk/resource/stoppable.hpp>
1513
#include <viam/sdk/spatialmath/geometry.hpp>
@@ -67,8 +65,6 @@ class Arm : public Component, public Stoppable {
6765
boost::optional<double> max_acc_degs_per_sec2;
6866
};
6967

70-
static KinematicsData from_proto(const viam::common::v1::GetKinematicsResponse& proto);
71-
7268
/// @brief Get the current position of the end of the arm.
7369
/// @return The `pose` representing the end position of the arm.
7470
inline pose get_end_position() {

src/viam/sdk/components/base.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
#include <viam/sdk/components/base.hpp>
22

3-
#include <google/protobuf/descriptor.h>
4-
5-
#include <viam/api/component/base/v1/base.grpc.pb.h>
6-
#include <viam/api/component/base/v1/base.pb.h>
7-
8-
#include <viam/sdk/common/utils.hpp>
9-
#include <viam/sdk/resource/resource.hpp>
10-
113
namespace viam {
124
namespace sdk {
135

@@ -19,12 +11,6 @@ API API::traits<Base>::api() {
1911
return {kRDK, kComponent, "base"};
2012
}
2113

22-
Base::properties Base::properties::from_proto(
23-
const component::base::v1::GetPropertiesResponse& proto) {
24-
return {
25-
proto.width_meters(), proto.turning_radius_meters(), proto.wheel_circumference_meters()};
26-
}
27-
2814
std::ostream& operator<<(std::ostream& os, const Base::properties& v) {
2915
os << "{ turning_radius_meters: " << v.turning_radius_meters
3016
<< ", wheel_circumference_meters: " << v.wheel_circumference_meters

src/viam/sdk/components/base.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
#include <string>
77

8-
#include <viam/api/component/base/v1/base.pb.h>
9-
108
#include <viam/sdk/common/linear_algebra.hpp>
119
#include <viam/sdk/common/proto_value.hpp>
1210
#include <viam/sdk/common/utils.hpp>
@@ -32,8 +30,6 @@ class Base : public Component, public Stoppable {
3230
double width_meters;
3331
double turning_radius_meters;
3432
double wheel_circumference_meters;
35-
36-
static properties from_proto(const component::base::v1::GetPropertiesResponse& proto);
3733
};
3834
friend std::ostream& operator<<(std::ostream& os, const properties& v);
3935
friend bool operator==(const properties& lhs, const properties& rhs);

src/viam/sdk/components/board.cpp

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
#include <google/protobuf/descriptor.h>
44

5-
#include <viam/api/component/board/v1/board.grpc.pb.h>
6-
#include <viam/api/component/board/v1/board.pb.h>
7-
8-
#include <viam/sdk/common/exception.hpp>
95
#include <viam/sdk/common/utils.hpp>
106
#include <viam/sdk/resource/resource.hpp>
117

@@ -20,59 +16,6 @@ API API::traits<Board>::api() {
2016
return {kRDK, kComponent, "board"};
2117
}
2218

23-
Board::status Board::from_proto(const viam::component::board::v1::Status& proto) {
24-
Board::status status;
25-
for (const auto& analog : proto.analogs()) {
26-
status.analog_reader_values.emplace(analog.first, analog.second);
27-
}
28-
for (const auto& digital : proto.digital_interrupts()) {
29-
status.digital_interrupt_values.emplace(digital.first, digital.second);
30-
}
31-
return status;
32-
}
33-
34-
Board::power_mode Board::from_proto(viam::component::board::v1::PowerMode proto) {
35-
switch (proto) {
36-
case viam::component::board::v1::POWER_MODE_NORMAL: {
37-
return Board::power_mode::normal;
38-
}
39-
case viam::component::board::v1::POWER_MODE_OFFLINE_DEEP: {
40-
return Board::power_mode::offline_deep;
41-
}
42-
case viam::component::board::v1::POWER_MODE_UNSPECIFIED:
43-
default: {
44-
throw Exception(ErrorCondition::k_not_supported,
45-
"Invalid proto board power_mode to decode");
46-
}
47-
}
48-
}
49-
50-
viam::component::board::v1::Status Board::to_proto(const status& status) {
51-
viam::component::board::v1::Status proto;
52-
for (const auto& analog : status.analog_reader_values) {
53-
proto.mutable_analogs()->insert({analog.first, analog.second});
54-
}
55-
56-
for (const auto& digital : status.digital_interrupt_values) {
57-
proto.mutable_digital_interrupts()->insert({digital.first, digital.second});
58-
}
59-
return proto;
60-
}
61-
62-
viam::component::board::v1::PowerMode Board::to_proto(Board::power_mode power_mode) {
63-
switch (power_mode) {
64-
case Board::power_mode::normal: {
65-
return viam::component::board::v1::POWER_MODE_NORMAL;
66-
}
67-
case Board::power_mode::offline_deep: {
68-
return viam::component::board::v1::POWER_MODE_OFFLINE_DEEP;
69-
}
70-
default: {
71-
throw Exception(ErrorCondition::k_not_supported, "Invalid board power_mode to encode");
72-
}
73-
}
74-
}
75-
7619
Board::Board(std::string name) : Component(std::move(name)){};
7720

7821
bool operator==(const Board::status& lhs, const Board::status& rhs) {

src/viam/sdk/components/board.hpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include <string>
88
#include <unordered_map>
99

10-
#include <viam/api/component/board/v1/board.pb.h>
11-
1210
#include <viam/sdk/common/proto_value.hpp>
1311
#include <viam/sdk/common/utils.hpp>
1412
#include <viam/sdk/config/resource.hpp>
@@ -76,18 +74,6 @@ class Board : public Component {
7674

7775
API api() const override;
7876

79-
/// @brief Creates a `status` struct from its proto representation.
80-
static status from_proto(const viam::component::board::v1::Status& proto);
81-
82-
/// @brief Creates a `power_mode` enum from its proto representation.
83-
static power_mode from_proto(viam::component::board::v1::PowerMode proto);
84-
85-
/// @brief Converts a `status` struct to its proto representation.
86-
static viam::component::board::v1::Status to_proto(const status& status);
87-
88-
/// @brief Converts a `power_mode` enum to its proto representation.
89-
static viam::component::board::v1::PowerMode to_proto(power_mode power_mode);
90-
9177
/// @brief Gets the high/low state of the given pin on a board.
9278
/// @param pin board pin name
9379
/// @return high/low state of the given pin. High = on, low = off

src/viam/sdk/components/camera.cpp

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
#include <google/protobuf/descriptor.h>
44
#include <google/protobuf/util/time_util.h>
55

6-
#include <viam/api/common/v1/common.pb.h>
7-
#include <viam/api/component/camera/v1/camera.grpc.pb.h>
8-
#include <viam/api/component/camera/v1/camera.pb.h>
9-
106
#include <viam/sdk/common/exception.hpp>
117
#include <viam/sdk/common/utils.hpp>
128
#include <viam/sdk/resource/resource.hpp>
@@ -134,127 +130,6 @@ std::string Camera::normalize_mime_type(const std::string& str) {
134130
return mime_type;
135131
}
136132

137-
std::string Camera::format_to_MIME_string(viam::component::camera::v1::Format format) {
138-
switch (format) {
139-
case viam::component::camera::v1::FORMAT_RAW_RGBA:
140-
return "image/vnd.viam.rgba";
141-
case viam::component::camera::v1::FORMAT_RAW_DEPTH:
142-
return "image/vnd.viam.dep";
143-
case viam::component::camera::v1::FORMAT_JPEG:
144-
return "image/jpeg";
145-
case viam::component::camera::v1::FORMAT_PNG:
146-
return "image/png";
147-
default:
148-
return "";
149-
}
150-
}
151-
152-
::viam::component::camera::v1::Format Camera::MIME_string_to_format(
153-
const std::string& mime_string) {
154-
if (mime_string == "image/vnd.viam.rgba") {
155-
return viam::component::camera::v1::FORMAT_RAW_RGBA;
156-
}
157-
if (mime_string == "image/vnd.viam.dep") {
158-
return viam::component::camera::v1::FORMAT_RAW_DEPTH;
159-
}
160-
if (mime_string == "image/jpeg") {
161-
return viam::component::camera::v1::FORMAT_JPEG;
162-
}
163-
if (mime_string == "image/png") {
164-
return viam::component::camera::v1::FORMAT_PNG;
165-
}
166-
return viam::component::camera::v1::FORMAT_UNSPECIFIED;
167-
}
168-
169-
Camera::raw_image Camera::from_proto(const viam::component::camera::v1::GetImageResponse& proto) {
170-
Camera::raw_image raw_image;
171-
std::string img_string = proto.image();
172-
const std::vector<unsigned char> bytes(img_string.begin(), img_string.end());
173-
raw_image.bytes = bytes;
174-
raw_image.mime_type = proto.mime_type();
175-
raw_image.source_name = "";
176-
return raw_image;
177-
}
178-
179-
Camera::image_collection Camera::from_proto(
180-
const viam::component::camera::v1::GetImagesResponse& proto) {
181-
Camera::image_collection image_collection;
182-
std::vector<Camera::raw_image> images;
183-
for (const auto& img : proto.images()) {
184-
Camera::raw_image raw_image;
185-
std::string img_string = img.image();
186-
const std::vector<unsigned char> bytes(img_string.begin(), img_string.end());
187-
raw_image.bytes = bytes;
188-
raw_image.mime_type = format_to_MIME_string(img.format());
189-
raw_image.source_name = img.source_name();
190-
images.push_back(raw_image);
191-
}
192-
image_collection.images = std::move(images);
193-
image_collection.metadata = response_metadata::from_proto(proto.response_metadata());
194-
return image_collection;
195-
}
196-
197-
Camera::point_cloud Camera::from_proto(
198-
const viam::component::camera::v1::GetPointCloudResponse& proto) {
199-
Camera::point_cloud point_cloud;
200-
std::string pc_string = proto.point_cloud();
201-
const std::vector<unsigned char> bytes(pc_string.begin(), pc_string.end());
202-
point_cloud.pc = bytes;
203-
point_cloud.mime_type = proto.mime_type();
204-
return point_cloud;
205-
}
206-
207-
Camera::intrinsic_parameters Camera::from_proto(
208-
const viam::component::camera::v1::IntrinsicParameters& proto) {
209-
Camera::intrinsic_parameters params;
210-
// NOLINTNEXTLINE(bugprone-narrowing-conversions)
211-
params.width_px = proto.width_px();
212-
// NOLINTNEXTLINE(bugprone-narrowing-conversions)
213-
params.height_px = proto.height_px();
214-
params.focal_x_px = proto.focal_x_px();
215-
params.focal_y_px = proto.focal_y_px();
216-
params.center_x_px = proto.center_x_px();
217-
params.center_y_px = proto.center_y_px();
218-
return params;
219-
}
220-
221-
Camera::distortion_parameters Camera::from_proto(
222-
const viam::component::camera::v1::DistortionParameters& proto) {
223-
Camera::distortion_parameters params;
224-
params.model = proto.model();
225-
params.parameters = {proto.parameters().begin(), proto.parameters().end()};
226-
return params;
227-
}
228-
229-
Camera::properties Camera::from_proto(
230-
const viam::component::camera::v1::GetPropertiesResponse& proto) {
231-
return {proto.supports_pcd(),
232-
from_proto(proto.intrinsic_parameters()),
233-
from_proto(proto.distortion_parameters()),
234-
{proto.mime_types().begin(), proto.mime_types().end()},
235-
(proto.frame_rate())};
236-
}
237-
238-
viam::component::camera::v1::IntrinsicParameters Camera::to_proto(
239-
const Camera::intrinsic_parameters& params) {
240-
viam::component::camera::v1::IntrinsicParameters proto;
241-
proto.set_width_px(params.width_px);
242-
proto.set_height_px(params.height_px);
243-
proto.set_focal_x_px(params.focal_x_px);
244-
proto.set_focal_y_px(params.focal_y_px);
245-
proto.set_center_x_px(params.center_x_px);
246-
proto.set_center_y_px(params.center_y_px);
247-
return proto;
248-
}
249-
250-
viam::component::camera::v1::DistortionParameters Camera::to_proto(
251-
const Camera::distortion_parameters& params) {
252-
viam::component::camera::v1::DistortionParameters proto;
253-
*proto.mutable_model() = params.model;
254-
*proto.mutable_parameters() = {params.parameters.begin(), params.parameters.end()};
255-
return proto;
256-
}
257-
258133
Camera::Camera(std::string name) : Component(std::move(name)){};
259134

260135
bool operator==(const Camera::point_cloud& lhs, const Camera::point_cloud& rhs) {

0 commit comments

Comments
 (0)