Skip to content
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
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "phaser",
version = "3.0.1"
version = "3.1.0"
)

bazel_dep(name = "bazel_skylib", version = "1.9.0")
Expand Down
41 changes: 17 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,17 +494,14 @@ When the caller has the protobuf full name and not the C++ type, the bank
writes one payload:

```c++
status = ::phaser::PhaserBankProtobufToAvro(
"foo.bar.TestMessage", protobuf_bytes, &avro);
status = ::phaser::PhaserBankPhaserToParquet(
"foo.bar.TestMessage", phaser_bytes, &parquet);
status = ::phaser::PhaserBankConvert(
"foo.bar.TestMessage", ::phaser::BankInputType::kProtobuf, protobuf_bytes,
::phaser::BankOutputType::kAvro, &avro);
"foo.bar.TestMessage", "protobuf", protobuf_bytes, "avro", &avro);
status = ::phaser::PhaserBankConvert(
"foo.bar.TestMessage", "phaser", phaser_bytes, "parquet", &parquet);
```

`PhaserBankConvert` also accepts `BankOutputType::kParquet`, and
`BankInputType::kPhaser` for a native payload. See the user guide's
`PhaserBankConvert` takes the format names `"phaser"`, `"protobuf"`, `"avro"`,
and `"parquet"`. See the user guide's
[Avro and Parquet](phaser/docs/phaser_user_guide.md#avro-and-parquet) section
for the type mapping and file layout.

Expand All @@ -528,26 +525,22 @@ The same lookup converts wire formats when the caller has the protobuf full
name and not the C++ type:

```c++
absl::Status status = ::phaser::PhaserBankProtobufToROS(
"foo.bar.TestMessage", protobuf_bytes, ros_output);
status = ::phaser::PhaserBankRosToProtobuf(
"foo.bar.TestMessage", ros_bytes, protobuf_output);
status = ::phaser::PhaserBankPhaserToROS(
"foo.bar.TestMessage", phaser_bytes, ros_output);
status = ::phaser::PhaserBankPhaserToProtobuf(
"foo.bar.TestMessage", phaser_bytes, protobuf_output);

std::string converted;
absl::Status status = ::phaser::PhaserBankConvert(
"foo.bar.TestMessage", "protobuf", protobuf_bytes, "ros", &converted);
status = ::phaser::PhaserBankConvert(
"foo.bar.TestMessage", "ros", ros_bytes, "protobuf", &converted);
status = ::phaser::PhaserBankConvert(
"foo.bar.TestMessage", "phaser", phaser_bytes, "ros", &converted);
status = ::phaser::PhaserBankConvert(
"foo.bar.TestMessage", ::phaser::BankInputType::kProtobuf, protobuf_bytes,
::phaser::BankOutputType::kRos, &converted);
"foo.bar.TestMessage", "phaser", phaser_bytes, "protobuf", &converted);
```

`PhaserBankRosDataType`, `PhaserBankRosMd5`, and `PhaserBankRosDefinition`
return the ROS datatype, MD5, and definition when the message was compiled with
ROS metadata. `PhaserBankProtobufFullName` and `PhaserBankProtobufName` return
the protobuf names. The bank also dispatches the generated Arrow functions for
an `Any` payload. The user guide's
`CallMessageProperty` returns a named property of a message. The built-in names
are `"ros-datatype"`, `"ros-md5"`, `"ros-definition"`, `"protobuf-full-name"`,
and `"protobuf-name"`. The ROS properties are present when the message was
compiled with ROS metadata. An `Any` payload is read and written through the
Arrow plugin. The user guide's
[Phaser Bank](phaser/docs/phaser_user_guide.md#the-phaser-bank) and
[Message information](phaser/docs/phaser_user_guide.md#message-information)
sections cover reflection, `MessageInfo`/`FieldInfo`, and the rest of the
Expand Down
8 changes: 8 additions & 0 deletions phaser/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ cc_test(
copts = PHASER_COPTS + PHASER_PROTOBUF_GENERATED_COPTS,
data = ["valgrind.supp"],
deps = [
"//phaser/plugins:arrow",
"//phaser/plugins:avro",
"//phaser/plugins:avro_conversion",
"//phaser/plugins:parquet",
"//phaser/plugins:parquet_conversion",
"//phaser/runtime:phaser_runtime",
"//phaser/testdata:test_message_phaser",
"@com_google_googletest//:gtest_main",
Expand All @@ -55,6 +60,7 @@ cc_test(
copts = PHASER_COPTS + PHASER_PROTOBUF_GENERATED_COPTS,
data = ["valgrind.supp"],
deps = [
"//phaser/plugins:arrow",
"//phaser/runtime:phaser_runtime",
"//phaser/testdata:test_message_phaser",
"@com_google_googletest//:gtest_main",
Expand Down Expand Up @@ -256,6 +262,8 @@ cc_test(
deps = [
"//phaser/runtime:phaser_bank_protobuf",
"//phaser/runtime:phaser_runtime",
"//phaser/plugins:protobuf_conversion",
"//phaser/plugins:ros_conversion",
"//phaser/testdata:ros_compile_cc_proto",
"//phaser/testdata:ros_compile_phaser",
"//phaser/testdata:ros_intrinsics_phaser",
Expand Down
2 changes: 1 addition & 1 deletion phaser/arrow_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string>
#include <vector>

#include "phaser/runtime/arrow_abi.h"
#include "phaser/plugins/arrow/arrow_abi.h"
#include "phaser/testdata/TestMessage.phaser.h"

namespace {
Expand Down
131 changes: 116 additions & 15 deletions phaser/columnar_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "gtest/gtest.h"
#include "phaser/runtime/phaser_bank.h"
#include "phaser/plugins/avro/avro.h"
#include "phaser/plugins/parquet/parquet.h"
#include "phaser/testdata/TestMessage.phaser.h"

namespace {
Expand Down Expand Up @@ -51,11 +53,16 @@ TEST(ColumnarMessageTest, WireFormatsMatchTheMessage) {

std::string bank_protobuf;
std::string bank_phaser;
ASSERT_TRUE(phaser::PhaserBankProtobufToAvro(foo::bar::phaser::TestMessage::FullName(),
protobuf, &bank_protobuf)
ASSERT_TRUE(phaser::PhaserBankConvert(
foo::bar::phaser::TestMessage::FullName(),
phaser::kProtobufFormat,
absl::MakeConstSpan(protobuf.data(), protobuf.size()),
phaser::avro::kFormat, &bank_protobuf)
.ok());
ASSERT_TRUE(phaser::PhaserBankPhaserToAvro(foo::bar::phaser::TestMessage::FullName(),
payload, &bank_phaser)
ASSERT_TRUE(phaser::PhaserBankConvert(foo::bar::phaser::TestMessage::FullName(),
phaser::kPhaserFormat, payload,
phaser::avro::kFormat,
&bank_phaser)
.ok());
EXPECT_EQ(from_message, bank_protobuf);
EXPECT_EQ(from_message, bank_phaser);
Expand All @@ -77,9 +84,11 @@ TEST(ColumnarMessageTest, WireFormatsMatchTheMessage) {
EXPECT_NE(parquet_message.find("hello"), std::string::npos);

std::string bank_parquet;
ASSERT_TRUE(phaser::PhaserBankProtobufToParquet(
foo::bar::phaser::TestMessage::FullName(), protobuf,
&bank_parquet)
ASSERT_TRUE(phaser::PhaserBankConvert(
foo::bar::phaser::TestMessage::FullName(),
phaser::kProtobufFormat,
absl::MakeConstSpan(protobuf.data(), protobuf.size()),
phaser::parquet::kFormat, &bank_parquet)
.ok());
EXPECT_EQ(parquet_message, bank_parquet);

Expand Down Expand Up @@ -110,24 +119,116 @@ TEST(ColumnarMessageTest, WireFormatsMatchTheMessage) {

const std::string_view full_name = foo::bar::phaser::TestMessage::FullName();
std::string converted;
ASSERT_TRUE(phaser::PhaserBankConvert(full_name, phaser::BankInputType::kPhaser,
payload, phaser::BankOutputType::kAvro,
ASSERT_TRUE(phaser::PhaserBankConvert(full_name, phaser::kPhaserFormat,
payload, phaser::avro::kFormat,
&converted)
.ok());
EXPECT_EQ(from_phaser, converted);
ASSERT_TRUE(phaser::PhaserBankConvert(
full_name, phaser::BankInputType::kProtobuf,
full_name, phaser::kProtobufFormat,
absl::MakeConstSpan(protobuf.data(), protobuf.size()),
phaser::BankOutputType::kParquet, &converted)
phaser::parquet::kFormat, &converted)
.ok());
EXPECT_EQ(parquet_protobuf, converted);
EXPECT_FALSE(phaser::PhaserBankConvert(full_name, phaser::BankInputType::kRos,
payload, phaser::BankOutputType::kAvro,
EXPECT_FALSE(phaser::PhaserBankConvert(full_name, phaser::kRosFormat,
payload, phaser::avro::kFormat,
&converted)
.ok());
EXPECT_TRUE(converted.empty());
EXPECT_FALSE(phaser::PhaserBankConvert(full_name, phaser::BankInputType::kPhaser,
payload, phaser::BankOutputType::kAvro,
EXPECT_FALSE(phaser::PhaserBankConvert(full_name, phaser::kPhaserFormat,
payload, phaser::avro::kFormat,
nullptr)
.ok());
}

absl::Status WriteDirection(std::string_view full_name, absl::Span<const char> bytes,
std::string* out, const void* options,
std::string_view label) {
(void)full_name;
(void)bytes;
(void)options;
*out = std::string(label);
return absl::OkStatus();
}

absl::Status WriteForward(std::string_view full_name, absl::Span<const char> bytes,
std::string* out, const void* options) {
return WriteDirection(full_name, bytes, out, options, "forward");
}

absl::Status WriteReverse(std::string_view full_name, absl::Span<const char> bytes,
std::string* out, const void* options) {
return WriteDirection(full_name, bytes, out, options, "reverse");
}

TEST(ColumnarMessageTest, ConversionDirectionSelectsTheInstalledEdge) {
const char* const forward_formats[] = {"plugin-src", "plugin-dst"};
const phaser::BankConversion forward[] = {
{"plugin-src", "plugin-dst", phaser::BankConversionDirection::kForward,
WriteForward, nullptr},
};
ASSERT_TRUE(phaser::PhaserBankRegisterConversionPlugin(
{"direction-forward", forward_formats, forward})
.ok());
std::string out;
ASSERT_TRUE(phaser::PhaserBankConvert("unused", "plugin-src", {}, "plugin-dst",
&out)
.ok());
EXPECT_EQ(out, "forward");
EXPECT_FALSE(
phaser::PhaserBankConvert("unused", "plugin-dst", {}, "plugin-src", &out)
.ok());

const char* const reverse_formats[] = {"plugin-reverse-src",
"plugin-reverse-dst"};
const phaser::BankConversion reverse[] = {
{"plugin-reverse-src", "plugin-reverse-dst",
phaser::BankConversionDirection::kReverse, nullptr, WriteReverse},
};
ASSERT_TRUE(phaser::PhaserBankRegisterConversionPlugin(
{"direction-reverse", reverse_formats, reverse})
.ok());
ASSERT_TRUE(phaser::PhaserBankConvert("unused", "plugin-reverse-dst", {},
"plugin-reverse-src", &out)
.ok());
EXPECT_EQ(out, "reverse");
EXPECT_FALSE(phaser::PhaserBankConvert("unused", "plugin-reverse-src", {},
"plugin-reverse-dst", &out)
.ok());

const char* const both_formats[] = {"plugin-both-src", "plugin-both-dst"};
const phaser::BankConversion both[] = {
{"plugin-both-src", "plugin-both-dst", phaser::BankConversionDirection::kBoth,
WriteForward, WriteReverse},
};
ASSERT_TRUE(phaser::PhaserBankRegisterConversionPlugin(
{"direction-both", both_formats, both})
.ok());
ASSERT_TRUE(phaser::PhaserBankConvert("unused", "plugin-both-src", {},
"plugin-both-dst", &out)
.ok());
EXPECT_EQ(out, "forward");
ASSERT_TRUE(phaser::PhaserBankConvert("unused", "plugin-both-dst", {},
"plugin-both-src", &out)
.ok());
EXPECT_EQ(out, "reverse");

const char* const missing_formats[] = {"plugin-missing-src",
"plugin-missing-dst"};
const phaser::BankConversion missing[] = {
{"plugin-missing-src", "plugin-missing-dst",
phaser::BankConversionDirection::kBoth, WriteForward, nullptr},
};
EXPECT_FALSE(phaser::PhaserBankRegisterConversionPlugin(
{"direction-missing", missing_formats, missing})
.ok());

const char* const undeclared_formats[] = {"plugin-src"};
const phaser::BankConversion undeclared[] = {
{"plugin-src", "plugin-undeclared", phaser::BankConversionDirection::kForward,
WriteForward, nullptr},
};
EXPECT_FALSE(phaser::PhaserBankRegisterConversionPlugin(
{"direction-undeclared", undeclared_formats, undeclared})
.ok());
}
69 changes: 45 additions & 24 deletions phaser/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,63 @@ load("//phaser:copts.bzl", "PHASER_PROTOC_COPTS")

package(default_visibility = ["//visibility:public"])

_GENERATOR_SRCS = [
"enum_gen.cc",
"gen.cc",
"generator_plugin.cc",
"message_gen.cc",
"message_gen_c.cc",
"message_gen_python.cc",
]

_GENERATOR_HDRS = [
"enum_gen.h",
"gen.h",
"generator_plugin.h",
"message_codegen_host.h",
"message_gen.h",
]

_GENERATOR_DEPS = [
"//phaser:options_cc_proto",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_protobuf//:protoc_lib",
]

cc_library(
name = "phaser_lib",
srcs = [
"enum_gen.cc",
"gen.cc",
"message_gen.cc",
"message_gen_arrow.cc",
"message_gen_c.cc",
"message_gen_python.cc",
],
name = "message_generator",
srcs = _GENERATOR_SRCS,
copts = PHASER_PROTOC_COPTS,
hdrs = [
"enum_gen.h",
"gen.h",
"message_gen.h",
],
deps = [
"//phaser:options_cc_proto",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_protobuf//:protoc_lib",
hdrs = _GENERATOR_HDRS,
deps = _GENERATOR_DEPS + [
"//phaser/plugins/ros:ros_codegen_helpers",
],
)

# Backward-compatible alias for in-tree targets.
alias(
name = "phaser_lib",
actual = ":message_generator",
)

cc_binary(
name = "phaser",
srcs = [
"main.cc",
],
copts = PHASER_PROTOC_COPTS,
deps = [
":phaser_lib",
":message_generator",
"//phaser/plugins:arrow_codegen",
"//phaser/plugins:avro_codegen",
"//phaser/plugins:parquet_codegen",
"//phaser/plugins:protobuf_codegen",
"//phaser/plugins:ros_codegen",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_protobuf//:protoc_lib",
Expand Down
6 changes: 6 additions & 0 deletions phaser/compiler/gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See LICENSE file for licensing information.

#include "phaser/compiler/gen.h"
#include "phaser/compiler/generator_plugin.h"

#include <filesystem>
#include <fstream>
Expand Down Expand Up @@ -422,6 +423,7 @@ Generator::Generator(const google::protobuf::FileDescriptor* file,
void Generator::GenerateHeaders(std::ostream& os, std::string* error) {
os << "#pragma once\n";
os << "#include \"phaser/runtime/runtime.h\"\n";
EmitGeneratorPluginFileHeaderIncludes(os);
os << "#include <new>\n";
if (frontend_style_ == FrontendStyle::kRos && UsesRos1Intrinsic(file_)) {
os << "#include \"phaser/runtime/ros.h\"\n";
Expand Down Expand Up @@ -560,6 +562,10 @@ void Generator::GenerateSources(std::ostream& os) {
std::string(file_->name())));
p.replace_extension(".phaser.h");
os << "#include \"" << p.string() << "\"\n";
EmitGeneratorPluginFileSourceIncludes(os);
if (frontend_style_ == FrontendStyle::kRos && UsesRos1Intrinsic(file_)) {
os << "#include \"phaser/runtime/ros.h\"\n";
}
GenerateProtobufDescriptorRegistrations(os);

OpenNamespace(os);
Expand Down
Loading
Loading