Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: remove create_from_json API #311

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ class audio_frame_t : public msg_t {
return std::make_unique<audio_frame_t>(c_frame, ctor_passkey_t());
}

static std::unique_ptr<audio_frame_t> create_from_json(
const char *json_str, error_t *err = nullptr) {
ten_shared_ptr_t *c_audio_frame = ten_audio_frame_create_from_json_string(
json_str,
err != nullptr ? err->get_internal_representation() : nullptr);

return std::make_unique<audio_frame_t>(c_audio_frame, ctor_passkey_t());
}

explicit audio_frame_t(ten_shared_ptr_t *audio_frame,
ctor_passkey_t /*unused*/)
: msg_t(audio_frame) {}
Expand Down
9 changes: 0 additions & 9 deletions core/include/ten_runtime/binding/cpp/internal/msg/cmd/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ class cmd_t : public msg_t {
return std::make_unique<cmd_t>(c_cmd, ctor_passkey_t());
}

static std::unique_ptr<cmd_t> create_from_json(const char *json_str,
error_t *err = nullptr) {
ten_shared_ptr_t *c_cmd = ten_cmd_create_from_json_string(
json_str,
err != nullptr ? err->get_internal_representation() : nullptr);

return std::make_unique<cmd_t>(c_cmd, ctor_passkey_t());
}

explicit cmd_t(ten_shared_ptr_t *cmd, ctor_passkey_t /*unused*/)
: msg_t(cmd) {}

Expand Down
9 changes: 0 additions & 9 deletions core/include/ten_runtime/binding/cpp/internal/msg/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ class data_t : public msg_t {
return std::make_unique<data_t>(c_data, ctor_passkey_t());
}

static std::unique_ptr<data_t> create_from_json(const char *json_str,
error_t *err = nullptr) {
ten_shared_ptr_t *c_data = ten_data_create_from_json_string(
json_str,
err != nullptr ? err->get_internal_representation() : nullptr);

return std::make_unique<data_t>(c_data, ctor_passkey_t());
}

explicit data_t(ten_shared_ptr_t *data, ctor_passkey_t /*unused*/)
: msg_t(data) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ class video_frame_t : public msg_t {
return std::make_unique<video_frame_t>(c_frame, ctor_passkey_t());
}

static std::unique_ptr<video_frame_t> create_from_json(
const char *json_str, error_t *err = nullptr) {
ten_shared_ptr_t *c_video_frame = ten_video_frame_create_from_json_string(
json_str,
err != nullptr ? err->get_internal_representation() : nullptr);

return std::make_unique<video_frame_t>(c_video_frame, ctor_passkey_t());
}

explicit video_frame_t(ten_shared_ptr_t *video_frame,
ctor_passkey_t /*unused*/)
: msg_t(video_frame) {}
Expand Down
26 changes: 10 additions & 16 deletions tests/ten_runtime/smoke/audio_frame_test/create_from_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "gtest/gtest.h"
#include "include_internal/ten_runtime/binding/cpp/ten.h"
#include "ten_runtime/binding/cpp/internal/msg/audio_frame.h"
#include "ten_runtime/msg/audio_frame/audio_frame.h"
#include "ten_utils/lib/thread.h"
#include "tests/common/client/cpp/msgpack_tcp.h"
Expand All @@ -26,22 +27,15 @@ class test_extension_1 : public ten::extension_t {
if (std::string(cmd->get_name()) == "hello_world") {
hello_world_cmd = std::move(cmd);

auto audio_frame = ten::audio_frame_t::create_from_json(
// clang-format off
R"({
"_ten": {
"name": "audio_frame",
"data_fmt": 1,
"bytes_per_sample": 3,
"channel_layout": 2,
"line_size": 100,
"number_of_channel": 555,
"sample_rate": 543,
"timestamp": 12341234
}
})"
// clang-format on
);
auto audio_frame = ten::audio_frame_t::create("audio_frame");
audio_frame->set_data_fmt(TEN_AUDIO_FRAME_DATA_FMT_INTERLEAVE);
audio_frame->set_bytes_per_sample(3);
audio_frame->set_channel_layout(2);
audio_frame->set_line_size(100);
audio_frame->set_number_of_channels(555);
audio_frame->set_sample_rate(543);
audio_frame->set_timestamp(12341234);

ten_env.send_audio_frame(std::move(audio_frame));
} else if (std::string(cmd->get_name()) == "audio_frame_ack") {
auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK);
Expand Down
14 changes: 4 additions & 10 deletions tests/ten_runtime/smoke/data_test/create_from_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "gtest/gtest.h"
#include "include_internal/ten_runtime/binding/cpp/ten.h"
#include "ten_runtime/binding/cpp/internal/msg/data.h"
#include "ten_utils/lib/thread.h"
#include "tests/common/client/cpp/msgpack_tcp.h"
#include "tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h"
Expand All @@ -25,16 +26,9 @@ class test_extension_1 : public ten::extension_t {
if (std::string(cmd->get_name()) == "hello_world") {
hello_world_cmd = std::move(cmd);

auto data = ten::data_t::create_from_json(
// clang-format off
R"({
"_ten": {
"name": "data"
},
"payload": 3
})"
// clang-format on
);
auto data = ten::data_t::create("data");
data->set_property("payload", 3);

ten_env.send_data(std::move(data));
} else if (std::string(cmd->get_name()) == "data_ack") {
auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK);
Expand Down
13 changes: 3 additions & 10 deletions tests/ten_runtime/smoke/msg_test/msg_12.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "gtest/gtest.h"
#include "include_internal/ten_runtime/binding/cpp/ten.h"
#include "ten_runtime/binding/cpp/internal/msg/cmd/cmd.h"
#include "ten_utils/lib/thread.h"
#include "ten_utils/macro/macros.h"
#include "tests/common/client/cpp/msgpack_tcp.h"
#include "tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h"

Expand Down Expand Up @@ -55,15 +55,8 @@ class test_extension_1 : public ten::extension_t {
if (std::string(cmd->get_name()) == "hello_world") {
hello_world_cmd = std::move(cmd);

std::unique_ptr<ten::cmd_t> test_cmd = ten::cmd_t::create_from_json(
R"({
"_ten": {
"type": "cmd",
"name": "test"
}
})");

test_cmd->set_property_from_json("test_data", TEN_XSTR(TEST_DATA));
auto test_cmd = ten::cmd_t::create("test");
test_cmd->set_property("test_data", TEST_DATA);

ten_env.send_cmd(
std::move(test_cmd), [this](ten::ten_env_t &ten_env,
Expand Down
11 changes: 2 additions & 9 deletions tests/ten_runtime/smoke/msg_test/msg_13.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "gtest/gtest.h"
#include "include_internal/ten_runtime/binding/cpp/ten.h"
#include "ten_utils/lib/thread.h"
#include "ten_utils/macro/macros.h"
#include "tests/common/client/cpp/msgpack_tcp.h"
#include "tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h"

Expand Down Expand Up @@ -55,14 +54,8 @@ class test_extension_1 : public ten::extension_t {
if (std::string(cmd->get_name()) == "hello_world") {
hello_world_cmd = std::move(cmd);

std::unique_ptr<ten::cmd_t> test_cmd = ten::cmd_t::create_from_json(
R"({
"_ten": {
"name": "test"
}
})");

test_cmd->set_property_from_json("test_data", TEN_XSTR(TEST_DATA));
auto test_cmd = ten::cmd_t::create("test");
test_cmd->set_property("test_data", TEST_DATA);

ten_env.send_cmd(
std::move(test_cmd), [this](ten::ten_env_t &ten_env,
Expand Down
16 changes: 4 additions & 12 deletions tests/ten_runtime/smoke/msg_test/msg_9.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "gtest/gtest.h"
#include "include_internal/ten_runtime/binding/cpp/ten.h"
#include "ten_runtime/binding/cpp/internal/msg/cmd/cmd.h"
#include "ten_utils/lib/thread.h"
#include "ten_utils/macro/macros.h"
#include "tests/common/client/cpp/msgpack_tcp.h"
#include "tests/ten_runtime/smoke/extension_test/util/binding/cpp/check.h"

Expand Down Expand Up @@ -53,19 +53,11 @@ class test_extension_1 : public ten::extension_t {
void on_cmd(ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_t> cmd) override {
if (std::string(cmd->get_name()) == "hello_world") {
auto new_cmd = ten::cmd_t::create_from_json(
// clang-format off
"{\
\"_ten\": {\
\"type\": \"cmd\",\
\"name\": \"test\"\
},\
\"test_data\": " TEN_XSTR(TEST_DATA) "\
}"
// clang-format on
);
hello_world_cmd = std::move(cmd);

auto new_cmd = ten::cmd_t::create("test");
new_cmd->set_property("test_data", TEST_DATA);

ten_env.send_cmd(
std::move(new_cmd), [this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd) {
Expand Down
20 changes: 7 additions & 13 deletions tests/ten_runtime/smoke/video_frame_test/create_from_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "gtest/gtest.h"
#include "include_internal/ten_runtime/binding/cpp/ten.h"
#include "ten_runtime/binding/cpp/internal/msg/video_frame.h"
#include "ten_runtime/msg/video_frame/video_frame.h"
#include "ten_utils/lib/thread.h"
#include "tests/common/client/cpp/msgpack_tcp.h"
Expand All @@ -26,19 +27,12 @@ class test_extension_1 : public ten::extension_t {
if (std::string(cmd->get_name()) == "hello_world") {
hello_world_cmd = std::move(cmd);

auto video_frame = ten::video_frame_t::create_from_json(
// clang-format off
R"({
"_ten": {
"name": "video_frame",
"width": 345,
"height": 567,
"pixel_fmt": 1,
"timestamp": 12341234
}
})"
// clang-format on
);
auto video_frame = ten::video_frame_t::create("video_frame");
video_frame->set_width(345);
video_frame->set_height(567);
video_frame->set_pixel_fmt(TEN_PIXEL_FMT_RGB24);
video_frame->set_timestamp(12341234);

ten_env.send_video_frame(std::move(video_frame));
} else if (std::string(cmd->get_name()) == "video_frame_ack") {
auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK);
Expand Down
Loading