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

feat: Add IPC integration test executable #585

Merged
merged 9 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ if(NANOARROW_IPC)
DESTINATION include/nanoarrow)
endif()

if(NANOARROW_IPC AND NANOARROW_BUILD_INTEGRATION_TESTS)
add_executable(nanoarrow_ipc_json_integration src/nanoarrow/ipc/json_integration.cc)
target_include_directories(nanoarrow_ipc_json_integration
PUBLIC $<BUILD_INTERFACE:${NANOARROW_BUILD_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_link_libraries(nanoarrow_ipc_json_integration PRIVATE nanoarrow_testing
nanoarrow_ipc flatccrt)
endif()

if(NANOARROW_DEVICE)
if(NANOARROW_DEVICE_WITH_METAL)
if(NOT EXISTS "${CMAKE_BINARY_DIR}/metal-cpp")
Expand Down Expand Up @@ -348,7 +358,8 @@ foreach(target
nanoarrow_ipc
nanoarrow_device
nanoarrow_testing
nanoarrow_c_data_integration)
nanoarrow_c_data_integration
nanoarrow_ipc_json_integration)
if(TARGET ${target})
target_compile_definitions(${target} PUBLIC "$<$<CONFIG:Debug>:NANOARROW_DEBUG>")

Expand Down
18 changes: 12 additions & 6 deletions src/nanoarrow/ipc/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct ArrowIpcEncoderPrivate {
flatcc_builder_t builder;
struct ArrowBuffer buffers;
struct ArrowBuffer nodes;
int encoding_footer;
};

ArrowErrorCode ArrowIpcEncoderInit(struct ArrowIpcEncoder* encoder) {
Expand All @@ -60,6 +61,7 @@ ArrowErrorCode ArrowIpcEncoderInit(struct ArrowIpcEncoder* encoder) {
ArrowFree(private);
return ESPIPE;
}
private->encoding_footer = 0;
ArrowBufferInit(&private->buffers);
ArrowBufferInit(&private->nodes);
return NANOARROW_OK;
Expand Down Expand Up @@ -412,10 +414,12 @@ ArrowErrorCode ArrowIpcEncoderEncodeSchema(struct ArrowIpcEncoder* encoder,

flatcc_builder_t* builder = &private->builder;

FLATCC_RETURN_UNLESS_0(Message_start_as_root(builder), error);
FLATCC_RETURN_UNLESS_0(Message_version_add(builder, ns(MetadataVersion_V5)), error);
if (!private->encoding_footer) {
FLATCC_RETURN_UNLESS_0(Message_start_as_root(builder), error);
FLATCC_RETURN_UNLESS_0(Message_version_add(builder, ns(MetadataVersion_V5)), error);

FLATCC_RETURN_UNLESS_0(Message_header_Schema_start(builder), error);
FLATCC_RETURN_UNLESS_0(Message_header_Schema_start(builder), error);
}

if (ArrowIpcSystemEndianness() == NANOARROW_IPC_ENDIANNESS_LITTLE) {
FLATCC_RETURN_UNLESS_0(Schema_endianness_add(builder, ns(Endianness_Little)), error);
Expand All @@ -440,10 +444,12 @@ ArrowErrorCode ArrowIpcEncoderEncodeSchema(struct ArrowIpcEncoder* encoder,
FLATCC_RETURN_UNLESS_0(Schema_features_start(builder), error);
FLATCC_RETURN_UNLESS_0(Schema_features_end(builder), error);

FLATCC_RETURN_UNLESS_0(Message_header_Schema_end(builder), error);
if (!private->encoding_footer) {
FLATCC_RETURN_UNLESS_0(Message_header_Schema_end(builder), error);

FLATCC_RETURN_UNLESS_0(Message_bodyLength_add(builder, 0), error);
FLATCC_RETURN_IF_NULL(ns(Message_end_as_root(builder)), error);
FLATCC_RETURN_UNLESS_0(Message_bodyLength_add(builder, 0), error);
FLATCC_RETURN_IF_NULL(ns(Message_end_as_root(builder)), error);
}
return NANOARROW_OK;
}

Expand Down
Loading
Loading