diff --git a/src/viam/sdk/common/client_helper.hpp b/src/viam/sdk/common/client_helper.hpp index d8db1f338..95d1f8f09 100644 --- a/src/viam/sdk/common/client_helper.hpp +++ b/src/viam/sdk/common/client_helper.hpp @@ -59,7 +59,7 @@ class ClientHelper { ProtoValue value = key->second; debug_key_ = *value.get(); } - *request_.mutable_extra() = map_to_struct(extra); + *request_.mutable_extra() = v2::to_proto(extra); return with(std::forward(rsc)); } diff --git a/src/viam/sdk/common/proto_value.cpp b/src/viam/sdk/common/proto_value.cpp index 0650856de..580941c2e 100644 --- a/src/viam/sdk/common/proto_value.cpp +++ b/src/viam/sdk/common/proto_value.cpp @@ -43,37 +43,6 @@ ProtoValue::ProtoValue(ProtoValue&& other) noexcept(proto_value_details::all_mov ProtoValue::ProtoValue(const ProtoValue& other) : vtable_(other.vtable_), self_(other.self_, other.vtable_) {} -ProtoValue::ProtoValue(const Value* value) // NOLINT(misc-no-recursion) - : ProtoValue([](const Value& v) { // NOLINT(misc-no-recursion) - switch (v.kind_case()) { - case Value::KindCase::kBoolValue: { - return ProtoValue(v.bool_value()); - } - case Value::KindCase::kStringValue: { - return ProtoValue(v.string_value()); - } - case Value::KindCase::kNumberValue: { - return ProtoValue(v.number_value()); - } - case Value::KindCase::kListValue: { - ProtoList vec; - vec.reserve(v.list_value().values_size()); - for (const Value& list_val : v.list_value().values()) { - vec.push_back(ProtoValue::from_proto(list_val)); - } - - return ProtoValue(std::move(vec)); - } - case Value::KindCase::kStructValue: { - return ProtoValue(struct_to_map(v.struct_value())); - } - case Value::KindCase::KIND_NOT_SET: - case Value::KindCase::kNullValue: - default: - return ProtoValue(nullptr); - } - }(*value)) {} - ProtoValue& ProtoValue::operator=(ProtoValue&& other) noexcept( proto_value_details::all_moves_noexcept{}) { ProtoValue(std::move(other)).swap(*this); @@ -98,13 +67,6 @@ void ProtoValue::swap(ProtoValue& other) noexcept(proto_value_details::all_moves std::swap(vtable_, other.vtable_); } -template -ProtoValue ProtoValue::from_proto(const Val& v) { // NOLINT(misc-no-recursion) - return ProtoValue(&v); -} - -template ProtoValue ProtoValue::from_proto(const Value&); - ProtoValue::Kind ProtoValue::kind() const { return vtable_.kind(); } @@ -182,8 +144,8 @@ void ProtoValue::model::move(void* self, void* dest) { } template -void ProtoValue::model::to_proto(void const* self, google::protobuf::Value* v) { - viam::sdk::to_proto(static_cast(self)->data, v); +void ProtoValue::model::to_value(void const* self, google::protobuf::Value* v) { + viam::sdk::proto_value_details::to_value(static_cast(self)->data, v); } template @@ -254,53 +216,94 @@ void ProtoValue::storage::destruct(const ProtoValue::vtable& vtab) noexcept { vtab.dtor(this->get()); } -void to_proto(std::nullptr_t, Value* v) { +namespace proto_value_details { + +void to_value(std::nullptr_t, Value* v) { v->set_null_value(::google::protobuf::NULL_VALUE); } -void to_proto(bool b, Value* v) { +void to_value(bool b, Value* v) { v->set_bool_value(b); } -void to_proto(double d, Value* v) { +void to_value(double d, Value* v) { v->set_number_value(d); } -void to_proto(std::string s, Value* v) { +void to_value(std::string s, Value* v) { v->set_string_value(std::move(s)); } -void to_proto(const ProtoList& vec, Value* v) { +void to_value(const ProtoList& vec, Value* v) { ::google::protobuf::ListValue l; for (const auto& val : vec) { - *l.add_values() = to_proto(val); + *l.add_values() = v2::to_proto(val); } *(v->mutable_list_value()) = std::move(l); } -void to_proto(const ProtoStruct& m, Value* v) { - Struct s; - map_to_struct(m, &s); - - *(v->mutable_struct_value()) = std::move(s); +void to_value(const ProtoStruct& m, Value* v) { + *(v->mutable_struct_value()) = v2::to_proto(m); +} + +} // namespace proto_value_details + +namespace proto_convert_details { + +void to_proto::operator()(const ProtoValue& self, google::protobuf::Value* v) const { + self.vtable_.to_value(self.self_.get(), v); +} + +ProtoValue from_proto::operator()( + const google::protobuf::Value* v) const { // NOLINT(misc-no-recursion) + switch (v->kind_case()) { + case Value::KindCase::kBoolValue: { + return ProtoValue(v->bool_value()); + } + case Value::KindCase::kStringValue: { + return ProtoValue(v->string_value()); + } + case Value::KindCase::kNumberValue: { + return ProtoValue(v->number_value()); + } + case Value::KindCase::kListValue: { + ProtoList vec; + vec.reserve(v->list_value().values_size()); + for (const Value& list_val : v->list_value().values()) { + vec.push_back(v2::from_proto(list_val)); + } + + return ProtoValue(std::move(vec)); + } + case Value::KindCase::kStructValue: { + return ProtoValue(v2::from_proto(v->struct_value())); + } + case Value::KindCase::KIND_NOT_SET: + case Value::KindCase::kNullValue: + default: + return ProtoValue(nullptr); + } } -void to_proto(const ProtoValue& t, Value* v) { - t.vtable_.to_proto(t.self_.get(), v); +void to_proto::operator()(const ProtoStruct& self, google::protobuf::Struct* s) const { + for (const auto& kv : self) { + s->mutable_fields()->insert( + google::protobuf::MapPair(kv.first, v2::to_proto(kv.second))); + } } -void struct_to_map(Struct const* s, ProtoStruct& map) { // NOLINT(misc-no-recursion) +ProtoStruct from_proto::operator()( + const google::protobuf::Struct* s) const { // NOLINT(misc-no-recursion) + ProtoStruct result; + for (const auto& val : s->fields()) { - map.emplace(val.first, ProtoValue::from_proto(val.second)); + result.emplace(val.first, v2::from_proto(val.second)); } -} -void map_to_struct(const ProtoStruct& m, Struct* s) { - for (const auto& kv : m) { - s->mutable_fields()->insert( - google::protobuf::MapPair(kv.first, to_proto(kv.second))); - } + return result; } +} // namespace proto_convert_details + } // namespace sdk } // namespace viam diff --git a/src/viam/sdk/common/proto_value.hpp b/src/viam/sdk/common/proto_value.hpp index 61bd43ea1..cc5102e80 100644 --- a/src/viam/sdk/common/proto_value.hpp +++ b/src/viam/sdk/common/proto_value.hpp @@ -7,6 +7,8 @@ #include #include +#include + namespace google { namespace protobuf { @@ -52,6 +54,8 @@ struct all_moves_noexcept /// definition. class ProtoValue { public: + friend proto_convert_details::to_proto; + /// @brief Type discriminator constants for possible values stored in a ProtoValue. enum Kind { k_null = 0, k_bool = 1, k_double = 2, k_string = 3, k_list = 4, k_struct = 5 }; @@ -110,15 +114,6 @@ class ProtoValue { void swap(ProtoValue& other) noexcept(proto_value_details::all_moves_noexcept{}); - /// @brief Construct from proto value - /// @note This method is trivially templated to insulate google::protobuf::Value from our - /// API/ABI. It is meant to be called with no template parameters in a translation unit which - /// includes - template - static ProtoValue from_proto(const Value& v); // NOLINT(misc-no-recursion) - - friend void to_proto(const ProtoValue& t, google::protobuf::Value* v); - /// @name Value access API ///@{ @@ -178,7 +173,7 @@ class ProtoValue { void (*dtor)(void*); void (*copy)(void const*, void*); void (*move)(void*, void*); - void (*to_proto)(void const*, google::protobuf::Value*); + void (*to_value)(void const*, google::protobuf::Value*); Kind (*kind)(); bool (*equal_to)(void const*, void const*, const vtable&); }; @@ -199,13 +194,13 @@ class ProtoValue { // non-noexcept pointer anyway static void move(void* self, void* dest); - static void to_proto(void const* self, google::protobuf::Value* v); + static void to_value(void const* self, google::protobuf::Value* v); static Kind kind() noexcept; static bool equal_to(void const* self, void const* other, const vtable& other_vtable); - static constexpr vtable vtable_{dtor, copy, move, to_proto, kind, equal_to}; + static constexpr vtable vtable_{dtor, copy, move, to_value, kind, equal_to}; T data; }; @@ -320,55 +315,39 @@ extern template std::string&& ProtoValue::get_unchecked() &&; extern template ProtoList&& ProtoValue::get_unchecked() &&; extern template ProtoStruct&& ProtoValue::get_unchecked() &&; -void to_proto(std::nullptr_t, google::protobuf::Value* v); -void to_proto(bool b, google::protobuf::Value* v); -void to_proto(double d, google::protobuf::Value* v); -void to_proto(std::string s, google::protobuf::Value* v); -void to_proto(const ProtoList& vec, google::protobuf::Value* v); -void to_proto(const ProtoStruct& m, google::protobuf::Value* v); -void to_proto(const ProtoValue& t, google::protobuf::Value* v); - -void struct_to_map(google::protobuf::Struct const* s, ProtoStruct& m); -void map_to_struct(const ProtoStruct& m, google::protobuf::Struct* s); - -/// @brief Convert a type to a google::protobuf::Value. -/// @note This method is trivially templated to insulate google::protobuf::Value from our -/// API/ABI. It is meant to be called with no template parameters in a translation unit which -/// includes -template -Value to_proto(const ProtoValue& proto_value) { - Value v; - to_proto(proto_value, &v); - - return v; -} +namespace proto_convert_details { -/// @brief Convert a google::protobuf::Struct to a ProtoStruct. -/// @note This method is trivially templated to insulate google::protobuf::Struct from our -/// API/ABI. It is meant to be called with no template parameters in a translation unit which -/// includes -template -ProtoStruct struct_to_map(const Struct& s) { - ProtoStruct result; - struct_to_map(&s, result); +template <> +struct to_proto { + void operator()(const ProtoValue&, google::protobuf::Value*) const; +}; - return result; -} +template <> +struct to_proto { + void operator()(const ProtoStruct&, google::protobuf::Struct*) const; +}; -/// @brief Convert a ProtoStruct to a google::protobuf::Struct. -/// @note This method is trivially templated to insulate google::protobuf::Struct from our -/// API/ABI. It is meant to be called with no template parameters in a translation unit which -/// includes -template -Struct map_to_struct(const ProtoStruct& m) { - Struct s; - map_to_struct(m, &s); +template <> +struct from_proto { + ProtoValue operator()(const google::protobuf::Value*) const; +}; - return s; -} +template <> +struct from_proto { + ProtoStruct operator()(const google::protobuf::Struct*) const; +}; + +} // namespace proto_convert_details namespace proto_value_details { +void to_value(std::nullptr_t, google::protobuf::Value* v); +void to_value(bool b, google::protobuf::Value* v); +void to_value(double d, google::protobuf::Value* v); +void to_value(std::string s, google::protobuf::Value* v); +void to_value(const ProtoList& vec, google::protobuf::Value* v); +void to_value(const ProtoStruct& m, google::protobuf::Value* v); + template struct kind {}; diff --git a/src/viam/sdk/common/service_helper.hpp b/src/viam/sdk/common/service_helper.hpp index af65418c5..0dd193fcb 100644 --- a/src/viam/sdk/common/service_helper.hpp +++ b/src/viam/sdk/common/service_helper.hpp @@ -49,7 +49,7 @@ class ServiceHelper : public ServiceHelperBase { } auto getExtra() const { - return request_->has_extra() ? struct_to_map(request_->extra()) : ProtoStruct{}; + return request_->has_extra() ? v2::from_proto(request_->extra()) : ProtoStruct{}; } private: diff --git a/src/viam/sdk/components/private/arm_client.cpp b/src/viam/sdk/components/private/arm_client.cpp index f58115d3c..ea889d1e4 100644 --- a/src/viam/sdk/components/private/arm_client.cpp +++ b/src/viam/sdk/components/private/arm_client.cpp @@ -83,8 +83,8 @@ void ArmClient::stop(const ProtoStruct& extra) { ProtoStruct ArmClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } Arm::KinematicsData ArmClient::get_kinematics(const ProtoStruct& extra) { diff --git a/src/viam/sdk/components/private/arm_server.cpp b/src/viam/sdk/components/private/arm_server.cpp index 6eef7dd6b..505c2122c 100644 --- a/src/viam/sdk/components/private/arm_server.cpp +++ b/src/viam/sdk/components/private/arm_server.cpp @@ -98,8 +98,8 @@ ::grpc::Status ArmServer::DoCommand(::grpc::ServerContext*, const ::viam::common::v1::DoCommandRequest* request, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper("ArmServer::DoCommand", this, request)([&](auto&, auto& arm) { - const ProtoStruct result = arm->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = arm->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/base_client.cpp b/src/viam/sdk/components/private/base_client.cpp index ca325444a..93623d04c 100644 --- a/src/viam/sdk/components/private/base_client.cpp +++ b/src/viam/sdk/components/private/base_client.cpp @@ -99,8 +99,8 @@ Base::properties BaseClient::get_properties(const ProtoStruct& extra) { ProtoStruct BaseClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/base_server.cpp b/src/viam/sdk/components/private/base_server.cpp index 7c19e623d..722a1f9ae 100644 --- a/src/viam/sdk/components/private/base_server.cpp +++ b/src/viam/sdk/components/private/base_server.cpp @@ -106,8 +106,8 @@ ::grpc::Status BaseServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "BaseServer::DoCommand", this, request)([&](auto&, auto& base) { - const ProtoStruct result = base->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = base->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/board_client.cpp b/src/viam/sdk/components/private/board_client.cpp index 072eb0638..b6c6a952f 100644 --- a/src/viam/sdk/components/private/board_client.cpp +++ b/src/viam/sdk/components/private/board_client.cpp @@ -105,8 +105,8 @@ void BoardClient::set_pwm_frequency(const std::string& pin, ProtoStruct BoardClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } // TODO(RSDK-6048) update `client_wrapper` to allow for requests without a `mutable_name()` method, @@ -119,7 +119,7 @@ Board::analog_response BoardClient::read_analog(const std::string& analog_reader request.set_board_name(this->name()); request.set_analog_reader_name(analog_reader_name); - *request.mutable_extra() = map_to_struct(extra); + *request.mutable_extra() = v2::to_proto(extra); const grpc::Status status = stub_->ReadAnalogReader(ctx, request, &response); if (!status.ok()) { @@ -149,7 +149,7 @@ Board::digital_value BoardClient::read_digital_interrupt(const std::string& digi request.set_board_name(this->name()); request.set_digital_interrupt_name(digital_interrupt_name); - *request.mutable_extra() = map_to_struct(extra); + *request.mutable_extra() = v2::to_proto(extra); const grpc::Status status = stub_->GetDigitalInterruptValue(ctx, request, &response); if (!status.ok()) { diff --git a/src/viam/sdk/components/private/board_server.cpp b/src/viam/sdk/components/private/board_server.cpp index acd4662ca..b3064912a 100644 --- a/src/viam/sdk/components/private/board_server.cpp +++ b/src/viam/sdk/components/private/board_server.cpp @@ -105,8 +105,8 @@ ::grpc::Status BoardServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "BoardServer::DoCommand", this, request)([&](auto&, auto& board) { - const ProtoStruct result = board->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = board->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } @@ -128,7 +128,7 @@ ::grpc::Status BoardServer::ReadAnalogReader( ProtoStruct extra; if (request->has_extra()) { - extra = struct_to_map(request->extra()); + extra = v2::from_proto(request->extra()); } const Board::analog_response result = board->read_analog(request->analog_reader_name(), extra); @@ -158,7 +158,7 @@ ::grpc::Status BoardServer::WriteAnalog( ProtoStruct extra; if (request->has_extra()) { - extra = struct_to_map(request->extra()); + extra = v2::from_proto(request->extra()); } board->write_analog(request->pin(), request->value(), extra); @@ -183,7 +183,7 @@ ::grpc::Status BoardServer::GetDigitalInterruptValue( ProtoStruct extra; if (request->has_extra()) { - extra = struct_to_map(request->extra()); + extra = v2::from_proto(request->extra()); } const Board::digital_value result = diff --git a/src/viam/sdk/components/private/camera_client.cpp b/src/viam/sdk/components/private/camera_client.cpp index b86c62cd7..eb2e24ced 100644 --- a/src/viam/sdk/components/private/camera_client.cpp +++ b/src/viam/sdk/components/private/camera_client.cpp @@ -106,8 +106,8 @@ CameraClient::CameraClient(std::string name, std::shared_ptr chan ProtoStruct CameraClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); }; Camera::raw_image CameraClient::get_image(std::string mime_type, const ProtoStruct& extra) { diff --git a/src/viam/sdk/components/private/camera_server.cpp b/src/viam/sdk/components/private/camera_server.cpp index 49ce978b9..eb3532814 100644 --- a/src/viam/sdk/components/private/camera_server.cpp +++ b/src/viam/sdk/components/private/camera_server.cpp @@ -42,8 +42,8 @@ ::grpc::Status CameraServer::DoCommand(::grpc::ServerContext*, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "CameraServer::DoCommand", this, request)([&](auto&, auto& camera) { - const ProtoStruct result = camera->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = camera->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/encoder_client.cpp b/src/viam/sdk/components/private/encoder_client.cpp index e09535b8a..320b095bd 100644 --- a/src/viam/sdk/components/private/encoder_client.cpp +++ b/src/viam/sdk/components/private/encoder_client.cpp @@ -72,8 +72,8 @@ std::vector EncoderClient::get_geometries(const ProtoStruct& ext ProtoStruct EncoderClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/encoder_server.cpp b/src/viam/sdk/components/private/encoder_server.cpp index 798e70d14..a85cbf157 100644 --- a/src/viam/sdk/components/private/encoder_server.cpp +++ b/src/viam/sdk/components/private/encoder_server.cpp @@ -66,8 +66,8 @@ ::grpc::Status EncoderServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "EncoderServer::DoCommand", this, request)([&](auto&, auto& encoder) { - const ProtoStruct result = encoder->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = encoder->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/gantry_client.cpp b/src/viam/sdk/components/private/gantry_client.cpp index 0fac69e89..028c1c55f 100644 --- a/src/viam/sdk/components/private/gantry_client.cpp +++ b/src/viam/sdk/components/private/gantry_client.cpp @@ -65,8 +65,8 @@ void GantryClient::stop(const ProtoStruct& extra) { ProtoStruct GantryClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } std::vector GantryClient::get_geometries(const ProtoStruct& extra) { diff --git a/src/viam/sdk/components/private/gantry_server.cpp b/src/viam/sdk/components/private/gantry_server.cpp index 7e8e6f247..124f6bcef 100644 --- a/src/viam/sdk/components/private/gantry_server.cpp +++ b/src/viam/sdk/components/private/gantry_server.cpp @@ -75,8 +75,8 @@ ::grpc::Status GantryServer::DoCommand(::grpc::ServerContext*, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "GantryServer::DoCommand", this, request)([&](auto&, auto& gantry) { - const ProtoStruct result = gantry->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = gantry->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/generic_client.cpp b/src/viam/sdk/components/private/generic_client.cpp index 96c8db854..ec062a860 100644 --- a/src/viam/sdk/components/private/generic_client.cpp +++ b/src/viam/sdk/components/private/generic_client.cpp @@ -23,8 +23,8 @@ GenericComponentClient::GenericComponentClient(std::string name, ProtoStruct GenericComponentClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } std::vector GenericComponentClient::get_geometries(const ProtoStruct& extra) { diff --git a/src/viam/sdk/components/private/generic_server.cpp b/src/viam/sdk/components/private/generic_server.cpp index 1e2b9423d..75860c819 100644 --- a/src/viam/sdk/components/private/generic_server.cpp +++ b/src/viam/sdk/components/private/generic_server.cpp @@ -17,8 +17,8 @@ ::grpc::Status GenericComponentServer::DoCommand( ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "GenericComponentServer::DoCommand", this, request)([&](auto&, auto& generic) { - const ProtoStruct result = generic->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = generic->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } ::grpc::Status GenericComponentServer::GetGeometries( diff --git a/src/viam/sdk/components/private/gripper_client.cpp b/src/viam/sdk/components/private/gripper_client.cpp index a6070c553..6e77fd52a 100644 --- a/src/viam/sdk/components/private/gripper_client.cpp +++ b/src/viam/sdk/components/private/gripper_client.cpp @@ -38,8 +38,8 @@ void GripperClient::stop(const ProtoStruct& extra) { ProtoStruct GripperClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } std::vector GripperClient::get_geometries(const ProtoStruct& extra) { diff --git a/src/viam/sdk/components/private/gripper_server.cpp b/src/viam/sdk/components/private/gripper_server.cpp index 980988567..1675829af 100644 --- a/src/viam/sdk/components/private/gripper_server.cpp +++ b/src/viam/sdk/components/private/gripper_server.cpp @@ -46,8 +46,8 @@ ::grpc::Status GripperServer::DoCommand(::grpc::ServerContext*, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "GripperServer::DoCommand", this, request)([&](auto&, auto& gripper) { - const ProtoStruct result = gripper->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = gripper->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/motor_client.cpp b/src/viam/sdk/components/private/motor_client.cpp index 7d1f438d9..bad14ccc6 100644 --- a/src/viam/sdk/components/private/motor_client.cpp +++ b/src/viam/sdk/components/private/motor_client.cpp @@ -113,8 +113,8 @@ bool MotorClient::is_moving() { ProtoStruct MotorClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/motor_server.cpp b/src/viam/sdk/components/private/motor_server.cpp index 69739d65e..66f366fe6 100644 --- a/src/viam/sdk/components/private/motor_server.cpp +++ b/src/viam/sdk/components/private/motor_server.cpp @@ -128,8 +128,8 @@ ::grpc::Status MotorServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "MotorServer::GetGeometries", this, request)([&](auto&, auto& motor) { - const ProtoStruct result = motor->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = motor->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/movement_sensor_client.cpp b/src/viam/sdk/components/private/movement_sensor_client.cpp index a4466c622..40eeddcde 100644 --- a/src/viam/sdk/components/private/movement_sensor_client.cpp +++ b/src/viam/sdk/components/private/movement_sensor_client.cpp @@ -117,8 +117,8 @@ Vector3 MovementSensorClient::get_linear_acceleration(const ProtoStruct& extra) ProtoStruct MovementSensorClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } std::vector MovementSensorClient::get_geometries(const ProtoStruct& extra) { diff --git a/src/viam/sdk/components/private/movement_sensor_server.cpp b/src/viam/sdk/components/private/movement_sensor_server.cpp index dc3240265..7f48a61e5 100644 --- a/src/viam/sdk/components/private/movement_sensor_server.cpp +++ b/src/viam/sdk/components/private/movement_sensor_server.cpp @@ -131,8 +131,8 @@ ::grpc::Status MovementSensorServer::DoCommand( viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "MovementSensorServer::DoCommand", this, request)([&](auto&, auto& movementsensor) { - const ProtoStruct result = movementsensor->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = movementsensor->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/pose_tracker_client.cpp b/src/viam/sdk/components/private/pose_tracker_client.cpp index 7d9a7cb6c..25e1f3490 100644 --- a/src/viam/sdk/components/private/pose_tracker_client.cpp +++ b/src/viam/sdk/components/private/pose_tracker_client.cpp @@ -40,8 +40,8 @@ std::vector PoseTrackerClient::get_geometries(const ProtoStruct& ProtoStruct PoseTrackerClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/pose_tracker_server.cpp b/src/viam/sdk/components/private/pose_tracker_server.cpp index 0009b9697..028acb775 100644 --- a/src/viam/sdk/components/private/pose_tracker_server.cpp +++ b/src/viam/sdk/components/private/pose_tracker_server.cpp @@ -36,8 +36,8 @@ ::grpc::Status PoseTrackerServer::DoCommand( viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "PoseTrackerServer::DoCommand", this, request)([&](auto&, auto& pose_tracker) { - const ProtoStruct result = pose_tracker->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = pose_tracker->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/power_sensor_client.cpp b/src/viam/sdk/components/private/power_sensor_client.cpp index 63f2cc6b8..4c064b9ca 100644 --- a/src/viam/sdk/components/private/power_sensor_client.cpp +++ b/src/viam/sdk/components/private/power_sensor_client.cpp @@ -38,7 +38,7 @@ PowerSensor::current from_proto(const GetCurrentResponse& proto) { PowerSensorClient::PowerSensorClient(std::string name, std::shared_ptr channel) : PowerSensor(std::move(name)), stub_(PowerSensorService::NewStub(channel)), - channel_(std::move(channel)){}; + channel_(std::move(channel)) {} PowerSensor::voltage PowerSensorClient::get_voltage(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetVoltage) @@ -64,7 +64,7 @@ ProtoStruct PowerSensorClient::get_readings(const ProtoStruct& extra) { .invoke([](auto& response) { ProtoStruct result; for (const auto& r : response.readings()) { - result.emplace(r.first, ProtoValue::from_proto(r.second)); + result.emplace(r.first, v2::from_proto(r.second)); } return result; }); @@ -72,8 +72,8 @@ ProtoStruct PowerSensorClient::get_readings(const ProtoStruct& extra) { ProtoStruct PowerSensorClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/power_sensor_server.cpp b/src/viam/sdk/components/private/power_sensor_server.cpp index 69461775f..4d81f013e 100644 --- a/src/viam/sdk/components/private/power_sensor_server.cpp +++ b/src/viam/sdk/components/private/power_sensor_server.cpp @@ -27,7 +27,7 @@ GetCurrentResponse to_proto(const PowerSensor::current& c) { } PowerSensorServer::PowerSensorServer(std::shared_ptr manager) - : ResourceServer(std::move(manager)){}; + : ResourceServer(std::move(manager)) {} ::grpc::Status PowerSensorServer::GetVoltage(::grpc::ServerContext*, const GetVoltageRequest* request, @@ -65,10 +65,8 @@ ::grpc::Status PowerSensorServer::GetReadings( viam::common::v1::GetReadingsResponse* response) noexcept { return make_service_helper( "PowerSensorServer::GetReadings", this, request)([&](auto& helper, auto& powersensor) { - const ProtoStruct result = powersensor->get_readings(helper.getExtra()); - for (const auto& r : result) { - response->mutable_readings()->insert({r.first, to_proto(r.second)}); - } + *(response->mutable_readings()) = + v2::to_proto(powersensor->get_readings(helper.getExtra())).fields(); }); } @@ -78,8 +76,8 @@ ::grpc::Status PowerSensorServer::DoCommand( viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "PowerSensorServer::DoCommand", this, request)([&](auto&, auto& powersensor) { - const ProtoStruct result = powersensor->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = powersensor->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/sensor_client.cpp b/src/viam/sdk/components/private/sensor_client.cpp index a083b0474..b28811dd1 100644 --- a/src/viam/sdk/components/private/sensor_client.cpp +++ b/src/viam/sdk/components/private/sensor_client.cpp @@ -29,7 +29,7 @@ ProtoStruct SensorClient::get_readings(const ProtoStruct& extra) { .invoke([](auto& response) { ProtoStruct result; for (const auto& r : response.readings()) { - result.emplace(r.first, ProtoValue::from_proto(r.second)); + result.emplace(r.first, v2::from_proto(r.second)); } return result; }); @@ -37,8 +37,8 @@ ProtoStruct SensorClient::get_readings(const ProtoStruct& extra) { ProtoStruct SensorClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } std::vector SensorClient::get_geometries(const ProtoStruct& extra) { diff --git a/src/viam/sdk/components/private/sensor_server.cpp b/src/viam/sdk/components/private/sensor_server.cpp index 5432a0f33..47301b040 100644 --- a/src/viam/sdk/components/private/sensor_server.cpp +++ b/src/viam/sdk/components/private/sensor_server.cpp @@ -20,10 +20,8 @@ ::grpc::Status SensorServer::GetReadings(::grpc::ServerContext*, GetReadingsResponse* response) noexcept { return make_service_helper( "SensorServer::GetReadings", this, request)([&](auto& helper, auto& sensor) { - const ProtoStruct result = sensor->get_readings(helper.getExtra()); - for (const auto& r : result) { - response->mutable_readings()->insert({r.first, to_proto(r.second)}); - } + *(response->mutable_readings()) = + v2::to_proto(sensor->get_readings(helper.getExtra())).fields(); }); } @@ -32,8 +30,8 @@ ::grpc::Status SensorServer::DoCommand(grpc::ServerContext*, DoCommandResponse* response) noexcept { return make_service_helper( "SensorServer::DoCommand", this, request)([&](auto&, auto& sensor) { - const ProtoStruct result = sensor->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = sensor->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/components/private/servo_client.cpp b/src/viam/sdk/components/private/servo_client.cpp index 6b27bdaff..eb5004e84 100644 --- a/src/viam/sdk/components/private/servo_client.cpp +++ b/src/viam/sdk/components/private/servo_client.cpp @@ -57,8 +57,8 @@ std::vector ServoClient::get_geometries(const ProtoStruct& extra ProtoStruct ServoClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/components/private/servo_server.cpp b/src/viam/sdk/components/private/servo_server.cpp index 8392366a4..831b57781 100644 --- a/src/viam/sdk/components/private/servo_server.cpp +++ b/src/viam/sdk/components/private/servo_server.cpp @@ -67,8 +67,8 @@ ::grpc::Status ServoServer::DoCommand(grpc::ServerContext*, viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "ServoServer::GetGeometries", this, request)([&](auto&, auto& servo) { - const ProtoStruct result = servo->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = servo->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/config/resource.cpp b/src/viam/sdk/config/resource.cpp index 5831428ba..ed772a328 100644 --- a/src/viam/sdk/config/resource.cpp +++ b/src/viam/sdk/config/resource.cpp @@ -96,7 +96,7 @@ ResourceConfig ResourceConfig::from_proto(const viam::app::v1::ComponentConfig& resource.name_ = proto_cfg.name(); resource.namespace__ = proto_cfg.namespace_(); resource.type_ = proto_cfg.type(); - resource.attributes_ = struct_to_map(proto_cfg.attributes()); + resource.attributes_ = v2::from_proto(proto_cfg.attributes()); const std::string& api = proto_cfg.api(); if (api.find(':') != std::string::npos) { resource.api_ = API::from_string(api); @@ -114,14 +114,14 @@ ResourceConfig ResourceConfig::from_proto(const viam::app::v1::ComponentConfig& viam::app::v1::ComponentConfig ResourceConfig::to_proto() const { viam::app::v1::ComponentConfig proto_cfg; - const google::protobuf::Struct s = map_to_struct(attributes_); + const google::protobuf::Struct s = v2::to_proto(attributes_); const google::protobuf::RepeatedPtrField service_configs; for (const auto& svc_cfg : service_config_) { viam::app::v1::ResourceLevelServiceConfig cfg; *cfg.mutable_type() = svc_cfg.type; - *cfg.mutable_attributes() = map_to_struct(svc_cfg.attributes); + *cfg.mutable_attributes() = v2::to_proto(svc_cfg.attributes); *proto_cfg.mutable_service_configs()->Add() = cfg; } @@ -131,7 +131,7 @@ viam::app::v1::ComponentConfig ResourceConfig::to_proto() const { *proto_cfg.mutable_api() = api_.to_string(); const std::string mm = model_.to_string(); *proto_cfg.mutable_model() = mm; - *proto_cfg.mutable_attributes() = map_to_struct(attributes_); + *proto_cfg.mutable_attributes() = v2::to_proto(attributes_); for (const auto& dep : depends_on_) { *proto_cfg.mutable_depends_on()->Add() = dep; } diff --git a/src/viam/sdk/robot/client.cpp b/src/viam/sdk/robot/client.cpp index 068f9bc32..24f3fdee8 100644 --- a/src/viam/sdk/robot/client.cpp +++ b/src/viam/sdk/robot/client.cpp @@ -66,7 +66,7 @@ RobotClient::discovery_query from_proto(const DiscoveryQuery& proto) { RobotClient::discovery from_proto(const Discovery& proto) { RobotClient::discovery discovery; discovery.query = from_proto(proto.query()); - discovery.results = struct_to_map(proto.results()); + discovery.results = v2::from_proto(proto.results()); return discovery; } @@ -74,7 +74,7 @@ RobotClient::frame_system_config from_proto(const FrameSystemConfig& proto) { RobotClient::frame_system_config fsconfig; fsconfig.frame = v2::from_proto(proto.frame()); if (proto.has_kinematics()) { - fsconfig.kinematics = struct_to_map(proto.kinematics()); + fsconfig.kinematics = v2::from_proto(proto.kinematics()); } return fsconfig; } @@ -85,7 +85,7 @@ RobotClient::status from_proto(const Status& proto) { status.name = Name::from_proto(proto.name()); } if (proto.has_status()) { - status.status_map = struct_to_map(proto.status()); + status.status_map = v2::from_proto(proto.status()); } if (proto.has_last_reconfigured()) { status.last_reconfigured = timestamp_to_time_pt(proto.last_reconfigured()); @@ -101,7 +101,7 @@ RobotClient::operation from_proto(const Operation& proto) { op.session_id = proto.session_id(); } if (proto.has_arguments()) { - op.arguments = struct_to_map(proto.arguments()); + op.arguments = v2::from_proto(proto.arguments()); } if (proto.has_started()) { op.started = timestamp_to_time_pt(proto.started()); @@ -115,20 +115,20 @@ bool operator==(const RobotClient::discovery_query& lhs, const RobotClient::disc } bool operator==(const RobotClient::discovery& lhs, const RobotClient::discovery& rhs) { - return lhs.query == rhs.query && map_to_struct(lhs.results).SerializeAsString() == - map_to_struct(rhs.results).SerializeAsString(); + return lhs.query == rhs.query && v2::to_proto(lhs.results).SerializeAsString() == + v2::to_proto(rhs.results).SerializeAsString(); } bool operator==(const RobotClient::frame_system_config& lhs, const RobotClient::frame_system_config& rhs) { - return lhs.frame == rhs.frame && map_to_struct(lhs.kinematics).SerializeAsString() == - map_to_struct(rhs.kinematics).SerializeAsString(); + return lhs.frame == rhs.frame && v2::to_proto(lhs.kinematics).SerializeAsString() == + v2::to_proto(rhs.kinematics).SerializeAsString(); } bool operator==(const RobotClient::status& lhs, const RobotClient::status& rhs) { return lhs.name == rhs.name && - map_to_struct(lhs.status_map).SerializeAsString() == - map_to_struct(rhs.status_map).SerializeAsString() && + v2::to_proto(lhs.status_map).SerializeAsString() == + v2::to_proto(rhs.status_map).SerializeAsString() && lhs.last_reconfigured == rhs.last_reconfigured; } @@ -454,7 +454,7 @@ void RobotClient::stop_all(const std::unordered_map& extra) { for (const auto& xtra : extra) { const Name& name = xtra.first; const ProtoStruct& params = xtra.second; - const google::protobuf::Struct s = map_to_struct(params); + const google::protobuf::Struct s = v2::to_proto(params); viam::robot::v1::StopExtraParameters stop; *stop.mutable_name() = name.to_proto(); *stop.mutable_params() = s; diff --git a/src/viam/sdk/robot/service.cpp b/src/viam/sdk/robot/service.cpp index 20f5d62bb..cb8bdc40b 100644 --- a/src/viam/sdk/robot/service.cpp +++ b/src/viam/sdk/robot/service.cpp @@ -185,7 +185,7 @@ ::grpc::Status RobotService_::StopAll(::grpc::ServerContext*, std::unordered_map extra; for (const auto& ex : request->extra()) { const google::protobuf::Struct& struct_ = ex.params(); - const ProtoStruct value_map = struct_to_map(struct_); + const ProtoStruct value_map = v2::from_proto(struct_); const std::string name = ex.name().SerializeAsString(); extra.emplace(name, value_map); } diff --git a/src/viam/sdk/services/private/generic_client.cpp b/src/viam/sdk/services/private/generic_client.cpp index de953d291..dabe414ec 100644 --- a/src/viam/sdk/services/private/generic_client.cpp +++ b/src/viam/sdk/services/private/generic_client.cpp @@ -22,8 +22,8 @@ GenericServiceClient::GenericServiceClient(std::string name, std::shared_ptr manager) - : ResourceServer(std::move(manager)){}; + : ResourceServer(std::move(manager)) {} ::grpc::Status GenericServiceServer::DoCommand( ::grpc::ServerContext*, @@ -17,8 +17,8 @@ ::grpc::Status GenericServiceServer::DoCommand( ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "GenericServiceServer::DoCommand", this, request)([&](auto&, auto& generic) { - const ProtoStruct result = generic->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = generic->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); } diff --git a/src/viam/sdk/services/private/mlmodel_client.cpp b/src/viam/sdk/services/private/mlmodel_client.cpp index d02405980..8b7fd6039 100644 --- a/src/viam/sdk/services/private/mlmodel_client.cpp +++ b/src/viam/sdk/services/private/mlmodel_client.cpp @@ -49,7 +49,7 @@ std::shared_ptr MLModelServiceClient::infer( auto* const req = pb::Arena::VIAM_SDK_PB_CREATE_MESSAGE(arena.get()); req->set_name(this->name()); - *req->mutable_extra() = map_to_struct(extra); + *req->mutable_extra() = v2::to_proto(extra); auto* const resp = pb::Arena::VIAM_SDK_PB_CREATE_MESSAGE(arena.get()); ClientContext ctx; @@ -93,7 +93,7 @@ struct MLModelService::metadata MLModelServiceClient::metadata(const ProtoStruct // Encode metadata args into a `MetadataRequest` viam::service::mlmodel::v1::MetadataRequest req; *req.mutable_name() = name(); - *req.mutable_extra() = map_to_struct(extra); + *req.mutable_extra() = v2::to_proto(extra); // Invoke the stub ClientContext ctx; @@ -150,7 +150,7 @@ struct MLModelService::metadata MLModelServiceClient::metadata(const ProtoStruct } } if (s.has_extra()) { - ti.extra = struct_to_map(s.extra()); + ti.extra = v2::from_proto(s.extra()); } } }; diff --git a/src/viam/sdk/services/private/mlmodel_server.cpp b/src/viam/sdk/services/private/mlmodel_server.cpp index da0ac4b91..2e3d3c2c2 100644 --- a/src/viam/sdk/services/private/mlmodel_server.cpp +++ b/src/viam/sdk/services/private/mlmodel_server.cpp @@ -142,7 +142,7 @@ ::grpc::Status MLModelServiceServer::Metadata( break; } } - *new_entry.mutable_extra() = map_to_struct(s.extra); + *new_entry.mutable_extra() = v2::to_proto(s.extra); } return ::grpc::Status(); }; diff --git a/src/viam/sdk/services/private/motion_client.cpp b/src/viam/sdk/services/private/motion_client.cpp index fa87ae56e..fe5aa59fe 100644 --- a/src/viam/sdk/services/private/motion_client.cpp +++ b/src/viam/sdk/services/private/motion_client.cpp @@ -351,8 +351,8 @@ std::vector MotionClient::list_active_plan_statuses ProtoStruct MotionClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/services/private/motion_server.cpp b/src/viam/sdk/services/private/motion_server.cpp index fcc28dbcf..0f81af575 100644 --- a/src/viam/sdk/services/private/motion_server.cpp +++ b/src/viam/sdk/services/private/motion_server.cpp @@ -354,8 +354,8 @@ ::grpc::Status MotionServer::DoCommand(::grpc::ServerContext*, ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "MotionServer::DoCommand", this, request)([&](auto&, auto& motion) { - const ProtoStruct result = motion->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = motion->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); }; diff --git a/src/viam/sdk/services/private/navigation_client.cpp b/src/viam/sdk/services/private/navigation_client.cpp index da4e1bf65..a165eda58 100644 --- a/src/viam/sdk/services/private/navigation_client.cpp +++ b/src/viam/sdk/services/private/navigation_client.cpp @@ -36,7 +36,7 @@ NavigationClient::NavigationClient(std::string name, std::shared_ptr NavigationClient::get_waypoints(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetWaypoints) - .with([&](auto& request) { *request.mutable_extra() = map_to_struct(extra); }) + .with([&](auto& request) { *request.mutable_extra() = v2::to_proto(extra); }) .invoke([](auto& response) { std::vector ret; repeatedPtrToVec(response.waypoints(), ret, from_proto); @@ -74,7 +74,7 @@ void NavigationClient::add_waypoint(const geo_point& location, const ProtoStruct return make_client_helper(this, *stub_, &StubType::AddWaypoint) .with([&](auto& request) { *request.mutable_location() = v2::to_proto(location); - *request.mutable_extra() = map_to_struct(extra); + *request.mutable_extra() = v2::to_proto(extra); }) .invoke([](auto& response) {}); } @@ -83,14 +83,14 @@ void NavigationClient::remove_waypoint(const std::string id, const ProtoStruct& return make_client_helper(this, *stub_, &StubType::RemoveWaypoint) .with([&](auto& request) { *request.mutable_id() = id; - *request.mutable_extra() = map_to_struct(extra); + *request.mutable_extra() = v2::to_proto(extra); }) .invoke([](auto& response) {}); } std::vector NavigationClient::get_obstacles(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetObstacles) - .with([&](auto& request) { *request.mutable_extra() = map_to_struct(extra); }) + .with([&](auto& request) { *request.mutable_extra() = v2::to_proto(extra); }) .invoke([](auto& response) { std::vector ret; repeatedPtrToVec(response.obstacles(), ret); @@ -100,7 +100,7 @@ std::vector NavigationClient::get_obstacles(const ProtoStruct& ext std::vector NavigationClient::get_paths(const ProtoStruct& extra) { return make_client_helper(this, *stub_, &StubType::GetPaths) - .with([&](auto& request) { *request.mutable_extra() = map_to_struct(extra); }) + .with([&](auto& request) { *request.mutable_extra() = v2::to_proto(extra); }) .invoke([](auto& response) { std::vector ret; repeatedPtrToVec(response.paths(), ret, from_proto); @@ -116,8 +116,8 @@ NavigationClient::Properties NavigationClient::get_properties() { ProtoStruct NavigationClient::do_command(const ProtoStruct& command) { return make_client_helper(this, *stub_, &StubType::DoCommand) - .with([&](auto& request) { *request.mutable_command() = map_to_struct(command); }) - .invoke([](auto& response) { return struct_to_map(response.result()); }); + .with([&](auto& request) { *request.mutable_command() = v2::to_proto(command); }) + .invoke([](auto& response) { return v2::from_proto(response.result()); }); } } // namespace impl diff --git a/src/viam/sdk/services/private/navigation_server.cpp b/src/viam/sdk/services/private/navigation_server.cpp index 5d8bdc2c2..f803918fa 100644 --- a/src/viam/sdk/services/private/navigation_server.cpp +++ b/src/viam/sdk/services/private/navigation_server.cpp @@ -122,8 +122,8 @@ ::grpc::Status NavigationServer::DoCommand( ::viam::common::v1::DoCommandResponse* response) noexcept { return make_service_helper( "NavigationServer::DoCommand", this, request)([&](auto&, auto& motion) { - const ProtoStruct result = motion->do_command(struct_to_map(request->command())); - *response->mutable_result() = map_to_struct(result); + const ProtoStruct result = motion->do_command(v2::from_proto(request->command())); + *response->mutable_result() = v2::to_proto(result); }); }; diff --git a/src/viam/sdk/tests/mocks/mock_robot.cpp b/src/viam/sdk/tests/mocks/mock_robot.cpp index 43b9b509a..7f9e23a13 100644 --- a/src/viam/sdk/tests/mocks/mock_robot.cpp +++ b/src/viam/sdk/tests/mocks/mock_robot.cpp @@ -95,7 +95,7 @@ std::vector mock_proto_discovery_response() { viam::robot::v1::Discovery discovery; *discovery.mutable_query() = query; - *discovery.mutable_results() = map_to_struct(d.results); + *discovery.mutable_results() = v2::to_proto(d.results); v.push_back(std::move(discovery)); } diff --git a/src/viam/sdk/tests/test_proto_value.cpp b/src/viam/sdk/tests/test_proto_value.cpp index 169110e8c..320002854 100644 --- a/src/viam/sdk/tests/test_proto_value.cpp +++ b/src/viam/sdk/tests/test_proto_value.cpp @@ -91,9 +91,9 @@ BOOST_AUTO_TEST_CASE(test_object_equality) { BOOST_CHECK(v1_copy_to_change == v3); } - Value converted = to_proto(v3); - auto roundtrip = ProtoValue::from_proto(converted); - Value value_roundtrip = to_proto(roundtrip); + Value converted = v2::to_proto(v3); + auto roundtrip = v2::from_proto(converted); + Value value_roundtrip = v2::to_proto(roundtrip); BOOST_CHECK(v3.kind() == roundtrip.kind()); @@ -215,9 +215,9 @@ BOOST_AUTO_TEST_CASE(test_nested_objects) { ProtoValue map_proto(map); - Value val = to_proto(map_proto); - auto roundtrip = ProtoValue::from_proto(val); - Value val2 = to_proto(roundtrip); + Value val = v2::to_proto(map_proto); + auto roundtrip = v2::from_proto(val); + Value val2 = v2::to_proto(roundtrip); BOOST_CHECK(map_proto == roundtrip); @@ -243,13 +243,13 @@ BOOST_AUTO_TEST_CASE(test_manual_list_conversion) { Value protoval; set_proto_value(protoval, test_val); - auto from_value = ProtoValue::from_proto(protoval); + auto from_value = v2::from_proto(protoval); BOOST_CHECK(val == from_value); - Value converted_to_value = to_proto(val); + Value converted_to_value = v2::to_proto(val); BOOST_CHECK(protoval.ShortDebugString() == converted_to_value.ShortDebugString()); - auto roundtrip = ProtoValue::from_proto(converted_to_value); + auto roundtrip = v2::from_proto(converted_to_value); BOOST_CHECK(val == roundtrip); }); @@ -286,10 +286,10 @@ BOOST_AUTO_TEST_CASE(test_manual_list_conversion) { Value v; *v.mutable_list_value() = lv; - Value value_from_proto = to_proto(proto); + Value value_from_proto = v2::to_proto(proto); BOOST_CHECK(v.ShortDebugString() == value_from_proto.ShortDebugString()); - auto roundtrip = ProtoValue::from_proto(value_from_proto); + auto roundtrip = v2::from_proto(value_from_proto); BOOST_CHECK(proto == roundtrip); } @@ -314,7 +314,7 @@ BOOST_AUTO_TEST_CASE(test_manual_map_conversion) { Value v; *v.mutable_struct_value() = proto_struct; - auto from_proto = ProtoValue::from_proto(v); + auto from_proto = v2::from_proto(v); ProtoValue from_map(m); BOOST_CHECK(from_proto == from_map); diff --git a/src/viam/sdk/tests/test_resource.cpp b/src/viam/sdk/tests/test_resource.cpp index a14bfa917..db950355a 100644 --- a/src/viam/sdk/tests/test_resource.cpp +++ b/src/viam/sdk/tests/test_resource.cpp @@ -246,7 +246,7 @@ BOOST_AUTO_TEST_CASE(test_resource) { Value value; for (const auto& key_and_value : resource2.attributes()) { key = key_and_value.first; - value = to_proto(key_and_value.second); + value = v2::to_proto(key_and_value.second); } BOOST_CHECK_EQUAL(key, "a"); BOOST_CHECK_EQUAL(value.number_value(), 1); diff --git a/src/viam/sdk/tests/test_robot.cpp b/src/viam/sdk/tests/test_robot.cpp index a7658b3f5..605e5f5bf 100644 --- a/src/viam/sdk/tests/test_robot.cpp +++ b/src/viam/sdk/tests/test_robot.cpp @@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(test_frame_system_config) { proto1.frame().pose_in_observer_frame().pose().o_x()); BOOST_CHECK_EQUAL(config1.frame.pose_in_observer_frame.pose.theta, proto1.frame().pose_in_observer_frame().pose().theta()); - BOOST_CHECK_EQUAL(map_to_struct(config1.kinematics).SerializeAsString(), + BOOST_CHECK_EQUAL(v2::to_proto(config1.kinematics).SerializeAsString(), proto1.kinematics().SerializeAsString()); BOOST_CHECK_EQUAL(config2.frame.reference_frame, proto2.frame().reference_frame()); @@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(test_frame_system_config) { proto2.frame().pose_in_observer_frame().pose().o_x()); BOOST_CHECK_EQUAL(config2.frame.pose_in_observer_frame.pose.theta, proto2.frame().pose_in_observer_frame().pose().theta()); - BOOST_CHECK_EQUAL(map_to_struct(config2.kinematics).SerializeAsString(), + BOOST_CHECK_EQUAL(v2::to_proto(config2.kinematics).SerializeAsString(), proto2.kinematics().SerializeAsString()); }); } @@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE(test_discovery) { // test `ProtoValue` conversions. Unfortunately the protobuf `ListValue` type doesn't // seem to have `==` defined, so we convert to a `DebugString` here to verify // comparison and to provide helpful printing of differences in case of an error. - BOOST_CHECK_EQUAL(to_proto(results->second).DebugString(), + BOOST_CHECK_EQUAL(v2::to_proto(results->second).DebugString(), proto_results->second.DebugString()); }); }