You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tsfile.apache.org by co...@apache.org on 2026/09/10 10:59:39 UTC

(tsfile) 05/17: fix(cpp): preserve pre-open codec configuration

This is an automated email from the ASF dual-hosted git repository.

ColinLeeo pushed a commit to branch feat/labview-bulk-io
in repository https://gitbox.apache.org/repos/asf/tsfile.git

commit 4287b0314ae2ed804160d201ecc163c1ba90f5a8
Author: ColinLee <sh...@163.com>
AuthorDate: Thu Sep 10 16:31:27 2026 +0800

    fix(cpp): preserve pre-open codec configuration
---
 cpp/src/cwrapper/tsfile_cwrapper.cc    |  4 +++
 cpp/src/labview_wrapper/CMakeLists.txt | 10 ++++++
 cpp/src/labview_wrapper/test_config.c  | 58 ++++++++++++++++++++++++++++++++++
 cpp/test/CMakeLists.txt                |  2 ++
 4 files changed, 74 insertions(+)

diff --git a/cpp/src/cwrapper/tsfile_cwrapper.cc b/cpp/src/cwrapper/tsfile_cwrapper.cc
index de17ba49b..a793228d6 100644
--- a/cpp/src/cwrapper/tsfile_cwrapper.cc
+++ b/cpp/src/cwrapper/tsfile_cwrapper.cc
@@ -78,18 +78,22 @@ uint8_t get_datatype_encoding(uint8_t data_type) {
 uint8_t get_global_compression() { return common::get_global_compression(); }
 
 int set_global_time_encoding(uint8_t encoding) {
+    init_tsfile_config();
     return common::set_global_time_encoding(encoding);
 }
 
 int set_global_time_compression(uint8_t compression) {
+    init_tsfile_config();
     return common::set_global_time_compression(compression);
 }
 
 int set_datatype_encoding(uint8_t data_type, uint8_t encoding) {
+    init_tsfile_config();
     return common::set_datatype_encoding(data_type, encoding);
 }
 
 int set_global_compression(uint8_t compression) {
+    init_tsfile_config();
     return common::set_global_compression(compression);
 }
 
diff --git a/cpp/src/labview_wrapper/CMakeLists.txt b/cpp/src/labview_wrapper/CMakeLists.txt
index f4074ab8c..f237daf69 100644
--- a/cpp/src/labview_wrapper/CMakeLists.txt
+++ b/cpp/src/labview_wrapper/CMakeLists.txt
@@ -53,4 +53,14 @@ if (BUILD_LABVIEW_WRAPPER_TESTS)
             C_STANDARD_REQUIRED ON
             RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH})
     endforeach()
+
+    add_executable(tsfile_labview_config_test test_config.c)
+    target_include_directories(tsfile_labview_config_test
+                               PRIVATE ${PROJECT_SRC_DIR})
+    target_link_libraries(tsfile_labview_config_test
+                          PRIVATE tsfile_labview tsfile)
+    set_target_properties(tsfile_labview_config_test PROPERTIES
+        C_STANDARD 99
+        C_STANDARD_REQUIRED ON
+        RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH})
 endif ()
diff --git a/cpp/src/labview_wrapper/test_config.c b/cpp/src/labview_wrapper/test_config.c
new file mode 100644
index 000000000..5abaaf0c8
--- /dev/null
+++ b/cpp/src/labview_wrapper/test_config.c
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdio.h>
+
+#include "cwrapper/tsfile_cwrapper.h"
+#include "tsfile_labview.h"
+
+#define CHECK(condition)                                           \
+    do {                                                           \
+        if (!(condition)) {                                        \
+            printf("FAIL: %s at line %d\n", #condition, __LINE__); \
+            return 1;                                              \
+        }                                                          \
+    } while (0)
+
+int main(void) {
+    const char* path = "lv_config_order.tsfile";
+    LV_Handle builder = 0;
+    LV_Handle writer = 0;
+
+    remove(path);
+    CHECK(lv_tsfile_set_datatype_encoding(LV_TYPE_DOUBLE, TS_ENCODING_PLAIN) ==
+          0);
+    CHECK(lv_tsfile_set_global_compression(TS_COMPRESSION_UNCOMPRESSED) == 0);
+    CHECK(get_datatype_encoding(TS_DATATYPE_DOUBLE) == TS_ENCODING_PLAIN);
+    CHECK(get_global_compression() == TS_COMPRESSION_UNCOMPRESSED);
+
+    builder = lv_tsfile_schema_builder_new("signals");
+    CHECK(builder != 0);
+    CHECK(lv_tsfile_schema_builder_add_column(builder, "value", LV_TYPE_DOUBLE,
+                                              LV_CAT_FIELD) == 0);
+    CHECK(lv_tsfile_writer_open(path, builder, 0, &writer) == 0);
+    CHECK(writer != 0);
+    CHECK(lv_tsfile_writer_close(writer) == 0);
+    lv_tsfile_schema_builder_free(builder);
+
+    CHECK(get_datatype_encoding(TS_DATATYPE_DOUBLE) == TS_ENCODING_PLAIN);
+    CHECK(get_global_compression() == TS_COMPRESSION_UNCOMPRESSED);
+    remove(path);
+    return 0;
+}
diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt
index 1a7c5c15e..6762e0b1a 100644
--- a/cpp/test/CMakeLists.txt
+++ b/cpp/test/CMakeLists.txt
@@ -365,4 +365,6 @@ if(TARGET tsfile_labview_smoke_test)
              COMMAND $<TARGET_FILE:tsfile_labview_dump_test>)
     add_test(NAME LabVIEWBlockTest
              COMMAND $<TARGET_FILE:tsfile_labview_block_test>)
+    add_test(NAME LabVIEWConfigTest
+             COMMAND $<TARGET_FILE:tsfile_labview_config_test>)
 endif()