From e49e9da797ec2313209ddf730f550757c58cf748 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 00:35:49 +0000 Subject: [PATCH 1/6] Initial plan From 40b63ac60924943daa823af0095b413ea72cbc1b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 00:41:36 +0000 Subject: [PATCH 2/6] Remove backup_unused_tests, frame_compat files, and old Win SDK compat Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> --- src/struct_frame/__init__.py | 2 - src/struct_frame/boilerplate/c/frame_compat.h | 217 ----------- .../boilerplate/cpp/frame_compat.hpp | 223 ----------- .../asio/detail/old_win_sdk_compat.hpp | 214 ---------- .../boilerplate/csharp/FrameCompat.cs | 366 ------------------ .../boilerplate/js/frame_compat.js | 342 ---------------- .../boilerplate/ts/frame_compat.ts | 343 ---------------- src/struct_frame/generate_boilerplate.py | 2 +- tests/backup_unused_tests/c/test_arrays.c | 129 ------ .../backup_unused_tests/c/test_basic_types.c | 115 ------ .../c/test_cross_platform_deserialization.c | 120 ------ .../c/test_cross_platform_serialization.c | 86 ---- tests/backup_unused_tests/cpp/test_arrays.cpp | 54 --- .../cpp/test_basic_types.cpp | 78 ---- .../test_cross_platform_deserialization.cpp | 112 ------ .../cpp/test_cross_platform_serialization.cpp | 56 --- tests/backup_unused_tests/js/test_arrays.js | 143 ------- .../js/test_basic_types.js | 77 ---- .../js/test_cross_platform_deserialization.js | 137 ------- .../js/test_cross_platform_serialization.js | 167 -------- tests/backup_unused_tests/py/test_arrays.py | 154 -------- .../py/test_basic_types.py | 145 ------- .../py/test_cross_platform_deserialization.py | 194 ---------- .../py/test_cross_platform_serialization.py | 116 ------ tests/backup_unused_tests/ts/test_arrays.ts | 137 ------- .../ts/test_basic_types.ts | 74 ---- .../ts/test_cross_platform_deserialization.ts | 131 ------- .../ts/test_cross_platform_serialization.ts | 161 -------- tests/c/frame_compat.h | 217 ----------- tests/cpp/frame_compat.hpp | 223 ----------- 30 files changed, 1 insertion(+), 4534 deletions(-) delete mode 100644 src/struct_frame/boilerplate/c/frame_compat.h delete mode 100644 src/struct_frame/boilerplate/cpp/frame_compat.hpp delete mode 100644 src/struct_frame/boilerplate/cpp/struct_frame_sdk/asio/detail/old_win_sdk_compat.hpp delete mode 100644 src/struct_frame/boilerplate/csharp/FrameCompat.cs delete mode 100644 src/struct_frame/boilerplate/js/frame_compat.js delete mode 100644 src/struct_frame/boilerplate/ts/frame_compat.ts delete mode 100644 tests/backup_unused_tests/c/test_arrays.c delete mode 100644 tests/backup_unused_tests/c/test_basic_types.c delete mode 100644 tests/backup_unused_tests/c/test_cross_platform_deserialization.c delete mode 100644 tests/backup_unused_tests/c/test_cross_platform_serialization.c delete mode 100644 tests/backup_unused_tests/cpp/test_arrays.cpp delete mode 100644 tests/backup_unused_tests/cpp/test_basic_types.cpp delete mode 100644 tests/backup_unused_tests/cpp/test_cross_platform_deserialization.cpp delete mode 100644 tests/backup_unused_tests/cpp/test_cross_platform_serialization.cpp delete mode 100644 tests/backup_unused_tests/js/test_arrays.js delete mode 100644 tests/backup_unused_tests/js/test_basic_types.js delete mode 100644 tests/backup_unused_tests/js/test_cross_platform_deserialization.js delete mode 100644 tests/backup_unused_tests/js/test_cross_platform_serialization.js delete mode 100644 tests/backup_unused_tests/py/test_arrays.py delete mode 100644 tests/backup_unused_tests/py/test_basic_types.py delete mode 100644 tests/backup_unused_tests/py/test_cross_platform_deserialization.py delete mode 100644 tests/backup_unused_tests/py/test_cross_platform_serialization.py delete mode 100644 tests/backup_unused_tests/ts/test_arrays.ts delete mode 100644 tests/backup_unused_tests/ts/test_basic_types.ts delete mode 100644 tests/backup_unused_tests/ts/test_cross_platform_deserialization.ts delete mode 100644 tests/backup_unused_tests/ts/test_cross_platform_serialization.ts delete mode 100644 tests/c/frame_compat.h delete mode 100644 tests/cpp/frame_compat.hpp diff --git a/src/struct_frame/__init__.py b/src/struct_frame/__init__.py index e8383004..6e86a4c3 100644 --- a/src/struct_frame/__init__.py +++ b/src/struct_frame/__init__.py @@ -12,7 +12,6 @@ HeaderType, PayloadType, HeaderDefinition, PayloadDefinition, FrameFormatCollection, parse_frame_formats ) -from .parser_py_gen import generate_py_parser, ParserPyGen from .generate import main from .generate_boilerplate import ( @@ -26,6 +25,5 @@ "NamingStyleC", "CamelToSnakeCase", "pascalCase", "HeaderType", "PayloadType", "HeaderDefinition", "PayloadDefinition", "FrameFormatCollection", "parse_frame_formats", - "generate_py_parser", "ParserPyGen", "generate_boilerplate_to_paths", "update_src_boilerplate", "get_default_frame_formats_path", "get_boilerplate_dir"] diff --git a/src/struct_frame/boilerplate/c/frame_compat.h b/src/struct_frame/boilerplate/c/frame_compat.h deleted file mode 100644 index 3cba478a..00000000 --- a/src/struct_frame/boilerplate/c/frame_compat.h +++ /dev/null @@ -1,217 +0,0 @@ -/** - * Compatibility layer for frame parser functions - * Provides encode/decode functions composed from separated header and payload types - */ - -#pragma once - -#include "frame_base.h" -#include "frame_headers/base.h" -#include "frame_headers/header_tiny.h" -#include "frame_headers/header_basic.h" -#include "payload_types/base.h" -#include "payload_types/payload_default.h" -#include "payload_types/payload_minimal.h" -#include "payload_types/payload_extended.h" -#include "payload_types/payload_extended_multi_system_stream.h" - -/* Basic + Default */ -static inline size_t basic_default_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 4; /* [0x90] [0x71] [LEN] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 255) { - return 0; - } - - buffer[0] = BASIC_START_BYTE; - buffer[1] = get_basic_second_start_byte(PAYLOAD_DEFAULT_CONFIG.payload_type); - buffer[2] = (uint8_t)msg_size; - buffer[3] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - frame_checksum_t ck = frame_fletcher_checksum(buffer + 2, msg_size + 2); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -static inline frame_msg_info_t basic_default_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 6 || buffer[0] != BASIC_START_BYTE || - !is_basic_second_start_byte(buffer[1])) { - return result; - } - - return frame_validate_payload_with_crc(buffer, length, 4, 1, 2); -} - -/* Tiny + Minimal */ -static inline size_t tiny_minimal_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 2; /* [0x70] [MSG_ID] */ - const size_t total_size = header_size + msg_size; - - if (buffer_size < total_size) { - return 0; - } - - buffer[0] = get_tiny_start_byte(PAYLOAD_MINIMAL_CONFIG.payload_type); - buffer[1] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - return total_size; -} - -static inline frame_msg_info_t tiny_minimal_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 2 || !is_tiny_start_byte(buffer[0])) { - return result; - } - - return frame_validate_payload_minimal(buffer, length, 2); -} - -/* Basic + Extended */ -static inline size_t basic_extended_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 6; /* [0x90] [0x74] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 65535) { - return 0; - } - - buffer[0] = BASIC_START_BYTE; - buffer[1] = get_basic_second_start_byte(PAYLOAD_EXTENDED_CONFIG.payload_type); - buffer[2] = (uint8_t)(msg_size & 0xFF); - buffer[3] = (uint8_t)((msg_size >> 8) & 0xFF); - buffer[4] = 0; /* PKG_ID = 0 */ - buffer[5] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - frame_checksum_t ck = frame_fletcher_checksum(buffer + 2, msg_size + 4); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -static inline frame_msg_info_t basic_extended_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 8 || buffer[0] != BASIC_START_BYTE || - !is_basic_second_start_byte(buffer[1])) { - return result; - } - - return frame_validate_payload_with_crc(buffer, length, 6, 2, 2); -} - -/* Basic + Extended Multi System Stream */ -static inline size_t basic_extended_multi_system_stream_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 9; /* [0x90] [0x78] [SEQ] [SYS] [COMP] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 65535) { - return 0; - } - - buffer[0] = BASIC_START_BYTE; - buffer[1] = get_basic_second_start_byte(PAYLOAD_EXTENDED_MULTI_SYSTEM_STREAM_CONFIG.payload_type); - buffer[2] = 0; /* SEQ = 0 */ - buffer[3] = 0; /* SYS_ID = 0 */ - buffer[4] = 0; /* COMP_ID = 0 */ - buffer[5] = (uint8_t)(msg_size & 0xFF); - buffer[6] = (uint8_t)((msg_size >> 8) & 0xFF); - buffer[7] = 0; /* PKG_ID = 0 */ - buffer[8] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - frame_checksum_t ck = frame_fletcher_checksum(buffer + 2, msg_size + 7); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -static inline frame_msg_info_t basic_extended_multi_system_stream_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 11 || buffer[0] != BASIC_START_BYTE || - !is_basic_second_start_byte(buffer[1])) { - return result; - } - - return frame_validate_payload_with_crc(buffer, length, 9, 2, 2); -} - -/* Basic + Minimal */ -static inline size_t basic_minimal_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 3; /* [0x90] [0x70] [MSG_ID] */ - const size_t total_size = header_size + msg_size; - - if (buffer_size < total_size) { - return 0; - } - - buffer[0] = BASIC_START_BYTE; - buffer[1] = get_basic_second_start_byte(PAYLOAD_MINIMAL_CONFIG.payload_type); - buffer[2] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - return total_size; -} - -static inline frame_msg_info_t basic_minimal_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 3 || buffer[0] != BASIC_START_BYTE || - !is_basic_second_start_byte(buffer[1])) { - return result; - } - - return frame_validate_payload_minimal(buffer, length, 3); -} - -/* Tiny + Default */ -static inline size_t tiny_default_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 3; /* [0x71] [LEN] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 255) { - return 0; - } - - buffer[0] = get_tiny_start_byte(PAYLOAD_DEFAULT_CONFIG.payload_type); - buffer[1] = (uint8_t)msg_size; - buffer[2] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - frame_checksum_t ck = frame_fletcher_checksum(buffer + 1, msg_size + 2); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -static inline frame_msg_info_t tiny_default_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 5 || !is_tiny_start_byte(buffer[0])) { - return result; - } - - return frame_validate_payload_with_crc(buffer, length, 3, 1, 1); -} diff --git a/src/struct_frame/boilerplate/cpp/frame_compat.hpp b/src/struct_frame/boilerplate/cpp/frame_compat.hpp deleted file mode 100644 index df74970d..00000000 --- a/src/struct_frame/boilerplate/cpp/frame_compat.hpp +++ /dev/null @@ -1,223 +0,0 @@ -/** - * Compatibility layer for frame parser functions (C++) - * Provides encode/decode functions composed from separated header and payload types - */ - -#pragma once - -#include "frame_base.hpp" -#include "frame_headers/base.hpp" -#include "frame_headers/header_tiny.hpp" -#include "frame_headers/header_basic.hpp" -#include "payload_types/base.hpp" -#include "payload_types/payload_default.hpp" -#include "payload_types/payload_minimal.hpp" -#include "payload_types/payload_extended.hpp" -#include "payload_types/payload_extended_multi_system_stream.hpp" - -#include - -namespace FrameParsers { - -/* Basic + Default */ -inline size_t basic_default_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 4; /* [0x90] [0x71] [LEN] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 255) { - return 0; - } - - buffer[0] = FrameHeaders::BASIC_START_BYTE; - buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_DEFAULT_CONFIG.payload_type)); - buffer[2] = static_cast(msg_size); - buffer[3] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - FrameChecksum ck = fletcher_checksum(buffer + 2, msg_size + 2); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -inline FrameMsgInfo basic_default_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 6 || buffer[0] != FrameHeaders::BASIC_START_BYTE || - !FrameHeaders::is_basic_second_start_byte(buffer[1])) { - return result; - } - - return validate_payload_with_crc(buffer, length, 4, 1, 2); -} - -/* Tiny + Minimal */ -inline size_t tiny_minimal_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 2; /* [0x70] [MSG_ID] */ - const size_t total_size = header_size + msg_size; - - if (buffer_size < total_size) { - return 0; - } - - buffer[0] = FrameHeaders::get_tiny_start_byte(static_cast(PayloadTypes::PAYLOAD_MINIMAL_CONFIG.payload_type)); - buffer[1] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - return total_size; -} - -inline FrameMsgInfo tiny_minimal_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 2 || !FrameHeaders::is_tiny_start_byte(buffer[0])) { - return result; - } - - return validate_payload_minimal(buffer, length, 2); -} - -/* Basic + Extended */ -inline size_t basic_extended_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 6; /* [0x90] [0x74] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 65535) { - return 0; - } - - buffer[0] = FrameHeaders::BASIC_START_BYTE; - buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_EXTENDED_CONFIG.payload_type)); - buffer[2] = static_cast(msg_size & 0xFF); - buffer[3] = static_cast((msg_size >> 8) & 0xFF); - buffer[4] = 0; /* PKG_ID = 0 */ - buffer[5] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - FrameChecksum ck = fletcher_checksum(buffer + 2, msg_size + 4); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -inline FrameMsgInfo basic_extended_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 8 || buffer[0] != FrameHeaders::BASIC_START_BYTE || - !FrameHeaders::is_basic_second_start_byte(buffer[1])) { - return result; - } - - return validate_payload_with_crc(buffer, length, 6, 2, 2); -} - -/* Basic + Extended Multi System Stream */ -inline size_t basic_extended_multi_system_stream_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 9; /* [0x90] [0x78] [SEQ] [SYS] [COMP] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 65535) { - return 0; - } - - buffer[0] = FrameHeaders::BASIC_START_BYTE; - buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_EXTENDED_MULTI_SYSTEM_STREAM_CONFIG.payload_type)); - buffer[2] = 0; /* SEQ = 0 */ - buffer[3] = 0; /* SYS_ID = 0 */ - buffer[4] = 0; /* COMP_ID = 0 */ - buffer[5] = static_cast(msg_size & 0xFF); - buffer[6] = static_cast((msg_size >> 8) & 0xFF); - buffer[7] = 0; /* PKG_ID = 0 */ - buffer[8] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - FrameChecksum ck = fletcher_checksum(buffer + 2, msg_size + 7); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -inline FrameMsgInfo basic_extended_multi_system_stream_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 11 || buffer[0] != FrameHeaders::BASIC_START_BYTE || - !FrameHeaders::is_basic_second_start_byte(buffer[1])) { - return result; - } - - return validate_payload_with_crc(buffer, length, 9, 2, 2); -} - -/* Basic + Minimal */ -inline size_t basic_minimal_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 3; /* [0x90] [0x70] [MSG_ID] */ - const size_t total_size = header_size + msg_size; - - if (buffer_size < total_size) { - return 0; - } - - buffer[0] = FrameHeaders::BASIC_START_BYTE; - buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_MINIMAL_CONFIG.payload_type)); - buffer[2] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - return total_size; -} - -inline FrameMsgInfo basic_minimal_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 3 || buffer[0] != FrameHeaders::BASIC_START_BYTE || - !FrameHeaders::is_basic_second_start_byte(buffer[1])) { - return result; - } - - return validate_payload_minimal(buffer, length, 3); -} - -/* Tiny + Default */ -inline size_t tiny_default_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 3; /* [0x71] [LEN] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 255) { - return 0; - } - - buffer[0] = FrameHeaders::get_tiny_start_byte(static_cast(PayloadTypes::PAYLOAD_DEFAULT_CONFIG.payload_type)); - buffer[1] = static_cast(msg_size); - buffer[2] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - FrameChecksum ck = fletcher_checksum(buffer + 1, msg_size + 2); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -inline FrameMsgInfo tiny_default_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 5 || !FrameHeaders::is_tiny_start_byte(buffer[0])) { - return result; - } - - return validate_payload_with_crc(buffer, length, 3, 1, 1); -} - -} // namespace FrameParsers diff --git a/src/struct_frame/boilerplate/cpp/struct_frame_sdk/asio/detail/old_win_sdk_compat.hpp b/src/struct_frame/boilerplate/cpp/struct_frame_sdk/asio/detail/old_win_sdk_compat.hpp deleted file mode 100644 index 2c43c1da..00000000 --- a/src/struct_frame/boilerplate/cpp/struct_frame_sdk/asio/detail/old_win_sdk_compat.hpp +++ /dev/null @@ -1,214 +0,0 @@ -// -// detail/old_win_sdk_compat.hpp -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// -// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// - -#ifndef ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP -#define ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP - -#if defined(_MSC_VER) && (_MSC_VER >= 1200) -# pragma once -#endif // defined(_MSC_VER) && (_MSC_VER >= 1200) - -#include "asio/detail/config.hpp" - -#if defined(ASIO_WINDOWS) || defined(__CYGWIN__) - -// Guess whether we are building against on old Platform SDK. -#if !defined(IN6ADDR_ANY_INIT) -#define ASIO_HAS_OLD_WIN_SDK 1 -#endif // !defined(IN6ADDR_ANY_INIT) - -#if defined(ASIO_HAS_OLD_WIN_SDK) - -// Emulation of types that are missing from old Platform SDKs. -// -// N.B. this emulation is also used if building for a Windows 2000 target with -// a recent (i.e. Vista or later) SDK, as the SDK does not provide IPv6 support -// in that case. - -#include "asio/detail/push_options.hpp" - -namespace asio { -namespace detail { - -enum -{ - sockaddr_storage_maxsize = 128, // Maximum size. - sockaddr_storage_alignsize = (sizeof(__int64)), // Desired alignment. - sockaddr_storage_pad1size = (sockaddr_storage_alignsize - sizeof(short)), - sockaddr_storage_pad2size = (sockaddr_storage_maxsize - - (sizeof(short) + sockaddr_storage_pad1size + sockaddr_storage_alignsize)) -}; - -struct sockaddr_storage_emulation -{ - short ss_family; - char __ss_pad1[sockaddr_storage_pad1size]; - __int64 __ss_align; - char __ss_pad2[sockaddr_storage_pad2size]; -}; - -struct in6_addr_emulation -{ - union - { - u_char Byte[16]; - u_short Word[8]; - } u; -}; - -#if !defined(s6_addr) -# define _S6_un u -# define _S6_u8 Byte -# define s6_addr _S6_un._S6_u8 -#endif // !defined(s6_addr) - -struct sockaddr_in6_emulation -{ - short sin6_family; - u_short sin6_port; - u_long sin6_flowinfo; - in6_addr_emulation sin6_addr; - u_long sin6_scope_id; -}; - -struct ipv6_mreq_emulation -{ - in6_addr_emulation ipv6mr_multiaddr; - unsigned int ipv6mr_interface; -}; - -struct addrinfo_emulation -{ - int ai_flags; - int ai_family; - int ai_socktype; - int ai_protocol; - size_t ai_addrlen; - char* ai_canonname; - sockaddr* ai_addr; - addrinfo_emulation* ai_next; -}; - -#if !defined(AI_PASSIVE) -# define AI_PASSIVE 0x1 -#endif - -#if !defined(AI_CANONNAME) -# define AI_CANONNAME 0x2 -#endif - -#if !defined(AI_NUMERICHOST) -# define AI_NUMERICHOST 0x4 -#endif - -#if !defined(EAI_AGAIN) -# define EAI_AGAIN WSATRY_AGAIN -#endif - -#if !defined(EAI_BADFLAGS) -# define EAI_BADFLAGS WSAEINVAL -#endif - -#if !defined(EAI_FAIL) -# define EAI_FAIL WSANO_RECOVERY -#endif - -#if !defined(EAI_FAMILY) -# define EAI_FAMILY WSAEAFNOSUPPORT -#endif - -#if !defined(EAI_MEMORY) -# define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY -#endif - -#if !defined(EAI_NODATA) -# define EAI_NODATA WSANO_DATA -#endif - -#if !defined(EAI_NONAME) -# define EAI_NONAME WSAHOST_NOT_FOUND -#endif - -#if !defined(EAI_SERVICE) -# define EAI_SERVICE WSATYPE_NOT_FOUND -#endif - -#if !defined(EAI_SOCKTYPE) -# define EAI_SOCKTYPE WSAESOCKTNOSUPPORT -#endif - -#if !defined(NI_NOFQDN) -# define NI_NOFQDN 0x01 -#endif - -#if !defined(NI_NUMERICHOST) -# define NI_NUMERICHOST 0x02 -#endif - -#if !defined(NI_NAMEREQD) -# define NI_NAMEREQD 0x04 -#endif - -#if !defined(NI_NUMERICSERV) -# define NI_NUMERICSERV 0x08 -#endif - -#if !defined(NI_DGRAM) -# define NI_DGRAM 0x10 -#endif - -#if !defined(IPPROTO_IPV6) -# define IPPROTO_IPV6 41 -#endif - -#if !defined(IPV6_UNICAST_HOPS) -# define IPV6_UNICAST_HOPS 4 -#endif - -#if !defined(IPV6_MULTICAST_IF) -# define IPV6_MULTICAST_IF 9 -#endif - -#if !defined(IPV6_MULTICAST_HOPS) -# define IPV6_MULTICAST_HOPS 10 -#endif - -#if !defined(IPV6_MULTICAST_LOOP) -# define IPV6_MULTICAST_LOOP 11 -#endif - -#if !defined(IPV6_JOIN_GROUP) -# define IPV6_JOIN_GROUP 12 -#endif - -#if !defined(IPV6_LEAVE_GROUP) -# define IPV6_LEAVE_GROUP 13 -#endif - -} // namespace detail -} // namespace asio - -#include "asio/detail/pop_options.hpp" - -#endif // defined(ASIO_HAS_OLD_WIN_SDK) - -// Even newer Platform SDKs that support IPv6 may not define IPV6_V6ONLY. -#if !defined(IPV6_V6ONLY) -# define IPV6_V6ONLY 27 -#endif - -// Some SDKs (e.g. Windows CE) don't define IPPROTO_ICMPV6. -#if !defined(IPPROTO_ICMPV6) -# define IPPROTO_ICMPV6 58 -#endif - -#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__) - -#endif // ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP diff --git a/src/struct_frame/boilerplate/csharp/FrameCompat.cs b/src/struct_frame/boilerplate/csharp/FrameCompat.cs deleted file mode 100644 index da5953c5..00000000 --- a/src/struct_frame/boilerplate/csharp/FrameCompat.cs +++ /dev/null @@ -1,366 +0,0 @@ -// Compatibility layer for frame parser functions (C#) -// Provides encode/decode functions composed from separated header and payload types - -using System; -using StructFrame.FrameHeaders; -using StructFrame.PayloadTypes; - -namespace StructFrame -{ - /// - /// Base class for frame formats using compositional approach - /// - public abstract class FrameCompat : FrameFormatBase - { - protected static (byte, byte) Fletcher16Checksum(byte[] buffer, int start, int length) - { - byte byte1 = 0; - byte byte2 = 0; - - for (int i = start; i < start + length; i++) - { - byte1 = (byte)((byte1 + buffer[i]) % 256); - byte2 = (byte)((byte2 + byte1) % 256); - } - - return (byte1, byte2); - } - } - - public class BasicDefault : FrameCompat - { - public override byte[] Encode(int msgId, byte[] msg) - { - int headerSize = 4; - int footerSize = 2; - int totalSize = headerSize + msg.Length + footerSize; - - if (msg.Length > 255) - return null; - - byte[] buffer = new byte[totalSize]; - buffer[0] = HeaderConstants.BASIC_START_BYTE; - buffer[1] = HeaderBasic.GetSecondStartByte(1); // DEFAULT = 1 - buffer[2] = (byte)msg.Length; - buffer[3] = (byte)msgId; - Array.Copy(msg, 0, buffer, headerSize, msg.Length); - - var ck = Fletcher16Checksum(buffer, 2, msg.Length + 2); - buffer[totalSize - 2] = ck.Item1; - buffer[totalSize - 1] = ck.Item2; - - return buffer; - } - - public override FrameParseResult ValidatePacket(byte[] buffer, int length) - { - if (length < 6 || buffer[0] != HeaderConstants.BASIC_START_BYTE || - !HeaderBasic.IsSecondStartByte(buffer[1])) - { - return new FrameParseResult { Valid = false }; - } - - int msgLen = buffer[2]; - byte msgId = buffer[3]; - int totalSize = 4 + msgLen + 2; - - if (length < totalSize) - return new FrameParseResult { Valid = false }; - - var ck = Fletcher16Checksum(buffer, 2, msgLen + 2); - if (ck.Item1 == buffer[totalSize - 2] && ck.Item2 == buffer[totalSize - 1]) - { - byte[] msgData = new byte[msgLen]; - Array.Copy(buffer, 4, msgData, 0, msgLen); - return new FrameParseResult { Valid = true, MsgId = msgId, MsgSize = msgLen, MsgData = msgData }; - } - - return new FrameParseResult { Valid = false }; - } - - public override FrameParseResult ParseByte(byte b) - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - - public override void Reset() - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - } - - public class TinyMinimal : FrameCompat - { - public override byte[] Encode(int msgId, byte[] msg) - { - int headerSize = 2; - int totalSize = headerSize + msg.Length; - - byte[] buffer = new byte[totalSize]; - buffer[0] = HeaderTiny.GetStartByte(0); // MINIMAL = 0 - buffer[1] = (byte)msgId; - Array.Copy(msg, 0, buffer, headerSize, msg.Length); - - return buffer; - } - - public override FrameParseResult ValidatePacket(byte[] buffer, int length) - { - if (length < 2 || !HeaderTiny.IsStartByte(buffer[0])) - { - return new FrameParseResult { Valid = false }; - } - - byte msgId = buffer[1]; - int msgLen = length - 2; - - byte[] msgData = new byte[msgLen]; - Array.Copy(buffer, 2, msgData, 0, msgLen); - return new FrameParseResult { Valid = true, MsgId = msgId, MsgSize = msgLen, MsgData = msgData }; - } - - public override FrameParseResult ParseByte(byte b) - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - - public override void Reset() - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - } - - public class BasicExtended : FrameCompat - { - public override byte[] Encode(int msgId, byte[] msg) - { - int headerSize = 6; - int footerSize = 2; - int totalSize = headerSize + msg.Length + footerSize; - - if (msg.Length > 65535) - return null; - - byte[] buffer = new byte[totalSize]; - buffer[0] = HeaderConstants.BASIC_START_BYTE; - buffer[1] = HeaderBasic.GetSecondStartByte(4); // EXTENDED = 4 - buffer[2] = (byte)(msg.Length & 0xFF); - buffer[3] = (byte)((msg.Length >> 8) & 0xFF); - buffer[4] = 0; // PKG_ID = 0 - buffer[5] = (byte)msgId; - Array.Copy(msg, 0, buffer, headerSize, msg.Length); - - var ck = Fletcher16Checksum(buffer, 2, msg.Length + 4); - buffer[totalSize - 2] = ck.Item1; - buffer[totalSize - 1] = ck.Item2; - - return buffer; - } - - public override FrameParseResult ValidatePacket(byte[] buffer, int length) - { - if (length < 8 || buffer[0] != HeaderConstants.BASIC_START_BYTE || - !HeaderBasic.IsSecondStartByte(buffer[1])) - { - return new FrameParseResult { Valid = false }; - } - - int msgLen = buffer[2] | (buffer[3] << 8); - byte msgId = buffer[5]; - int totalSize = 6 + msgLen + 2; - - if (length < totalSize) - return new FrameParseResult { Valid = false }; - - var ck = Fletcher16Checksum(buffer, 2, msgLen + 4); - if (ck.Item1 == buffer[totalSize - 2] && ck.Item2 == buffer[totalSize - 1]) - { - byte[] msgData = new byte[msgLen]; - Array.Copy(buffer, 6, msgData, 0, msgLen); - return new FrameParseResult { Valid = true, MsgId = msgId, MsgSize = msgLen, MsgData = msgData }; - } - - return new FrameParseResult { Valid = false }; - } - - public override FrameParseResult ParseByte(byte b) - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - - public override void Reset() - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - } - - public class BasicExtendedMultiSystemStream : FrameCompat - { - public override byte[] Encode(int msgId, byte[] msg) - { - int headerSize = 9; - int footerSize = 2; - int totalSize = headerSize + msg.Length + footerSize; - - if (msg.Length > 65535) - return null; - - byte[] buffer = new byte[totalSize]; - buffer[0] = HeaderConstants.BASIC_START_BYTE; - buffer[1] = HeaderBasic.GetSecondStartByte(8); // EXTENDED_MULTI_SYSTEM_STREAM = 8 - buffer[2] = 0; // SEQ = 0 - buffer[3] = 0; // SYS_ID = 0 - buffer[4] = 0; // COMP_ID = 0 - buffer[5] = (byte)(msg.Length & 0xFF); - buffer[6] = (byte)((msg.Length >> 8) & 0xFF); - buffer[7] = 0; // PKG_ID = 0 - buffer[8] = (byte)msgId; - Array.Copy(msg, 0, buffer, headerSize, msg.Length); - - var ck = Fletcher16Checksum(buffer, 2, msg.Length + 7); - buffer[totalSize - 2] = ck.Item1; - buffer[totalSize - 1] = ck.Item2; - - return buffer; - } - - public override FrameParseResult ValidatePacket(byte[] buffer, int length) - { - if (length < 11 || buffer[0] != HeaderConstants.BASIC_START_BYTE || - !HeaderBasic.IsSecondStartByte(buffer[1])) - { - return new FrameParseResult { Valid = false }; - } - - int msgLen = buffer[5] | (buffer[6] << 8); - byte msgId = buffer[8]; - int totalSize = 9 + msgLen + 2; - - if (length < totalSize) - return new FrameParseResult { Valid = false }; - - var ck = Fletcher16Checksum(buffer, 2, msgLen + 7); - if (ck.Item1 == buffer[totalSize - 2] && ck.Item2 == buffer[totalSize - 1]) - { - byte[] msgData = new byte[msgLen]; - Array.Copy(buffer, 9, msgData, 0, msgLen); - return new FrameParseResult { Valid = true, MsgId = msgId, MsgSize = msgLen, MsgData = msgData }; - } - - return new FrameParseResult { Valid = false }; - } - - public override FrameParseResult ParseByte(byte b) - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - - public override void Reset() - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - } - - public class BasicMinimal : FrameCompat - { - public override byte[] Encode(int msgId, byte[] msg) - { - int headerSize = 3; - int totalSize = headerSize + msg.Length; - - byte[] buffer = new byte[totalSize]; - buffer[0] = HeaderConstants.BASIC_START_BYTE; - buffer[1] = HeaderBasic.GetSecondStartByte(0); // MINIMAL = 0 - buffer[2] = (byte)msgId; - Array.Copy(msg, 0, buffer, headerSize, msg.Length); - - return buffer; - } - - public override FrameParseResult ValidatePacket(byte[] buffer, int length) - { - if (length < 3 || buffer[0] != HeaderConstants.BASIC_START_BYTE || - !HeaderBasic.IsSecondStartByte(buffer[1])) - { - return new FrameParseResult { Valid = false }; - } - - byte msgId = buffer[2]; - int msgLen = length - 3; - - byte[] msgData = new byte[msgLen]; - Array.Copy(buffer, 3, msgData, 0, msgLen); - return new FrameParseResult { Valid = true, MsgId = msgId, MsgSize = msgLen, MsgData = msgData }; - } - - public override FrameParseResult ParseByte(byte b) - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - - public override void Reset() - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - } - - public class TinyDefault : FrameCompat - { - public override byte[] Encode(int msgId, byte[] msg) - { - int headerSize = 3; - int footerSize = 2; - int totalSize = headerSize + msg.Length + footerSize; - - if (msg.Length > 255) - return null; - - byte[] buffer = new byte[totalSize]; - buffer[0] = HeaderTiny.GetStartByte(1); // DEFAULT = 1 - buffer[1] = (byte)msg.Length; - buffer[2] = (byte)msgId; - Array.Copy(msg, 0, buffer, headerSize, msg.Length); - - var ck = Fletcher16Checksum(buffer, 1, msg.Length + 2); - buffer[totalSize - 2] = ck.Item1; - buffer[totalSize - 1] = ck.Item2; - - return buffer; - } - - public override FrameParseResult ValidatePacket(byte[] buffer, int length) - { - if (length < 5 || !HeaderTiny.IsStartByte(buffer[0])) - { - return new FrameParseResult { Valid = false }; - } - - int msgLen = buffer[1]; - byte msgId = buffer[2]; - int totalSize = 3 + msgLen + 2; - - if (length < totalSize) - return new FrameParseResult { Valid = false }; - - var ck = Fletcher16Checksum(buffer, 1, msgLen + 2); - if (ck.Item1 == buffer[totalSize - 2] && ck.Item2 == buffer[totalSize - 1]) - { - byte[] msgData = new byte[msgLen]; - Array.Copy(buffer, 3, msgData, 0, msgLen); - return new FrameParseResult { Valid = true, MsgId = msgId, MsgSize = msgLen, MsgData = msgData }; - } - - return new FrameParseResult { Valid = false }; - } - - public override FrameParseResult ParseByte(byte b) - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - - public override void Reset() - { - throw new NotImplementedException("Streaming parser not implemented for compat layer"); - } - } -} diff --git a/src/struct_frame/boilerplate/js/frame_compat.js b/src/struct_frame/boilerplate/js/frame_compat.js deleted file mode 100644 index 7be06951..00000000 --- a/src/struct_frame/boilerplate/js/frame_compat.js +++ /dev/null @@ -1,342 +0,0 @@ -/** - * Compatibility layer for frame parser functions (JavaScript) - * Provides encode/decode functions composed from separated header and payload types - */ - -const { BASIC_START_BYTE } = require('./frame_headers/base'); -const { getTinyStartByte, isTinyStartByte } = require('./frame_headers/header_tiny'); -const { getBasicSecondStartByte, isBasicSecondStartByte } = require('./frame_headers/header_basic'); -const { fletcher_checksum } = require('./frame_base'); - -/* Basic + Default */ -function basic_default_encode(msgId, msg) { - const headerSize = 4; - const footerSize = 2; - const totalSize = headerSize + msg.length + footerSize; - - if (msg.length > 255) { - return new Uint8Array(0); - } - - const buffer = new Uint8Array(totalSize); - buffer[0] = BASIC_START_BYTE; - buffer[1] = getBasicSecondStartByte(1); - buffer[2] = msg.length; - buffer[3] = msgId; - buffer.set(msg, headerSize); - - const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); - buffer[totalSize - 2] = ck[0]; - buffer[totalSize - 1] = ck[1]; - - return buffer; -} - -function basic_default_validate_packet(buffer) { - if ( - buffer.length < 6 || - buffer[0] !== BASIC_START_BYTE || - !isBasicSecondStartByte(buffer[1]) - ) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgLen = buffer[2]; - const msgId = buffer[3]; - const totalSize = 4 + msgLen + 2; - - if (buffer.length < totalSize) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const ck = fletcher_checksum(buffer, 2, 4 + msgLen); - if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(4, 4 + msgLen), - }; - } - - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; -} - -/* Tiny + Minimal */ -function tiny_minimal_encode(msgId, msg) { - const headerSize = 2; - const totalSize = headerSize + msg.length; - - const buffer = new Uint8Array(totalSize); - buffer[0] = getTinyStartByte(0); - buffer[1] = msgId; - buffer.set(msg, headerSize); - - return buffer; -} - -function tiny_minimal_validate_packet(buffer) { - if (buffer.length < 2 || !isTinyStartByte(buffer[0])) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgId = buffer[1]; - const msgLen = buffer.length - 2; - - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(2), - }; -} - -/* Basic + Extended */ -function basic_extended_encode(msgId, msg) { - const headerSize = 6; - const footerSize = 2; - const totalSize = headerSize + msg.length + footerSize; - - if (msg.length > 65535) { - return new Uint8Array(0); - } - - const buffer = new Uint8Array(totalSize); - buffer[0] = BASIC_START_BYTE; - buffer[1] = getBasicSecondStartByte(4); - buffer[2] = msg.length & 0xff; - buffer[3] = (msg.length >> 8) & 0xff; - buffer[4] = 0; - buffer[5] = msgId; - buffer.set(msg, headerSize); - - const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); - buffer[totalSize - 2] = ck[0]; - buffer[totalSize - 1] = ck[1]; - - return buffer; -} - -function basic_extended_validate_packet(buffer) { - if ( - buffer.length < 8 || - buffer[0] !== BASIC_START_BYTE || - !isBasicSecondStartByte(buffer[1]) - ) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgLen = buffer[2] | (buffer[3] << 8); - const msgId = buffer[5]; - const totalSize = 6 + msgLen + 2; - - if (buffer.length < totalSize) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const ck = fletcher_checksum(buffer, 2, 6 + msgLen); - if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(6, 6 + msgLen), - }; - } - - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; -} - -/* Basic + Extended Multi System Stream */ -function basic_extended_multi_system_stream_encode(msgId, msg) { - const headerSize = 9; - const footerSize = 2; - const totalSize = headerSize + msg.length + footerSize; - - if (msg.length > 65535) { - return new Uint8Array(0); - } - - const buffer = new Uint8Array(totalSize); - buffer[0] = BASIC_START_BYTE; - buffer[1] = getBasicSecondStartByte(8); - buffer[2] = 0; - buffer[3] = 0; - buffer[4] = 0; - buffer[5] = msg.length & 0xff; - buffer[6] = (msg.length >> 8) & 0xff; - buffer[7] = 0; - buffer[8] = msgId; - buffer.set(msg, headerSize); - - const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); - buffer[totalSize - 2] = ck[0]; - buffer[totalSize - 1] = ck[1]; - - return buffer; -} - -function basic_extended_multi_system_stream_validate_packet(buffer) { - if ( - buffer.length < 11 || - buffer[0] !== BASIC_START_BYTE || - !isBasicSecondStartByte(buffer[1]) - ) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgLen = buffer[5] | (buffer[6] << 8); - const msgId = buffer[8]; - const totalSize = 9 + msgLen + 2; - - if (buffer.length < totalSize) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const ck = fletcher_checksum(buffer, 2, 9 + msgLen); - if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(9, 9 + msgLen), - }; - } - - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; -} - -/* Basic + Minimal */ -function basic_minimal_encode(msgId, msg) { - const headerSize = 3; - const totalSize = headerSize + msg.length; - - const buffer = new Uint8Array(totalSize); - buffer[0] = BASIC_START_BYTE; - buffer[1] = getBasicSecondStartByte(0); - buffer[2] = msgId; - buffer.set(msg, headerSize); - - return buffer; -} - -function basic_minimal_validate_packet(buffer) { - if ( - buffer.length < 3 || - buffer[0] !== BASIC_START_BYTE || - !isBasicSecondStartByte(buffer[1]) - ) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgId = buffer[2]; - const msgLen = buffer.length - 3; - - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(3), - }; -} - -/* Tiny + Default */ -function tiny_default_encode(msgId, msg) { - const headerSize = 3; - const footerSize = 2; - const totalSize = headerSize + msg.length + footerSize; - - if (msg.length > 255) { - return new Uint8Array(0); - } - - const buffer = new Uint8Array(totalSize); - buffer[0] = getTinyStartByte(1); - buffer[1] = msg.length; - buffer[2] = msgId; - buffer.set(msg, headerSize); - - const ck = fletcher_checksum(buffer, 1, headerSize + msg.length); - buffer[totalSize - 2] = ck[0]; - buffer[totalSize - 1] = ck[1]; - - return buffer; -} - -function tiny_default_validate_packet(buffer) { - if (buffer.length < 5 || !isTinyStartByte(buffer[0])) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgLen = buffer[1]; - const msgId = buffer[2]; - const totalSize = 3 + msgLen + 2; - - if (buffer.length < totalSize) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const ck = fletcher_checksum(buffer, 1, 3 + msgLen); - if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(3, 3 + msgLen), - }; - } - - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; -} - -// Export wrapper classes for backward compatibility -const BasicDefault = { - encode: basic_default_encode, - validate_packet: basic_default_validate_packet, -}; - -const TinyMinimal = { - encode: tiny_minimal_encode, - validate_packet: tiny_minimal_validate_packet, -}; - -const BasicExtended = { - encode: basic_extended_encode, - validate_packet: basic_extended_validate_packet, -}; - -const BasicExtendedMultiSystemStream = { - encode: basic_extended_multi_system_stream_encode, - validate_packet: basic_extended_multi_system_stream_validate_packet, -}; - -const BasicMinimal = { - encode: basic_minimal_encode, - validate_packet: basic_minimal_validate_packet, -}; - -const TinyDefault = { - encode: tiny_default_encode, - validate_packet: tiny_default_validate_packet, -}; - -module.exports = { - basic_default_encode, - basic_default_validate_packet, - tiny_minimal_encode, - tiny_minimal_validate_packet, - basic_extended_encode, - basic_extended_validate_packet, - basic_extended_multi_system_stream_encode, - basic_extended_multi_system_stream_validate_packet, - basic_minimal_encode, - basic_minimal_validate_packet, - tiny_default_encode, - tiny_default_validate_packet, - BasicDefault, - TinyMinimal, - BasicExtended, - BasicExtendedMultiSystemStream, - BasicMinimal, - TinyDefault, -}; diff --git a/src/struct_frame/boilerplate/ts/frame_compat.ts b/src/struct_frame/boilerplate/ts/frame_compat.ts deleted file mode 100644 index ec66c70e..00000000 --- a/src/struct_frame/boilerplate/ts/frame_compat.ts +++ /dev/null @@ -1,343 +0,0 @@ -/** - * Compatibility layer for frame parser functions (TypeScript) - * Provides encode/decode functions composed from separated header and payload types - */ - -import { BASIC_START_BYTE } from './frame_headers/base'; -import { getTinyStartByte, isTinyStartByte } from './frame_headers/header_tiny'; -import { getBasicSecondStartByte, isBasicSecondStartByte } from './frame_headers/header_basic'; -import { fletcher_checksum, FrameMsgInfo } from './frame_base'; - -/* Basic + Default */ -export function basic_default_encode( - msgId: number, - msg: Uint8Array -): Uint8Array { - const headerSize = 4; /* [0x90] [0x71] [LEN] [MSG_ID] */ - const footerSize = 2; /* [CRC1] [CRC2] */ - const totalSize = headerSize + msg.length + footerSize; - - if (msg.length > 255) { - return new Uint8Array(0); - } - - const buffer = new Uint8Array(totalSize); - buffer[0] = BASIC_START_BYTE; - buffer[1] = getBasicSecondStartByte(1); // PayloadType.DEFAULT = 1 - buffer[2] = msg.length; - buffer[3] = msgId; - buffer.set(msg, headerSize); - - const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); - buffer[totalSize - 2] = ck[0]; - buffer[totalSize - 1] = ck[1]; - - return buffer; -} - -export function basic_default_validate_packet( - buffer: Uint8Array -): FrameMsgInfo { - if ( - buffer.length < 6 || - buffer[0] !== BASIC_START_BYTE || - !isBasicSecondStartByte(buffer[1]) - ) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgLen = buffer[2]; - const msgId = buffer[3]; - const totalSize = 4 + msgLen + 2; - - if (buffer.length < totalSize) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const ck = fletcher_checksum(buffer, 2, 4 + msgLen); - if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(4, 4 + msgLen), - }; - } - - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; -} - -/* Tiny + Minimal */ -export function tiny_minimal_encode( - msgId: number, - msg: Uint8Array -): Uint8Array { - const headerSize = 2; /* [0x70] [MSG_ID] */ - const totalSize = headerSize + msg.length; - - const buffer = new Uint8Array(totalSize); - buffer[0] = getTinyStartByte(0); // PayloadType.MINIMAL = 0 - buffer[1] = msgId; - buffer.set(msg, headerSize); - - return buffer; -} - -export function tiny_minimal_validate_packet(buffer: Uint8Array): FrameMsgInfo { - if (buffer.length < 2 || !isTinyStartByte(buffer[0])) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgId = buffer[1]; - const msgLen = buffer.length - 2; - - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(2), - }; -} - -/* Basic + Extended */ -export function basic_extended_encode( - msgId: number, - msg: Uint8Array -): Uint8Array { - const headerSize = 6; /* [0x90] [0x74] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const footerSize = 2; /* [CRC1] [CRC2] */ - const totalSize = headerSize + msg.length + footerSize; - - if (msg.length > 65535) { - return new Uint8Array(0); - } - - const buffer = new Uint8Array(totalSize); - buffer[0] = BASIC_START_BYTE; - buffer[1] = getBasicSecondStartByte(4); // PayloadType.EXTENDED = 4 - buffer[2] = msg.length & 0xff; - buffer[3] = (msg.length >> 8) & 0xff; - buffer[4] = 0; // PKG_ID = 0 - buffer[5] = msgId; - buffer.set(msg, headerSize); - - const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); - buffer[totalSize - 2] = ck[0]; - buffer[totalSize - 1] = ck[1]; - - return buffer; -} - -export function basic_extended_validate_packet(buffer: Uint8Array): FrameMsgInfo { - if ( - buffer.length < 8 || - buffer[0] !== BASIC_START_BYTE || - !isBasicSecondStartByte(buffer[1]) - ) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgLen = buffer[2] | (buffer[3] << 8); - const msgId = buffer[5]; - const totalSize = 6 + msgLen + 2; - - if (buffer.length < totalSize) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const ck = fletcher_checksum(buffer, 2, 6 + msgLen); - if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(6, 6 + msgLen), - }; - } - - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; -} - -/* Basic + Extended Multi System Stream */ -export function basic_extended_multi_system_stream_encode( - msgId: number, - msg: Uint8Array -): Uint8Array { - const headerSize = 9; /* [0x90] [0x78] [SEQ] [SYS] [COMP] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const footerSize = 2; /* [CRC1] [CRC2] */ - const totalSize = headerSize + msg.length + footerSize; - - if (msg.length > 65535) { - return new Uint8Array(0); - } - - const buffer = new Uint8Array(totalSize); - buffer[0] = BASIC_START_BYTE; - buffer[1] = getBasicSecondStartByte(8); // PayloadType.EXTENDED_MULTI_SYSTEM_STREAM = 8 - buffer[2] = 0; // SEQ = 0 - buffer[3] = 0; // SYS_ID = 0 - buffer[4] = 0; // COMP_ID = 0 - buffer[5] = msg.length & 0xff; - buffer[6] = (msg.length >> 8) & 0xff; - buffer[7] = 0; // PKG_ID = 0 - buffer[8] = msgId; - buffer.set(msg, headerSize); - - const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); - buffer[totalSize - 2] = ck[0]; - buffer[totalSize - 1] = ck[1]; - - return buffer; -} - -export function basic_extended_multi_system_stream_validate_packet( - buffer: Uint8Array -): FrameMsgInfo { - if ( - buffer.length < 11 || - buffer[0] !== BASIC_START_BYTE || - !isBasicSecondStartByte(buffer[1]) - ) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgLen = buffer[5] | (buffer[6] << 8); - const msgId = buffer[8]; - const totalSize = 9 + msgLen + 2; - - if (buffer.length < totalSize) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const ck = fletcher_checksum(buffer, 2, 9 + msgLen); - if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(9, 9 + msgLen), - }; - } - - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; -} - -/* Basic + Minimal */ -export function basic_minimal_encode( - msgId: number, - msg: Uint8Array -): Uint8Array { - const headerSize = 3; /* [0x90] [0x70] [MSG_ID] */ - const totalSize = headerSize + msg.length; - - const buffer = new Uint8Array(totalSize); - buffer[0] = BASIC_START_BYTE; - buffer[1] = getBasicSecondStartByte(0); // PayloadType.MINIMAL = 0 - buffer[2] = msgId; - buffer.set(msg, headerSize); - - return buffer; -} - -export function basic_minimal_validate_packet(buffer: Uint8Array): FrameMsgInfo { - if ( - buffer.length < 3 || - buffer[0] !== BASIC_START_BYTE || - !isBasicSecondStartByte(buffer[1]) - ) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgId = buffer[2]; - const msgLen = buffer.length - 3; - - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(3), - }; -} - -/* Tiny + Default */ -export function tiny_default_encode( - msgId: number, - msg: Uint8Array -): Uint8Array { - const headerSize = 3; /* [0x71] [LEN] [MSG_ID] */ - const footerSize = 2; /* [CRC1] [CRC2] */ - const totalSize = headerSize + msg.length + footerSize; - - if (msg.length > 255) { - return new Uint8Array(0); - } - - const buffer = new Uint8Array(totalSize); - buffer[0] = getTinyStartByte(1); // PayloadType.DEFAULT = 1 - buffer[1] = msg.length; - buffer[2] = msgId; - buffer.set(msg, headerSize); - - const ck = fletcher_checksum(buffer, 1, headerSize + msg.length); - buffer[totalSize - 2] = ck[0]; - buffer[totalSize - 1] = ck[1]; - - return buffer; -} - -export function tiny_default_validate_packet(buffer: Uint8Array): FrameMsgInfo { - if (buffer.length < 5 || !isTinyStartByte(buffer[0])) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const msgLen = buffer[1]; - const msgId = buffer[2]; - const totalSize = 3 + msgLen + 2; - - if (buffer.length < totalSize) { - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; - } - - const ck = fletcher_checksum(buffer, 1, 3 + msgLen); - if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { - return { - valid: true, - msg_id: msgId, - msg_len: msgLen, - msg_data: buffer.slice(3, 3 + msgLen), - }; - } - - return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; -} - -// Create wrapper classes for backward compatibility -export class BasicDefault { - static encodeMsg = basic_default_encode; - static validatePacket = basic_default_validate_packet; -} - -export class TinyMinimal { - static encodeMsg = tiny_minimal_encode; - static validatePacket = tiny_minimal_validate_packet; -} - -export class BasicExtended { - static encodeMsg = basic_extended_encode; - static validatePacket = basic_extended_validate_packet; -} - -export class BasicExtendedMultiSystemStream { - static encodeMsg = basic_extended_multi_system_stream_encode; - static validatePacket = basic_extended_multi_system_stream_validate_packet; -} - -export class BasicMinimal { - static encodeMsg = basic_minimal_encode; - static validatePacket = basic_minimal_validate_packet; -} - -export class TinyDefault { - static encodeMsg = tiny_default_encode; - static validatePacket = tiny_default_validate_packet; -} diff --git a/src/struct_frame/generate_boilerplate.py b/src/struct_frame/generate_boilerplate.py index 769a0149..dae48f5d 100644 --- a/src/struct_frame/generate_boilerplate.py +++ b/src/struct_frame/generate_boilerplate.py @@ -26,7 +26,7 @@ sys.path.insert(0, parent_dir) from struct_frame.frame_format import parse_frame_formats -from struct_frame.parser_py_gen import generate_py_parser +from struct_frame.frame_parser_py_gen import generate_py_frame_parsers def get_default_frame_formats_path(): diff --git a/tests/backup_unused_tests/c/test_arrays.c b/tests/backup_unused_tests/c/test_arrays.c deleted file mode 100644 index 38cb95a2..00000000 --- a/tests/backup_unused_tests/c/test_arrays.c +++ /dev/null @@ -1,129 +0,0 @@ -#include -#include -#include - -#include "comprehensive_arrays.sf.h" -#include "frame_parsers.h" - -void print_failure_details(const char* label, const void* raw_data, size_t raw_data_size) { - printf("\n"); - printf("============================================================\n"); - printf("FAILURE DETAILS: %s\n", label); - printf("============================================================\n"); - - if (raw_data && raw_data_size > 0) { - printf("\nRaw Data (%zu bytes):\n Hex: ", raw_data_size); - for (size_t i = 0; i < raw_data_size && i < 64; i++) { - printf("%02x", ((const uint8_t*)raw_data)[i]); - } - if (raw_data_size > 64) printf("..."); - printf("\n"); - } - - printf("============================================================\n\n"); -} - -int test_array_operations() { - ComprehensiveArraysComprehensiveArrayMessage msg = {0}; - - msg.fixed_ints[0] = 1; - msg.fixed_ints[1] = 2; - msg.fixed_ints[2] = 3; - - msg.fixed_floats[0] = 1.1f; - msg.fixed_floats[1] = 2.2f; - - msg.fixed_bools[0] = true; - msg.fixed_bools[1] = false; - msg.fixed_bools[2] = true; - msg.fixed_bools[3] = false; - - msg.bounded_uints.count = 3; - msg.bounded_uints.data[0] = 100; - msg.bounded_uints.data[1] = 200; - msg.bounded_uints.data[2] = 300; - - msg.bounded_doubles.count = 2; - msg.bounded_doubles.data[0] = 123.456; - msg.bounded_doubles.data[1] = 789.012; - - strncpy(msg.fixed_strings[0], "String1", sizeof(msg.fixed_strings[0])); - strncpy(msg.fixed_strings[1], "String2", sizeof(msg.fixed_strings[1])); - - msg.bounded_strings.count = 2; - strncpy(msg.bounded_strings.data[0], "BoundedStr1", sizeof(msg.bounded_strings.data[0])); - strncpy(msg.bounded_strings.data[1], "BoundedStr2", sizeof(msg.bounded_strings.data[1])); - - msg.fixed_statuses[0] = 1; - msg.fixed_statuses[1] = 2; - - msg.bounded_statuses.count = 2; - msg.bounded_statuses.data[0] = 1; - msg.bounded_statuses.data[1] = 3; - - msg.fixed_sensors[0].id = 1; - msg.fixed_sensors[0].value = 25.5; - msg.fixed_sensors[0].status = 1; - strncpy(msg.fixed_sensors[0].name, "Temp1", 16); - - msg.bounded_sensors.count = 1; - msg.bounded_sensors.data[0].id = 3; - msg.bounded_sensors.data[0].value = 15.5; - msg.bounded_sensors.data[0].status = 2; - strncpy(msg.bounded_sensors.data[0].name, "Pressure", 16); - - // Encode message into BasicDefault format - uint8_t encode_buffer[1024]; - size_t encoded_size = basic_default_encode(encode_buffer, sizeof(encode_buffer), - COMPREHENSIVE_ARRAYS_COMPREHENSIVE_ARRAY_MESSAGE_MSG_ID, - (const uint8_t*)&msg, COMPREHENSIVE_ARRAYS_COMPREHENSIVE_ARRAY_MESSAGE_MAX_SIZE); - - if (encoded_size == 0) { - print_failure_details("Encoding failed", NULL, 0); - return 0; - } - - // Validate and decode the BasicDefault frame - frame_msg_info_t decode_result = basic_default_validate_packet(encode_buffer, encoded_size); - if (!decode_result.valid) { - print_failure_details("Validation failed", encode_buffer, encoded_size); - return 0; - } - - ComprehensiveArraysComprehensiveArrayMessage* decoded_msg = - (ComprehensiveArraysComprehensiveArrayMessage*)decode_result.msg_data; - - // Compare original and decoded messages - if (decoded_msg->fixed_ints[0] != msg.fixed_ints[0]) { - print_failure_details("Value mismatch: fixed_ints[0]", encode_buffer, encoded_size); - return 0; - } - - if (decoded_msg->bounded_uints.count != msg.bounded_uints.count) { - print_failure_details("Value mismatch: bounded_uints.count", encode_buffer, encoded_size); - return 0; - } - - if (decoded_msg->bounded_uints.data[0] != msg.bounded_uints.data[0]) { - print_failure_details("Value mismatch: bounded_uints.data[0]", encode_buffer, encoded_size); - return 0; - } - - if (decoded_msg->fixed_sensors[0].id != msg.fixed_sensors[0].id) { - print_failure_details("Value mismatch: fixed_sensors[0].id", encode_buffer, encoded_size); - return 0; - } - - return 1; -} - -int main() { - printf("\n[TEST START] C Array Operations\n"); - - int success = test_array_operations(); - - const char* status = success ? "PASS" : "FAIL"; - printf("[TEST END] C Array Operations: %s\n\n", status); - - return success ? 0 : 1; -} diff --git a/tests/backup_unused_tests/c/test_basic_types.c b/tests/backup_unused_tests/c/test_basic_types.c deleted file mode 100644 index f77f629b..00000000 --- a/tests/backup_unused_tests/c/test_basic_types.c +++ /dev/null @@ -1,115 +0,0 @@ -#include -#include -#include - -#include "basic_types.sf.h" -#include "frame_parsers.h" - -void print_failure_details(const char* label, const BasicTypesBasicTypesMessage* expected, - const BasicTypesBasicTypesMessage* actual, - const uint8_t* raw_data, size_t raw_data_size) { - printf("\n"); - printf("============================================================\n"); - printf("FAILURE DETAILS: %s\n", label); - printf("============================================================\n"); - - if (expected && actual) { - printf("\nExpected Values:\n"); - printf(" small_int: %d\n", expected->small_int); - printf(" medium_int: %d\n", expected->medium_int); - printf(" regular_int: %d\n", expected->regular_int); - printf(" large_int: %lld\n", (long long)expected->large_int); - printf(" flag: %s\n", expected->flag ? "true" : "false"); - - printf("\nActual Values:\n"); - printf(" small_int: %d\n", actual->small_int); - printf(" medium_int: %d\n", actual->medium_int); - printf(" regular_int: %d\n", actual->regular_int); - printf(" large_int: %lld\n", (long long)actual->large_int); - printf(" flag: %s\n", actual->flag ? "true" : "false"); - } - - if (raw_data && raw_data_size > 0) { - printf("\nRaw Data (%zu bytes):\n Hex: ", raw_data_size); - for (size_t i = 0; i < raw_data_size && i < 64; i++) { - printf("%02x", raw_data[i]); - } - if (raw_data_size > 64) printf("..."); - printf("\n"); - } - - printf("============================================================\n\n"); -} - -int test_basic_types() { - BasicTypesBasicTypesMessage msg = {0}; - - msg.small_int = -42; - msg.medium_int = -1000; - msg.regular_int = -100000; - msg.large_int = -1000000000LL; - msg.small_uint = 255; - msg.medium_uint = 65535; - msg.regular_uint = 4294967295U; - msg.large_uint = 18446744073709551615ULL; - msg.single_precision = 3.14159f; - msg.double_precision = 2.718281828459045; - msg.flag = true; - strncpy(msg.device_id, "TEST_DEVICE_12345678901234567890", 32); - msg.description.length = strlen("Test description for basic types"); - strncpy(msg.description.data, "Test description for basic types", msg.description.length); - - // Encode message into BasicDefault format - uint8_t encode_buffer[1024]; - size_t encoded_size = basic_default_encode(encode_buffer, sizeof(encode_buffer), - BASIC_TYPES_BASIC_TYPES_MESSAGE_MSG_ID, - (const uint8_t*)&msg, BASIC_TYPES_BASIC_TYPES_MESSAGE_MAX_SIZE); - - if (encoded_size == 0) { - print_failure_details("Encoding failed", &msg, NULL, NULL, 0); - return 0; - } - - // Validate and decode the BasicDefault frame - frame_msg_info_t decode_result = basic_default_validate_packet(encode_buffer, encoded_size); - if (!decode_result.valid) { - print_failure_details("Validation failed", &msg, NULL, encode_buffer, encoded_size); - return 0; - } - - BasicTypesBasicTypesMessage* decoded_msg = (BasicTypesBasicTypesMessage*)decode_result.msg_data; - - // Compare original and decoded messages - if (decoded_msg->small_int != msg.small_int) { - print_failure_details("Value mismatch: small_int", &msg, decoded_msg, encode_buffer, encoded_size); - return 0; - } - - if (decoded_msg->medium_int != msg.medium_int) { - print_failure_details("Value mismatch: medium_int", &msg, decoded_msg, encode_buffer, encoded_size); - return 0; - } - - if (decoded_msg->flag != msg.flag) { - print_failure_details("Value mismatch: flag", &msg, decoded_msg, encode_buffer, encoded_size); - return 0; - } - - if (decoded_msg->single_precision != msg.single_precision) { - print_failure_details("Value mismatch: single_precision", &msg, decoded_msg, encode_buffer, encoded_size); - return 0; - } - - return 1; -} - -int main() { - printf("\n[TEST START] C Basic Types\n"); - - int success = test_basic_types(); - - const char* status = success ? "PASS" : "FAIL"; - printf("[TEST END] C Basic Types: %s\n\n", status); - - return success ? 0 : 1; -} diff --git a/tests/backup_unused_tests/c/test_cross_platform_deserialization.c b/tests/backup_unused_tests/c/test_cross_platform_deserialization.c deleted file mode 100644 index 3e5eee93..00000000 --- a/tests/backup_unused_tests/c/test_cross_platform_deserialization.c +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#include - -#include "serialization_test.sf.h" -#include "frame_parsers.h" - -void print_failure_details(const char* label, const void* raw_data, size_t raw_data_size) { - printf("\n"); - printf("============================================================\n"); - printf("FAILURE DETAILS: %s\n", label); - printf("============================================================\n"); - - if (raw_data && raw_data_size > 0) { - printf("\nRaw Data (%zu bytes):\n Hex: ", raw_data_size); - for (size_t i = 0; i < raw_data_size && i < 64; i++) { - printf("%02x", ((const uint8_t*)raw_data)[i]); - } - if (raw_data_size > 64) printf("..."); - printf("\n"); - } - - printf("============================================================\n\n"); -} - -int validate_message(SerializationTestSerializationTestMessage* msg) { - // Expected values from expected_values.json - uint32_t expected_magic = 3735928559; // 0xDEADBEEF - const char* expected_string = "Cross-platform test!"; - float expected_float = 3.14159f; - bool expected_bool = true; - int expected_array[3] = {100, 200, 300}; - - if (msg->magic_number != expected_magic) { - printf(" Value mismatch: magic_number (expected %u, got %u)\n", expected_magic, msg->magic_number); - return 0; - } - - if (strncmp(msg->test_string.data, expected_string, msg->test_string.length) != 0) { - printf(" Value mismatch: test_string\n"); - return 0; - } - - if (fabs(msg->test_float - expected_float) > 0.0001f) { - printf(" Value mismatch: test_float (expected %f, got %f)\n", expected_float, msg->test_float); - return 0; - } - - if (msg->test_bool != expected_bool) { - printf(" Value mismatch: test_bool\n"); - return 0; - } - - if (msg->test_array.count != 3) { - printf(" Value mismatch: test_array.count (expected 3, got %u)\n", msg->test_array.count); - return 0; - } - - for (int i = 0; i < 3; i++) { - if (msg->test_array.data[i] != expected_array[i]) { - printf(" Value mismatch: test_array[%d] (expected %d, got %d)\n", i, expected_array[i], msg->test_array.data[i]); - return 0; - } - } - - return 1; -} - -int read_and_validate_test_data(const char* filename) { - FILE* file = fopen(filename, "rb"); - if (!file) { - printf(" Error: file not found: %s\n", filename); - return 0; - } - - uint8_t buffer[512]; - size_t size = fread(buffer, 1, sizeof(buffer), file); - fclose(file); - - if (size == 0) { - print_failure_details("Empty file", buffer, size); - return 0; - } - - frame_msg_info_t decode_result = basic_default_validate_packet(buffer, size); - - if (!decode_result.valid) { - print_failure_details("Failed to decode data", buffer, size); - return 0; - } - - SerializationTestSerializationTestMessage* decoded_msg = - (SerializationTestSerializationTestMessage*)decode_result.msg_data; - - if (!validate_message(decoded_msg)) { - printf(" Validation failed\n"); - return 0; - } - - printf(" [OK] Data validated successfully\n"); - return 1; -} - -int main(int argc, char* argv[]) { - printf("\n[TEST START] C Cross-Platform Deserialization\n"); - - if (argc != 2) { - printf(" Usage: %s \n", argv[0]); - printf("[TEST END] C Cross-Platform Deserialization: FAIL\n\n"); - return 1; - } - - int success = read_and_validate_test_data(argv[1]); - - const char* status = success ? "PASS" : "FAIL"; - printf("[TEST END] C Cross-Platform Deserialization: %s\n\n", status); - - return success ? 0 : 1; -} diff --git a/tests/backup_unused_tests/c/test_cross_platform_serialization.c b/tests/backup_unused_tests/c/test_cross_platform_serialization.c deleted file mode 100644 index e9e25f43..00000000 --- a/tests/backup_unused_tests/c/test_cross_platform_serialization.c +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include -#include - -#include "serialization_test.sf.h" -#include "frame_parsers.h" - -void print_failure_details(const char* label, const void* raw_data, size_t raw_data_size) { - printf("\n"); - printf("============================================================\n"); - printf("FAILURE DETAILS: %s\n", label); - printf("============================================================\n"); - - if (raw_data && raw_data_size > 0) { - printf("\nRaw Data (%zu bytes):\n Hex: ", raw_data_size); - for (size_t i = 0; i < raw_data_size && i < 64; i++) { - printf("%02x", ((const uint8_t*)raw_data)[i]); - } - if (raw_data_size > 64) printf("..."); - printf("\n"); - } - - printf("============================================================\n\n"); -} - -int create_test_data() { - SerializationTestSerializationTestMessage msg = {0}; - - // Use values from expected_values.json - msg.magic_number = 3735928559; // 0xDEADBEEF - msg.test_string.length = strlen("Cross-platform test!"); - strncpy(msg.test_string.data, "Cross-platform test!", msg.test_string.length); - msg.test_float = 3.14159f; - msg.test_bool = true; - msg.test_array.count = 3; - msg.test_array.data[0] = 100; - msg.test_array.data[1] = 200; - msg.test_array.data[2] = 300; - - uint8_t encode_buffer[512]; - size_t encoded_size = basic_default_encode(encode_buffer, sizeof(encode_buffer), - SERIALIZATION_TEST_SERIALIZATION_TEST_MESSAGE_MSG_ID, - (const uint8_t*)&msg, SERIALIZATION_TEST_SERIALIZATION_TEST_MESSAGE_MAX_SIZE); - - if (encoded_size == 0) { - print_failure_details("Encoding failed", NULL, 0); - return 0; - } - - FILE* file = fopen("c_test_data.bin", "wb"); - if (!file) { - print_failure_details("File creation failed", NULL, 0); - return 0; - } - - fwrite(encode_buffer, 1, encoded_size, file); - fclose(file); - - // Self-validate - frame_msg_info_t decode_result = basic_default_validate_packet(encode_buffer, encoded_size); - if (!decode_result.valid) { - print_failure_details("Self-validation failed", encode_buffer, encoded_size); - return 0; - } - - SerializationTestSerializationTestMessage* decoded_msg = - (SerializationTestSerializationTestMessage*)decode_result.msg_data; - - if (decoded_msg->magic_number != 3735928559 || decoded_msg->test_array.count != 3) { - print_failure_details("Self-verification failed", encode_buffer, encoded_size); - return 0; - } - - return 1; -} - -int main() { - printf("\n[TEST START] C Cross-Platform Serialization\n"); - - int success = create_test_data(); - - const char* status = success ? "PASS" : "FAIL"; - printf("[TEST END] C Cross-Platform Serialization: %s\n\n", status); - - return success ? 0 : 1; -} diff --git a/tests/backup_unused_tests/cpp/test_arrays.cpp b/tests/backup_unused_tests/cpp/test_arrays.cpp deleted file mode 100644 index edf0590b..00000000 --- a/tests/backup_unused_tests/cpp/test_arrays.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "comprehensive_arrays.sf.hpp" -#include "frame_parsers.hpp" -#include -#include - -void print_failure_details(const char* label) { - std::cout << "\n============================================================\n"; - std::cout << "FAILURE DETAILS: " << label << "\n"; - std::cout << "============================================================\n\n"; -} - -int main() { - std::cout << "\n[TEST START] C++ Array Operations\n"; - - try { - ComprehensiveArraysComprehensiveArrayMessage msg{}; - - msg.fixed_ints[0] = 1; msg.fixed_ints[1] = 2; msg.fixed_ints[2] = 3; - msg.fixed_floats[0] = 1.1f; msg.fixed_floats[1] = 2.2f; - msg.fixed_bools[0] = true; msg.fixed_bools[1] = false; - msg.fixed_bools[2] = true; msg.fixed_bools[3] = false; - - msg.bounded_uints.count = 3; - msg.bounded_uints.data[0] = 100; - msg.bounded_uints.data[1] = 200; - msg.bounded_uints.data[2] = 300; - - // Encode message into BasicDefault format - uint8_t buffer[1024]; - FrameParsers::BasicDefaultEncodeBuffer encoder(buffer, sizeof(buffer)); - - if (!encoder.encode(COMPREHENSIVE_ARRAYS_COMPREHENSIVE_ARRAY_MESSAGE_MSG_ID, &msg, - COMPREHENSIVE_ARRAYS_COMPREHENSIVE_ARRAY_MESSAGE_MAX_SIZE)) { - print_failure_details("Failed to encode message"); - std::cout << "[TEST END] C++ Array Operations: FAIL\n\n"; - return 1; - } - - // Verify encoding produced data - if (encoder.size() == 0) { - print_failure_details("Encoded data is empty"); - std::cout << "[TEST END] C++ Array Operations: FAIL\n\n"; - return 1; - } - - std::cout << "[TEST END] C++ Array Operations: PASS\n\n"; - return 0; - - } catch (const std::exception& e) { - print_failure_details(e.what()); - std::cout << "[TEST END] C++ Array Operations: FAIL\n\n"; - return 1; - } -} diff --git a/tests/backup_unused_tests/cpp/test_basic_types.cpp b/tests/backup_unused_tests/cpp/test_basic_types.cpp deleted file mode 100644 index 5194f65c..00000000 --- a/tests/backup_unused_tests/cpp/test_basic_types.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "basic_types.sf.hpp" -#include "frame_parsers.hpp" -#include -#include - -void print_failure_details(const char* label, const uint8_t* raw_data = nullptr, size_t raw_data_size = 0) { - std::cout << "\n"; - std::cout << "============================================================\n"; - std::cout << "FAILURE DETAILS: " << label << "\n"; - std::cout << "============================================================\n"; - - if (raw_data && raw_data_size > 0) { - std::cout << "\nRaw Data (" << raw_data_size << " bytes):\n Hex: "; - for (size_t i = 0; i < raw_data_size && i < 64; i++) { - printf("%02x", raw_data[i]); - } - if (raw_data_size > 64) std::cout << "..."; - std::cout << "\n"; - } - - std::cout << "============================================================\n\n"; -} - -int main() { - std::cout << "\n[TEST START] C++ Basic Types\n"; - - try { - BasicTypesBasicTypesMessage msg{}; - - msg.small_int = -42; - msg.medium_int = -1234; - msg.regular_int = -123456; - msg.large_int = -123456789; - msg.small_uint = 200; - msg.medium_uint = 50000; - msg.regular_uint = 3000000000U; - msg.large_uint = 9000000000000000000ULL; - msg.single_precision = 3.14159f; - msg.double_precision = 2.718281828; - msg.flag = true; - std::strncpy(msg.device_id, "TEST_DEVICE_001", sizeof(msg.device_id)); - msg.description.length = 12; - std::strncpy(msg.description.data, "Test message", sizeof(msg.description.data)); - - // Encode message into BasicDefault format - uint8_t buffer[512]; - FrameParsers::BasicDefaultEncodeBuffer encoder(buffer, sizeof(buffer)); - - if (!encoder.encode(BASIC_TYPES_BASIC_TYPES_MESSAGE_MSG_ID, &msg, - BASIC_TYPES_BASIC_TYPES_MESSAGE_MAX_SIZE)) { - print_failure_details("Failed to encode message", buffer, encoder.size()); - std::cout << "[TEST END] C++ Basic Types: FAIL\n\n"; - return 1; - } - - // Verify encoding produced data - if (encoder.size() == 0) { - print_failure_details("Encoded data is empty", buffer, encoder.size()); - std::cout << "[TEST END] C++ Basic Types: FAIL\n\n"; - return 1; - } - - // Verify minimum packet structure (start bytes + msg_id + data + checksums) - if (encoder.size() < 5) { - print_failure_details("Encoded data too small", buffer, encoder.size()); - std::cout << "[TEST END] C++ Basic Types: FAIL\n\n"; - return 1; - } - - std::cout << "[TEST END] C++ Basic Types: PASS\n\n"; - return 0; - - } catch (const std::exception& e) { - print_failure_details(e.what()); - std::cout << "[TEST END] C++ Basic Types: FAIL\n\n"; - return 1; - } -} diff --git a/tests/backup_unused_tests/cpp/test_cross_platform_deserialization.cpp b/tests/backup_unused_tests/cpp/test_cross_platform_deserialization.cpp deleted file mode 100644 index 71b497ee..00000000 --- a/tests/backup_unused_tests/cpp/test_cross_platform_deserialization.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include -#include -#include -#include - -#include "serialization_test.sf.hpp" -#include "frame_parsers.hpp" - -void print_failure_details(const char* label) { - std::cout << "\n============================================================\n"; - std::cout << "FAILURE DETAILS: " << label << "\n"; - std::cout << "============================================================\n\n"; -} - -bool validate_message(const SerializationTestSerializationTestMessage* msg) { - // Expected values from expected_values.json - uint32_t expected_magic = 3735928559; // 0xDEADBEEF - const char* expected_string = "Cross-platform test!"; - float expected_float = 3.14159f; - bool expected_bool = true; - int expected_array[3] = {100, 200, 300}; - - if (msg->magic_number != expected_magic) { - std::cout << " Value mismatch: magic_number (expected " << expected_magic - << ", got " << msg->magic_number << ")\n"; - return false; - } - - if (std::strncmp(msg->test_string.data, expected_string, msg->test_string.length) != 0) { - std::cout << " Value mismatch: test_string\n"; - return false; - } - - if (std::fabs(msg->test_float - expected_float) > 0.0001f) { - std::cout << " Value mismatch: test_float (expected " << expected_float - << ", got " << msg->test_float << ")\n"; - return false; - } - - if (msg->test_bool != expected_bool) { - std::cout << " Value mismatch: test_bool\n"; - return false; - } - - if (msg->test_array.count != 3) { - std::cout << " Value mismatch: test_array.count (expected 3, got " - << (int)msg->test_array.count << ")\n"; - return false; - } - - for (int i = 0; i < 3; i++) { - if (msg->test_array.data[i] != expected_array[i]) { - std::cout << " Value mismatch: test_array[" << i << "] (expected " - << expected_array[i] << ", got " << msg->test_array.data[i] << ")\n"; - return false; - } - } - - std::cout << " [OK] Data validated successfully\n"; - return true; -} - -bool read_and_validate_test_data(const char* filename) { - std::ifstream file(filename, std::ios::binary); - if (!file) { - std::cout << " Error: file not found: " << filename << "\n"; - return false; - } - - uint8_t buffer[512]; - file.read(reinterpret_cast(buffer), sizeof(buffer)); - size_t size = file.gcount(); - file.close(); - - if (size == 0) { - print_failure_details("Empty file"); - return false; - } - - FrameParsers::FrameMsgInfo decode_result = FrameParsers::basic_default_validate_packet(buffer, size); - - if (!decode_result.valid) { - print_failure_details("Failed to decode data"); - return false; - } - - const SerializationTestSerializationTestMessage* decoded_msg = - reinterpret_cast(decode_result.msg_data); - - if (!validate_message(decoded_msg)) { - std::cout << " Validation failed\n"; - return false; - } - - return true; -} - -int main(int argc, char* argv[]) { - std::cout << "\n[TEST START] C++ Cross-Platform Deserialization\n"; - - if (argc != 2) { - std::cout << " Usage: " << argv[0] << " \n"; - std::cout << "[TEST END] C++ Cross-Platform Deserialization: FAIL\n\n"; - return 1; - } - - bool success = read_and_validate_test_data(argv[1]); - - std::cout << "[TEST END] C++ Cross-Platform Deserialization: " << (success ? "PASS" : "FAIL") << "\n\n"; - - return success ? 0 : 1; -} diff --git a/tests/backup_unused_tests/cpp/test_cross_platform_serialization.cpp b/tests/backup_unused_tests/cpp/test_cross_platform_serialization.cpp deleted file mode 100644 index fa0518ba..00000000 --- a/tests/backup_unused_tests/cpp/test_cross_platform_serialization.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "serialization_test.sf.hpp" -#include "frame_parsers.hpp" -#include -#include -#include - -void print_failure_details(const char* label) { - std::cout << "\n============================================================\n"; - std::cout << "FAILURE DETAILS: " << label << "\n"; - std::cout << "============================================================\n\n"; -} - -int main() { - std::cout << "\n[TEST START] C++ Cross-Platform Serialization\n"; - - try { - SerializationTestSerializationTestMessage msg{}; - // Use values from expected_values.json - msg.magic_number = 3735928559; // 0xDEADBEEF - msg.test_string.length = 20; - std::strncpy(msg.test_string.data, "Cross-platform test!", sizeof(msg.test_string.data)); - msg.test_float = 3.14159f; - msg.test_bool = true; - msg.test_array.count = 3; - msg.test_array.data[0] = 100; - msg.test_array.data[1] = 200; - msg.test_array.data[2] = 300; - - uint8_t buffer[512]; - FrameParsers::BasicDefaultEncodeBuffer encoder(buffer, sizeof(buffer)); - - if (!encoder.encode(SERIALIZATION_TEST_SERIALIZATION_TEST_MESSAGE_MSG_ID, &msg, - SERIALIZATION_TEST_SERIALIZATION_TEST_MESSAGE_MAX_SIZE)) { - print_failure_details("Failed to encode message"); - std::cout << "[TEST END] C++ Cross-Platform Serialization: FAIL\n\n"; - return 1; - } - - std::ofstream file("cpp_test_data.bin", std::ios::binary); - if (!file) { - print_failure_details("Failed to create test data file"); - std::cout << "[TEST END] C++ Cross-Platform Serialization: FAIL\n\n"; - return 1; - } - file.write(reinterpret_cast(buffer), encoder.size()); - file.close(); - - std::cout << "[TEST END] C++ Cross-Platform Serialization: PASS\n\n"; - return 0; - - } catch (const std::exception& e) { - print_failure_details(e.what()); - std::cout << "[TEST END] C++ Cross-Platform Serialization: FAIL\n\n"; - return 1; - } -} diff --git a/tests/backup_unused_tests/js/test_arrays.js b/tests/backup_unused_tests/js/test_arrays.js deleted file mode 100644 index 88ce7048..00000000 --- a/tests/backup_unused_tests/js/test_arrays.js +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Array operations test for JavaScript struct-frame. - * Human-readable JavaScript version of the TypeScript test. - */ -"use strict"; - -function printFailureDetails(label, expectedValues, actualValues, rawData) { - console.log('\n============================================================'); - console.log('FAILURE DETAILS: ' + label); - console.log('============================================================'); - - if (expectedValues) { - console.log('\nExpected Values:'); - for (const [key, val] of Object.entries(expectedValues)) { - console.log(' ' + key + ': ' + val); - } - } - - if (actualValues) { - console.log('\nActual Values:'); - for (const [key, val] of Object.entries(actualValues)) { - console.log(' ' + key + ': ' + val); - } - } - - if (rawData && rawData.length > 0) { - console.log('\nRaw Data (' + rawData.length + ' bytes):'); - console.log(' Hex: ' + rawData.toString('hex').substring(0, 128) + (rawData.length > 64 ? '...' : '')); - } - - console.log('============================================================\n'); -} - -let comprehensive_arrays_ComprehensiveArrayMessage; -let comprehensive_arrays_Sensor; -let msg_encode; -let struct_frame_buffer; -let basic_frame_config; - -try { - const comprehensiveArraysModule = require('./comprehensive_arrays.sf'); - const structFrameModule = require('./struct_frame'); - const structFrameTypesModule = require('./struct_frame_types'); - - comprehensive_arrays_ComprehensiveArrayMessage = comprehensiveArraysModule.comprehensive_arrays_ComprehensiveArrayMessage; - comprehensive_arrays_Sensor = comprehensiveArraysModule.comprehensive_arrays_Sensor; - msg_encode = structFrameModule.msg_encode; - struct_frame_buffer = structFrameTypesModule.struct_frame_buffer; - basic_frame_config = structFrameTypesModule.basic_frame_config; -} catch (error) { - // Skip test if generated modules are not available (before code generation) -} - -function main() { - console.log('\n[TEST START] JavaScript Array Operations'); - - // Check if required modules are loaded - if (!comprehensive_arrays_ComprehensiveArrayMessage || !comprehensive_arrays_Sensor || - !msg_encode || !struct_frame_buffer || !basic_frame_config) { - console.log('[TEST SKIP] JavaScript Array Operations: Generated code not available\n'); - return true; // Return success for skip case - } - - try { - // Create a message with array data - const msg = new comprehensive_arrays_ComprehensiveArrayMessage(); - - // Fixed arrays of primitives - msg.fixed_ints = [1, 2, 3]; - msg.fixed_floats = [1.1, 2.2]; - msg.fixed_bools = [1, 0, 1, 0]; // booleans as uint8 - - // Bounded arrays of primitives - msg.bounded_uints_count = 3; - msg.bounded_uints_data = [100, 200, 300]; - - msg.bounded_doubles_count = 2; - msg.bounded_doubles_data = [123.456, 789.012]; - - // Fixed string arrays - msg.fixed_strings = [ - { value: 'String1' }, - { value: 'String2' } - ]; - - // Bounded string arrays - msg.bounded_strings_count = 2; - msg.bounded_strings_data = [ - { value: 'BoundedStr1' }, - { value: 'BoundedStr2' } - ]; - - // Enum arrays - msg.fixed_statuses = [1, 2]; // ACTIVE, ERROR - msg.bounded_statuses_count = 2; - msg.bounded_statuses_data = [1, 3]; // ACTIVE, MAINTENANCE - - // Nested message arrays - const sensor1 = new comprehensive_arrays_Sensor(); - sensor1.id = 1; - sensor1.value = 25.5; - sensor1.status = 1; // ACTIVE - sensor1.name = 'Temp1'; - msg.fixed_sensors = [sensor1]; - - const sensor3 = new comprehensive_arrays_Sensor(); - sensor3.id = 3; - sensor3.value = 15.5; - sensor3.status = 2; // ERROR - sensor3.name = 'Pressure'; - - msg.bounded_sensors_count = 1; - msg.bounded_sensors_data = [sensor3]; - - // Try to encode the message - const buffer = new struct_frame_buffer(1024); - buffer.config = basic_frame_config; - msg_encode(buffer, msg, 203); - - if (buffer.size === 0) { - printFailureDetails('Empty encoded data', - { encoded_size: '>0' }, - { encoded_size: buffer.size } - ); - console.log('[TEST END] JavaScript Array Operations: FAIL\n'); - return false; - } - - console.log('[TEST END] JavaScript Array Operations: PASS\n'); - return true; - } catch (error) { - printFailureDetails('Exception: ' + error); - console.log('[TEST END] JavaScript Array Operations: FAIL\n'); - return false; - } -} - -if (require.main === module) { - const success = main(); - process.exit(success ? 0 : 1); -} - -module.exports.main = main; diff --git a/tests/backup_unused_tests/js/test_basic_types.js b/tests/backup_unused_tests/js/test_basic_types.js deleted file mode 100644 index 61286480..00000000 --- a/tests/backup_unused_tests/js/test_basic_types.js +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Basic types test for JavaScript struct-frame. - * Human-readable JavaScript version of the TypeScript test. - */ -"use strict"; - -function printFailureDetails(label, rawData) { - console.log('\n============================================================'); - console.log('FAILURE DETAILS: ' + label); - console.log('============================================================'); - - if (rawData && rawData.length > 0) { - console.log('\nRaw Data (' + rawData.length + ' bytes):'); - console.log(' Hex: ' + rawData.toString('hex').substring(0, 128) + (rawData.length > 64 ? '...' : '')); - } - - console.log('============================================================\n'); -} - -let basic_types_BasicTypesMessage; -let msg_encode; -let struct_frame_buffer; -let basic_frame_config; - -try { - const basicTypesModule = require('./basic_types.sf'); - const structFrameModule = require('./struct_frame'); - const structFrameTypesModule = require('./struct_frame_types'); - - basic_types_BasicTypesMessage = basicTypesModule.basic_types_BasicTypesMessage; - msg_encode = structFrameModule.msg_encode; - struct_frame_buffer = structFrameTypesModule.struct_frame_buffer; - basic_frame_config = structFrameTypesModule.basic_frame_config; -} catch (error) { - // Skip test if generated modules are not available (before code generation) -} - -function testBasicTypes() { - console.log('\n[TEST START] JavaScript Basic Types'); - - try { - const msg = new basic_types_BasicTypesMessage(); - msg.small_int = -42; - msg.medium_int = -1000; - msg.regular_int = -100000; - msg.large_int = BigInt(-1000000000); - msg.small_uint = 255; - msg.medium_uint = 65535; - msg.regular_uint = 4294967295; - msg.large_uint = BigInt(1844674407370955); - msg.single_precision = 3.14159; - msg.double_precision = 2.718281828459045; - msg.flag = true; - msg.device_id = 'TEST_DEVICE_12345678901234567890'; - msg.description_length = 'Test description for basic types'.length; - msg.description_data = 'Test description for basic types'; - - const buffer = new struct_frame_buffer(1024); - buffer.config = basic_frame_config; - msg_encode(buffer, msg, 201); - - console.log('[TEST END] JavaScript Basic Types: PASS\n'); - return true; - - } catch (error) { - printFailureDetails('Exception: ' + error); - console.log('[TEST END] JavaScript Basic Types: FAIL\n'); - return false; - } -} - -if (require.main === module) { - const success = testBasicTypes(); - process.exit(success ? 0 : 1); -} - -module.exports.testBasicTypes = testBasicTypes; diff --git a/tests/backup_unused_tests/js/test_cross_platform_deserialization.js b/tests/backup_unused_tests/js/test_cross_platform_deserialization.js deleted file mode 100644 index 67318ed5..00000000 --- a/tests/backup_unused_tests/js/test_cross_platform_deserialization.js +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Cross-platform deserialization test for JavaScript struct-frame. - * Human-readable JavaScript version of the TypeScript test. - */ -"use strict"; - -const fs = require('fs'); -const path = require('path'); - -// BasicDefault constants -const BASIC_DEFAULT_START_BYTE1 = 0x90; -const BASIC_DEFAULT_START_BYTE2 = 0x71; -const BASIC_DEFAULT_HEADER_SIZE = 4; // start1 + start2 + length + msg_id -const BASIC_DEFAULT_FOOTER_SIZE = 2; // crc1 + crc2 - -function printFailureDetails(label) { - console.log('\n============================================================'); - console.log('FAILURE DETAILS: ' + label); - console.log('============================================================\n'); -} - -function loadExpectedValues() { - try { - const jsonPath = path.join(__dirname, '../../expected_values.json'); - const data = JSON.parse(fs.readFileSync(jsonPath, 'utf-8')); - return data.serialization_test; - } catch (error) { - console.log('Error loading expected values: ' + error); - return null; - } -} - -function validateBasicDefault(buffer, expected) { - // BasicDefault validation with 2 start bytes + length + msg_id - if (buffer.length < BASIC_DEFAULT_HEADER_SIZE + BASIC_DEFAULT_FOOTER_SIZE) { - console.log(' Data too short'); - return false; - } - - // Check start bytes - if (buffer[0] !== BASIC_DEFAULT_START_BYTE1 || buffer[1] !== BASIC_DEFAULT_START_BYTE2) { - console.log(' Invalid start bytes (expected 0x90 0x71, got 0x' + buffer[0].toString(16) + ' 0x' + buffer[1].toString(16) + ')'); - return false; - } - - // Check message ID (at offset 3 in BasicDefault - after length) - if (buffer[3] !== 204) { - console.log(' Invalid message ID (expected 204, got ' + buffer[3] + ')'); - return false; - } - - // Validate checksum - const msgLen = buffer.length - BASIC_DEFAULT_HEADER_SIZE - BASIC_DEFAULT_FOOTER_SIZE; - let byte1 = buffer[2]; // Start with length byte - let byte2 = buffer[2]; - byte1 = (byte1 + buffer[3]) % 256; // Add msg_id - byte2 = (byte2 + byte1) % 256; - for (let i = 0; i < msgLen; i++) { - byte1 = (byte1 + buffer[BASIC_DEFAULT_HEADER_SIZE + i]) & 0xFF; - byte2 = (byte2 + byte1) & 0xFF; - } - - if (byte1 !== buffer[buffer.length - 2] || byte2 !== buffer[buffer.length - 1]) { - console.log(' Checksum mismatch'); - return false; - } - - // Extract magic number from payload (starts at offset 4 in BasicDefault) - const magicNumber = buffer.readUInt32LE(BASIC_DEFAULT_HEADER_SIZE); - if (magicNumber !== expected.magic_number) { - console.log(' Magic number mismatch (expected ' + expected.magic_number + ', got ' + magicNumber + ')'); - return false; - } - - console.log(' [OK] Data validated successfully'); - return true; -} - -function readAndValidateTestData(filename) { - try { - if (!fs.existsSync(filename)) { - console.log(' Error: file not found: ' + filename); - return false; - } - - const binaryData = fs.readFileSync(filename); - - if (binaryData.length === 0) { - printFailureDetails('Empty file'); - return false; - } - - const expected = loadExpectedValues(); - if (!expected) { - return false; - } - - if (!validateBasicDefault(binaryData, expected)) { - console.log(' Validation failed'); - return false; - } - - return true; - } catch (error) { - printFailureDetails('Read data exception: ' + error); - return false; - } -} - -function main() { - console.log('\n[TEST START] JavaScript Cross-Platform Deserialization'); - - const args = process.argv.slice(2); - if (args.length !== 1) { - console.log(' Usage: ' + process.argv[1] + ' '); - console.log('[TEST END] JavaScript Cross-Platform Deserialization: FAIL\n'); - return false; - } - - try { - const success = readAndValidateTestData(args[0]); - - console.log('[TEST END] JavaScript Cross-Platform Deserialization: ' + (success ? 'PASS' : 'FAIL') + '\n'); - return success; - } catch (error) { - printFailureDetails('Exception: ' + error); - console.log('[TEST END] JavaScript Cross-Platform Deserialization: FAIL\n'); - return false; - } -} - -if (require.main === module) { - const success = main(); - process.exit(success ? 0 : 1); -} - -module.exports.main = main; diff --git a/tests/backup_unused_tests/js/test_cross_platform_serialization.js b/tests/backup_unused_tests/js/test_cross_platform_serialization.js deleted file mode 100644 index b1009c2e..00000000 --- a/tests/backup_unused_tests/js/test_cross_platform_serialization.js +++ /dev/null @@ -1,167 +0,0 @@ -/** - * Cross-platform serialization test for JavaScript struct-frame. - * Human-readable JavaScript version of the TypeScript test. - */ -"use strict"; - -const fs = require('fs'); -const path = require('path'); - -// BasicDefault constants -const BASIC_DEFAULT_START_BYTE1 = 0x90; -const BASIC_DEFAULT_START_BYTE2 = 0x71; -const BASIC_DEFAULT_HEADER_SIZE = 4; // start1 + start2 + length + msg_id -const BASIC_DEFAULT_FOOTER_SIZE = 2; // crc1 + crc2 - -function printFailureDetails(label, expectedValues, actualValues, rawData) { - console.log('\n============================================================'); - console.log('FAILURE DETAILS: ' + label); - console.log('============================================================'); - - if (expectedValues) { - console.log('\nExpected Values:'); - for (const [key, val] of Object.entries(expectedValues)) { - console.log(' ' + key + ': ' + val); - } - } - - if (actualValues) { - console.log('\nActual Values:'); - for (const [key, val] of Object.entries(actualValues)) { - console.log(' ' + key + ': ' + val); - } - } - - if (rawData && rawData.length > 0) { - console.log('\nRaw Data (' + rawData.length + ' bytes):'); - console.log(' Hex: ' + rawData.toString('hex').substring(0, 128) + (rawData.length > 64 ? '...' : '')); - } - - console.log('============================================================\n'); -} - -function loadExpectedValues() { - try { - const jsonPath = path.join(__dirname, '../../expected_values.json'); - const data = JSON.parse(fs.readFileSync(jsonPath, 'utf-8')); - return data.serialization_test; - } catch (error) { - console.log('Error loading expected values: ' + error); - return null; - } -} - -function createTestData() { - try { - // Load expected values from JSON - const expected = loadExpectedValues(); - if (!expected) { - return false; - } - - // Create a full BasicDefault message that matches C/Python format - // Frame format: [START1=0x90] [START2=0x71] [LEN] [MSG_ID] [payload] [checksum1] [checksum2] - const msg_id = 204; - - // Create full payload matching the message structure: - // - magic_number: uint32 (4 bytes) - // - test_string: length byte (1) + data (64 bytes) = 65 bytes - // - test_float: float (4 bytes) - // - test_bool: bool (1 byte) - // - test_array: count byte (1) + int32 data (5*4=20 bytes) = 21 bytes - // Total: 4 + 65 + 4 + 1 + 21 = 95 bytes - const payloadSize = 95; - const payload = Buffer.alloc(payloadSize); - let offset = 0; - - // magic_number (uint32, little-endian) - payload.writeUInt32LE(expected.magic_number, offset); - offset += 4; - - // test_string: length byte + 64 bytes of data - const testString = expected.test_string; - payload.writeUInt8(testString.length, offset); - offset += 1; - Buffer.from(testString).copy(payload, offset, 0, testString.length); - // String data array is 64 bytes, remaining bytes are already 0 - offset += 64; - - // test_float (float, little-endian) - payload.writeFloatLE(expected.test_float, offset); - offset += 4; - - // test_bool (1 byte) - payload.writeUInt8(expected.test_bool ? 1 : 0, offset); - offset += 1; - - // test_array: count byte + int32 data (5 elements max) - const testArray = expected.test_array; - payload.writeUInt8(testArray.length, offset); - offset += 1; - for (let i = 0; i < 5; i++) { - if (i < testArray.length) { - payload.writeInt32LE(testArray[i], offset); - } else { - payload.writeInt32LE(0, offset); - } - offset += 4; - } - - // Calculate Fletcher checksum on length + msg_id + payload (consistent with BasicDefault) - let byte1 = payloadSize & 0xFF; // Start with length byte - let byte2 = payloadSize & 0xFF; - byte1 = (byte1 + msg_id) & 0xFF; // Add msg_id - byte2 = (byte2 + byte1) & 0xFF; - for (let i = 0; i < payload.length; i++) { - byte1 = (byte1 + payload[i]) & 0xFF; - byte2 = (byte2 + byte1) & 0xFF; - } - - // Build complete frame with BasicDefault format - const frame = Buffer.alloc(BASIC_DEFAULT_HEADER_SIZE + payloadSize + BASIC_DEFAULT_FOOTER_SIZE); - frame[0] = BASIC_DEFAULT_START_BYTE1; - frame[1] = BASIC_DEFAULT_START_BYTE2; - frame[2] = payloadSize & 0xFF; // Length byte - frame[3] = msg_id; - payload.copy(frame, BASIC_DEFAULT_HEADER_SIZE); - frame[frame.length - 2] = byte1; - frame[frame.length - 1] = byte2; - - // Write to file - determine correct path based on where we're running from - const outputPath = fs.existsSync('tests/generated/js') - ? 'tests/generated/js/javascript_test_data.bin' - : 'javascript_test_data.bin'; - fs.writeFileSync(outputPath, frame); - - return true; - } catch (error) { - printFailureDetails('Create test data exception: ' + error); - return false; - } -} - -function main() { - console.log('\n[TEST START] JavaScript Cross-Platform Serialization'); - - try { - // Create JavaScript test data - if (!createTestData()) { - console.log('[TEST END] JavaScript Cross-Platform Serialization: FAIL\n'); - return false; - } - - console.log('[TEST END] JavaScript Cross-Platform Serialization: PASS\n'); - return true; - } catch (error) { - printFailureDetails('Exception: ' + error); - console.log('[TEST END] JavaScript Cross-Platform Serialization: FAIL\n'); - return false; - } -} - -if (require.main === module) { - const success = main(); - process.exit(success ? 0 : 1); -} - -module.exports.main = main; diff --git a/tests/backup_unused_tests/py/test_arrays.py b/tests/backup_unused_tests/py/test_arrays.py deleted file mode 100644 index 6432f617..00000000 --- a/tests/backup_unused_tests/py/test_arrays.py +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env python3 -""" -Test script for array operations serialization/deserialization in Python. -""" - -import sys -import os - - -def print_failure_details(label, expected_values=None, actual_values=None, raw_data=None): - """Print detailed failure information""" - print(f"\n{'='*60}") - print(f"FAILURE DETAILS: {label}") - print(f"{'='*60}") - - if expected_values: - print("\nExpected Values:") - for key, val in expected_values.items(): - print(f" {key}: {val}") - - if actual_values: - print("\nActual Values:") - for key, val in actual_values.items(): - print(f" {key}: {val}") - - if raw_data: - print(f"\nRaw Data ({len(raw_data)} bytes):") - print(f" Hex: {raw_data.hex()}") - - print(f"{'='*60}\n") - - -def test_array_operations(): - """Test array operations serialization and deserialization with BasicPacket""" - try: - sys.path.insert(0, '../generated/py') - from comprehensive_arrays_sf import ( - ComprehensiveArraysComprehensiveArrayMessage, - ComprehensiveArraysSensor, - ComprehensiveArraysStatus, - _BoundedArray_bounded_uints, - _BoundedArray_bounded_doubles, - _BoundedStringArray_bounded_strings, - _BoundedArray_bounded_statuses, - _BoundedArray_bounded_sensors - ) - from struct_frame_parser import BasicPacket, FrameParser - - sensor1 = ComprehensiveArraysSensor(1, 25.5, 1, b"Temp1") - sensor3 = ComprehensiveArraysSensor(3, 15.5, 2, b"Pressure") - - bounded_uints = _BoundedArray_bounded_uints(3, [100, 200, 300]) - bounded_doubles = _BoundedArray_bounded_doubles(2, [123.456, 789.012]) - bounded_strings = _BoundedStringArray_bounded_strings(2, [b"BoundedStr1", b"BoundedStr2"]) - bounded_statuses = _BoundedArray_bounded_statuses(2, [1, 3]) - bounded_sensors = _BoundedArray_bounded_sensors(1, sensor3) - - msg = ComprehensiveArraysComprehensiveArrayMessage( - [1, 2, 3], [1.1, 2.2], [True, False, True, False], - bounded_uints, bounded_doubles, - [b"String1", b"String2"], bounded_strings, - [1, 2], bounded_statuses, - sensor1, bounded_sensors - ) - - # Encode message into BasicPacket format - packet = BasicPacket() - encoded_data = packet.encode_msg(msg) - - if len(encoded_data) == 0: - print_failure_details( - "Empty encoded data", - expected_values={"encoded_size": ">0"}, - actual_values={"encoded_size": len(encoded_data)} - ) - return False - - # Decode the BasicPacket back into a message - packet_formats = {0x90: BasicPacket()} - msg_definitions = {203: ComprehensiveArraysComprehensiveArrayMessage} - parser = FrameParser(packet_formats, msg_definitions) - - decoded_msg = None - for byte in encoded_data: - result = parser.parse_char(byte) - if result: - decoded_msg = result - break - - if not decoded_msg: - print_failure_details( - "Failed to decode message", - expected_values={"decoded_message": "valid"}, - actual_values={"decoded_message": None}, - raw_data=encoded_data - ) - return False - - # Compare original and decoded messages - if decoded_msg.fixed_uints != msg.fixed_uints: - print_failure_details( - "Value mismatch: fixed_uints", - expected_values={"fixed_uints": msg.fixed_uints}, - actual_values={"fixed_uints": decoded_msg.fixed_uints} - ) - return False - - if decoded_msg.bounded_uints.count != msg.bounded_uints.count: - print_failure_details( - "Value mismatch: bounded_uints.count", - expected_values={"count": msg.bounded_uints.count}, - actual_values={"count": decoded_msg.bounded_uints.count} - ) - return False - - if decoded_msg.sensor.id != msg.sensor.id: - print_failure_details( - "Value mismatch: sensor.id", - expected_values={"sensor.id": msg.sensor.id}, - actual_values={"sensor.id": decoded_msg.sensor.id} - ) - return False - - return True - - except ImportError: - return True # Skip if generated code not available - - except Exception as e: - print_failure_details( - f"Exception: {type(e).__name__}", - expected_values={"result": "success"}, - actual_values={"exception": str(e)} - ) - import traceback - traceback.print_exc() - return False - - -def main(): - """Main test function""" - print("\n[TEST START] Python Array Operations") - - success = test_array_operations() - - status = "PASS" if success else "FAIL" - print(f"[TEST END] Python Array Operations: {status}\n") - - return success - - -if __name__ == "__main__": - success = main() - sys.exit(0 if success else 1) diff --git a/tests/backup_unused_tests/py/test_basic_types.py b/tests/backup_unused_tests/py/test_basic_types.py deleted file mode 100644 index 299c006e..00000000 --- a/tests/backup_unused_tests/py/test_basic_types.py +++ /dev/null @@ -1,145 +0,0 @@ -#!/usr/bin/env python3 -""" -Test script for basic data types serialization/deserialization in Python. -""" - -import sys -import os - - -def print_failure_details(label, msg, expected_values=None, actual_values=None, raw_data=None): - """Print detailed failure information""" - print(f"\n{'='*60}") - print(f"FAILURE DETAILS: {label}") - print(f"{'='*60}") - - if expected_values: - print("\nExpected Values:") - for key, val in expected_values.items(): - print(f" {key}: {val}") - - if actual_values: - print("\nActual Values:") - for key, val in actual_values.items(): - print(f" {key}: {val}") - - if raw_data: - print(f"\nRaw Data ({len(raw_data)} bytes):") - print(f" Hex: {raw_data.hex()}") - - print(f"{'='*60}\n") - - -def test_basic_types(): - """Test basic data types serialization and deserialization with BasicPacket""" - try: - sys.path.insert(0, '../generated/py') - from basic_types_sf import BasicTypesBasicTypesMessage, _VariableString_description - from struct_frame_parser import BasicPacket, FrameParser - - desc_text = b"Test description for basic types" - description = _VariableString_description( - length=len(desc_text), - data=desc_text.ljust(128, b'\x00') - ) - - msg = BasicTypesBasicTypesMessage( - -42, -1000, -100000, -1000000000, - 255, 65535, 4294967295, 18446744073709551615, - 3.14159, 2.718281828459045, True, - b"TEST_DEVICE_12345678901234567890", - description - ) - - # Encode message into BasicPacket format - packet = BasicPacket() - encoded_data = packet.encode_msg(msg) - - # Verify encoded data is not empty - if len(encoded_data) == 0: - print_failure_details( - "Empty encoded data", - msg, - expected_values={"encoded_size": ">0"}, - actual_values={"encoded_size": len(encoded_data)} - ) - return False - - # Decode the BasicPacket back into a message - packet_formats = {0x90: BasicPacket()} - msg_definitions = {201: BasicTypesBasicTypesMessage} - parser = FrameParser(packet_formats, msg_definitions) - - decoded_msg = None - for byte in encoded_data: - result = parser.parse_char(byte) - if result: - decoded_msg = result - break - - if not decoded_msg: - print_failure_details( - "Failed to decode message", - expected_values={"decoded_message": "valid"}, - actual_values={"decoded_message": None}, - raw_data=encoded_data - ) - return False - - # Compare original and decoded messages - if decoded_msg.small_int != msg.small_int: - print_failure_details( - "Value mismatch: small_int", - expected_values={"small_int": msg.small_int}, - actual_values={"small_int": decoded_msg.small_int} - ) - return False - - if decoded_msg.medium_int != msg.medium_int: - print_failure_details( - "Value mismatch: medium_int", - expected_values={"medium_int": msg.medium_int}, - actual_values={"medium_int": decoded_msg.medium_int} - ) - return False - - if decoded_msg.flag != msg.flag: - print_failure_details( - "Value mismatch: flag", - expected_values={"flag": msg.flag}, - actual_values={"flag": decoded_msg.flag} - ) - return False - - return True - - except ImportError: - return True # Skip if generated code not available - - except Exception as e: - print_failure_details( - f"Exception: {type(e).__name__}", - None, - expected_values={"result": "success"}, - actual_values={"exception": str(e)} - ) - import traceback - traceback.print_exc() - return False - - -def main(): - """Main test function""" - print("\n[TEST START] Python Basic Types") - - success = test_basic_types() - - status = "PASS" if success else "FAIL" - print(f"[TEST END] Python Basic Types: {status}\n") - - return success - - -if __name__ == "__main__": - success = main() - sys.exit(0 if success else 1) diff --git a/tests/backup_unused_tests/py/test_cross_platform_deserialization.py b/tests/backup_unused_tests/py/test_cross_platform_deserialization.py deleted file mode 100644 index 1bc26e40..00000000 --- a/tests/backup_unused_tests/py/test_cross_platform_deserialization.py +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env python3 -""" -Test script for cross-platform deserialization - reads and validates test data from files. -This test reads a binary file and validates it against expected_values.json. -""" - -import sys -import os -import json - - -def print_failure_details(label, expected_values=None, actual_values=None, raw_data=None): - """Print detailed failure information""" - print(f"\n{'='*60}") - print(f"FAILURE DETAILS: {label}") - print(f"{'='*60}") - - if expected_values: - print("\nExpected Values:") - for key, val in expected_values.items(): - print(f" {key}: {val}") - - if actual_values: - print("\nActual Values:") - for key, val in actual_values.items(): - print(f" {key}: {val}") - - if raw_data: - print(f"\nRaw Data ({len(raw_data)} bytes):") - print(f" Hex: {raw_data.hex()}") - - print(f"{'='*60}\n") - - -def load_expected_values(): - """Load expected values from JSON file""" - json_path = os.path.join(os.path.dirname( - __file__), '..', 'expected_values.json') - try: - with open(json_path, 'r') as f: - data = json.load(f) - return data['serialization_test'] - except Exception as e: - print(f"Error loading expected values: {e}") - return None - - -def validate_message(msg, expected): - """Validate a decoded message against expected values""" - if msg.magic_number != expected['magic_number']: - print_failure_details( - "Value mismatch: magic_number", - expected_values={"magic_number": expected['magic_number']}, - actual_values={"magic_number": msg.magic_number} - ) - return False - - # Compare string (bytes vs string) - test_string = msg.test_string.decode('utf-8').rstrip('\x00') if isinstance( - msg.test_string, bytes) else str(msg.test_string).rstrip('\x00') - if test_string != expected['test_string']: - print_failure_details( - "Value mismatch: test_string", - expected_values={"test_string": expected['test_string']}, - actual_values={"test_string": test_string} - ) - return False - - # Compare float with tolerance - if abs(msg.test_float - expected['test_float']) > 0.0001: - print_failure_details( - "Value mismatch: test_float", - expected_values={"test_float": expected['test_float']}, - actual_values={"test_float": msg.test_float} - ) - return False - - if msg.test_bool != expected['test_bool']: - print_failure_details( - "Value mismatch: test_bool", - expected_values={"test_bool": expected['test_bool']}, - actual_values={"test_bool": msg.test_bool} - ) - return False - - # Compare array - if list(msg.test_array) != expected['test_array']: - print_failure_details( - "Value mismatch: test_array", - expected_values={"test_array": expected['test_array']}, - actual_values={"test_array": list(msg.test_array)} - ) - return False - - return True - - -def read_and_validate_test_data(filename): - """Read and validate test data from a binary file""" - try: - if not os.path.exists(filename): - print(f" Error: file not found: {filename}") - return False - - with open(filename, 'rb') as f: - binary_data = f.read() - - if len(binary_data) == 0: - print_failure_details( - "Empty file", - expected_values={"data_size": ">0"}, - actual_values={"data_size": 0}, - raw_data=binary_data - ) - return False - - # Import modules - try package import first, then fallback to direct import - import importlib - try: - msg_module = importlib.import_module('py.serialization_test_sf') - SerializationTestSerializationTestMessage = msg_module.SerializationTestSerializationTestMessage - basic_module = importlib.import_module('py.basic_default') - BasicDefault = basic_module.BasicDefault - except ImportError: - try: - from serialization_test_sf import SerializationTestSerializationTestMessage - from basic_default import BasicDefault - except ImportError as e: - print(f" Error importing modules: {e}") - return False - - # Validate and decode using BasicDefault - result = BasicDefault.validate_packet(list(binary_data)) - - if not result.valid: - print_failure_details( - "Failed to decode data", - expected_values={"decoded_message": "valid"}, - actual_values={"decoded_message": None}, - raw_data=binary_data - ) - return False - - # Decode the message data - msg_data = bytes(result.msg_data) - decoded_msg = SerializationTestSerializationTestMessage.create_unpack(msg_data) - - # Load expected values and validate - expected = load_expected_values() - if not expected: - return False - - if not validate_message(decoded_msg, expected): - print(" Validation failed") - return False - - print(" [OK] Data validated successfully") - return True - - except ImportError: - print(" Error: Generated code not available") - return False - - except Exception as e: - print_failure_details( - f"Read data exception: {type(e).__name__}", - expected_values={"result": "success"}, - actual_values={"exception": str(e)} - ) - import traceback - traceback.print_exc() - return False - - -def main(): - """Main test function""" - print("\n[TEST START] Python Cross-Platform Deserialization") - - if len(sys.argv) != 2: - print(f" Usage: {sys.argv[0]} ") - print("[TEST END] Python Cross-Platform Deserialization: FAIL\n") - return False - - success = read_and_validate_test_data(sys.argv[1]) - - status = "PASS" if success else "FAIL" - print(f"[TEST END] Python Cross-Platform Deserialization: {status}\n") - - return success - - -if __name__ == "__main__": - success = main() - sys.exit(0 if success else 1) diff --git a/tests/backup_unused_tests/py/test_cross_platform_serialization.py b/tests/backup_unused_tests/py/test_cross_platform_serialization.py deleted file mode 100644 index 8750f9e1..00000000 --- a/tests/backup_unused_tests/py/test_cross_platform_serialization.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env python3 -""" -Test script for cross-platform serialization - writes test data to file. -This test populates a message from expected_values.json and writes it to a binary file. -""" - -import sys -import os -import json - - -def print_failure_details(label, expected_values=None, actual_values=None, raw_data=None): - """Print detailed failure information""" - print(f"\n{'='*60}") - print(f"FAILURE DETAILS: {label}") - print(f"{'='*60}") - - if expected_values: - print("\nExpected Values:") - for key, val in expected_values.items(): - print(f" {key}: {val}") - - if actual_values: - print("\nActual Values:") - for key, val in actual_values.items(): - print(f" {key}: {val}") - - if raw_data: - print(f"\nRaw Data ({len(raw_data)} bytes):") - print(f" Hex: {raw_data.hex()}") - - print(f"{'='*60}\n") - - -def load_expected_values(): - """Load expected values from JSON file""" - json_path = os.path.join(os.path.dirname(__file__), '..', 'expected_values.json') - try: - with open(json_path, 'r') as f: - data = json.load(f) - return data['serialization_test'] - except Exception as e: - print(f"Error loading expected values: {e}") - return None - - -def create_test_data(): - """Create test data for cross-platform compatibility testing""" - try: - # Import modules - try package import first, then fallback to direct import - import importlib - try: - msg_module = importlib.import_module('py.serialization_test_sf') - SerializationTestSerializationTestMessage = msg_module.SerializationTestSerializationTestMessage - basic_module = importlib.import_module('py.basic_default') - BasicDefault = basic_module.BasicDefault - except ImportError: - try: - from serialization_test_sf import SerializationTestSerializationTestMessage - from basic_default import BasicDefault - except ImportError as e: - print(f" Error importing modules: {e}") - return True # Skip if generated code not available - - # Load expected values from JSON - expected = load_expected_values() - if not expected: - return False - - # Create test message using values from JSON - msg = SerializationTestSerializationTestMessage( - magic_number=expected['magic_number'], - test_string=expected['test_string'].encode('utf-8'), - test_float=expected['test_float'], - test_bool=expected['test_bool'], - test_array=expected['test_array'] - ) - - # Create a parser instance and encode the message - parser = BasicDefault() - encoded_data = parser.encode_msg(msg) - - with open('python_test_data.bin', 'wb') as f: - f.write(bytes(encoded_data)) - - return True - - except ImportError: - return True # Skip if generated code not available - - except Exception as e: - print_failure_details( - f"Create test data exception: {type(e).__name__}", - expected_values={"result": "success"}, - actual_values={"exception": str(e)} - ) - import traceback - traceback.print_exc() - return False - - -def main(): - """Main test function""" - print("\n[TEST START] Python Cross-Platform Serialization") - - success = create_test_data() - - status = "PASS" if success else "FAIL" - print(f"[TEST END] Python Cross-Platform Serialization: {status}\n") - - return success - - -if __name__ == "__main__": - success = main() - sys.exit(0 if success else 1) diff --git a/tests/backup_unused_tests/ts/test_arrays.ts b/tests/backup_unused_tests/ts/test_arrays.ts deleted file mode 100644 index 8a6fc51d..00000000 --- a/tests/backup_unused_tests/ts/test_arrays.ts +++ /dev/null @@ -1,137 +0,0 @@ -function printFailureDetails(label: string, expectedValues?: any, actualValues?: any, rawData?: Buffer): void { - console.log('\n============================================================'); - console.log(`FAILURE DETAILS: ${label}`); - console.log('============================================================'); - - if (expectedValues) { - console.log('\nExpected Values:'); - for (const [key, val] of Object.entries(expectedValues)) { - console.log(` ${key}: ${val}`); - } - } - - if (actualValues) { - console.log('\nActual Values:'); - for (const [key, val] of Object.entries(actualValues)) { - console.log(` ${key}: ${val}`); - } - } - - if (rawData && rawData.length > 0) { - console.log(`\nRaw Data (${rawData.length} bytes):`); - console.log(` Hex: ${rawData.toString('hex').substring(0, 128)}${rawData.length > 64 ? '...' : ''}`); - } - - console.log('============================================================\n'); -} - -let comprehensive_arrays_ComprehensiveArrayMessage: any; -let comprehensive_arrays_Sensor: any; -let msg_encode: any; -let struct_frame_buffer: any; -let basic_frame_config: any; - -try { - const comprehensiveArraysModule = require('./comprehensive_arrays.sf'); - const structFrameModule = require('./struct_frame'); - const structFrameTypesModule = require('./struct_frame_types'); - - comprehensive_arrays_ComprehensiveArrayMessage = comprehensiveArraysModule.comprehensive_arrays_ComprehensiveArrayMessage; - comprehensive_arrays_Sensor = comprehensiveArraysModule.comprehensive_arrays_Sensor; - msg_encode = structFrameModule.msg_encode; - struct_frame_buffer = structFrameTypesModule.struct_frame_buffer; - basic_frame_config = structFrameTypesModule.basic_frame_config; -} catch (error) { - // Skip test if generated modules are not available (before code generation) -} - -function main(): boolean { - console.log('\n[TEST START] TypeScript Array Operations'); - - // Check if required modules are loaded - if (!comprehensive_arrays_ComprehensiveArrayMessage || !comprehensive_arrays_Sensor || - !msg_encode || !struct_frame_buffer || !basic_frame_config) { - console.log('[TEST SKIP] TypeScript Array Operations: Generated code not available\n'); - return true; // Return success for skip case - } - - try { - // Create a message with array data - const msg = new comprehensive_arrays_ComprehensiveArrayMessage(); - - // Fixed arrays of primitives - msg.fixed_ints = [1, 2, 3]; - msg.fixed_floats = [1.1, 2.2]; - msg.fixed_bools = [1, 0, 1, 0]; // booleans as uint8 - - // Bounded arrays of primitives - msg.bounded_uints_count = 3; - msg.bounded_uints_data = [100, 200, 300]; - - msg.bounded_doubles_count = 2; - msg.bounded_doubles_data = [123.456, 789.012]; - - // Fixed string arrays - msg.fixed_strings = [ - { value: 'String1' }, - { value: 'String2' } - ]; - - // Bounded string arrays - msg.bounded_strings_count = 2; - msg.bounded_strings_data = [ - { value: 'BoundedStr1' }, - { value: 'BoundedStr2' } - ]; - - // Enum arrays - msg.fixed_statuses = [1, 2]; // ACTIVE, ERROR - msg.bounded_statuses_count = 2; - msg.bounded_statuses_data = [1, 3]; // ACTIVE, MAINTENANCE - - // Nested message arrays - const sensor1 = new comprehensive_arrays_Sensor(); - sensor1.id = 1; - sensor1.value = 25.5; - sensor1.status = 1; // ACTIVE - sensor1.name = 'Temp1'; - msg.fixed_sensors = [sensor1]; - - const sensor3 = new comprehensive_arrays_Sensor(); - sensor3.id = 3; - sensor3.value = 15.5; - sensor3.status = 2; // ERROR - sensor3.name = 'Pressure'; - - msg.bounded_sensors_count = 1; - msg.bounded_sensors_data = [sensor3]; - - // Try to encode the message - const buffer = new struct_frame_buffer(1024); - buffer.config = basic_frame_config; - msg_encode(buffer, msg, 203); - - if (buffer.size === 0) { - printFailureDetails('Empty encoded data', - { encoded_size: '>0' }, - { encoded_size: buffer.size } - ); - console.log('[TEST END] TypeScript Array Operations: FAIL\n'); - return false; - } - - console.log('[TEST END] TypeScript Array Operations: PASS\n'); - return true; - } catch (error) { - printFailureDetails(`Exception: ${error}`); - console.log('[TEST END] TypeScript Array Operations: FAIL\n'); - return false; - } -} - -if (require.main === module) { - const success = main(); - process.exit(success ? 0 : 1); -} - -export { main }; diff --git a/tests/backup_unused_tests/ts/test_basic_types.ts b/tests/backup_unused_tests/ts/test_basic_types.ts deleted file mode 100644 index aeaaf7d9..00000000 --- a/tests/backup_unused_tests/ts/test_basic_types.ts +++ /dev/null @@ -1,74 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; - -function printFailureDetails(label: string, rawData?: Buffer): void { - console.log('\n============================================================'); - console.log(`FAILURE DETAILS: ${label}`); - console.log('============================================================'); - - if (rawData && rawData.length > 0) { - console.log(`\nRaw Data (${rawData.length} bytes):`); - console.log(` Hex: ${rawData.toString('hex').substring(0, 128)}${rawData.length > 64 ? '...' : ''}`); - } - - console.log('============================================================\n'); -} - -let basic_types_BasicTypesMessage: any; -let msg_encode: any; -let struct_frame_buffer: any; -let basic_frame_config: any; - -try { - const basicTypesModule = require('./basic_types.sf'); - const structFrameModule = require('./struct_frame'); - const structFrameTypesModule = require('./struct_frame_types'); - - basic_types_BasicTypesMessage = basicTypesModule.basic_types_BasicTypesMessage; - msg_encode = structFrameModule.msg_encode; - struct_frame_buffer = structFrameTypesModule.struct_frame_buffer; - basic_frame_config = structFrameTypesModule.basic_frame_config; -} catch (error) { - // Skip test if generated modules are not available (before code generation) -} - -function testBasicTypes(): boolean { - console.log('\n[TEST START] TypeScript Basic Types'); - - try { - const msg = new basic_types_BasicTypesMessage(); - msg.small_int = -42; - msg.medium_int = -1000; - msg.regular_int = -100000; - msg.large_int = BigInt(-1000000000); - msg.small_uint = 255; - msg.medium_uint = 65535; - msg.regular_uint = 4294967295; - msg.large_uint = BigInt(1844674407370955); - msg.single_precision = 3.14159; - msg.double_precision = 2.718281828459045; - msg.flag = true; - msg.device_id = 'TEST_DEVICE_12345678901234567890'; - msg.description_length = 'Test description for basic types'.length; - msg.description_data = 'Test description for basic types'; - - const buffer = new struct_frame_buffer(1024); - buffer.config = basic_frame_config; - msg_encode(buffer, msg, 201); - - console.log('[TEST END] TypeScript Basic Types: PASS\n'); - return true; - - } catch (error) { - printFailureDetails(`Exception: ${error}`); - console.log('[TEST END] TypeScript Basic Types: FAIL\n'); - return false; - } -} - -if (require.main === module) { - const success = testBasicTypes(); - process.exit(success ? 0 : 1); -} - -export { testBasicTypes }; diff --git a/tests/backup_unused_tests/ts/test_cross_platform_deserialization.ts b/tests/backup_unused_tests/ts/test_cross_platform_deserialization.ts deleted file mode 100644 index 11415e99..00000000 --- a/tests/backup_unused_tests/ts/test_cross_platform_deserialization.ts +++ /dev/null @@ -1,131 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; - -// BasicDefault constants -const BASIC_DEFAULT_START_BYTE1 = 0x90; -const BASIC_DEFAULT_START_BYTE2 = 0x71; -const BASIC_DEFAULT_HEADER_SIZE = 4; // start1 + start2 + length + msg_id -const BASIC_DEFAULT_FOOTER_SIZE = 2; // crc1 + crc2 - -function printFailureDetails(label: string): void { - console.log('\n============================================================'); - console.log(`FAILURE DETAILS: ${label}`); - console.log('============================================================\n'); -} - -function loadExpectedValues(): any { - try { - const jsonPath = path.join(__dirname, '../../../expected_values.json'); - const data = JSON.parse(fs.readFileSync(jsonPath, 'utf-8')); - return data.serialization_test; - } catch (error) { - console.log(`Error loading expected values: ${error}`); - return null; - } -} - -function validateBasicDefault(buffer: Buffer, expected: any): boolean { - // BasicDefault validation with 2 start bytes + length + msg_id - if (buffer.length < BASIC_DEFAULT_HEADER_SIZE + BASIC_DEFAULT_FOOTER_SIZE) { - console.log(' Data too short'); - return false; - } - - // Check start bytes - if (buffer[0] !== BASIC_DEFAULT_START_BYTE1 || buffer[1] !== BASIC_DEFAULT_START_BYTE2) { - console.log(` Invalid start bytes (expected 0x90 0x71, got 0x${buffer[0].toString(16)} 0x${buffer[1].toString(16)})`); - return false; - } - - // Check message ID (at offset 3 in BasicDefault - after length) - if (buffer[3] !== 204) { - console.log(` Invalid message ID (expected 204, got ${buffer[3]})`); - return false; - } - - // Validate checksum - const msgLen = buffer.length - BASIC_DEFAULT_HEADER_SIZE - BASIC_DEFAULT_FOOTER_SIZE; - let byte1 = buffer[2]; // Start with length byte - let byte2 = buffer[2]; - byte1 = (byte1 + buffer[3]) % 256; // Add msg_id - byte2 = (byte2 + byte1) % 256; - for (let i = 0; i < msgLen; i++) { - byte1 = (byte1 + buffer[BASIC_DEFAULT_HEADER_SIZE + i]) & 0xFF; - byte2 = (byte2 + byte1) & 0xFF; - } - - if (byte1 !== buffer[buffer.length - 2] || byte2 !== buffer[buffer.length - 1]) { - console.log(` Checksum mismatch`); - return false; - } - - // Extract magic number from payload (starts at offset 4 in BasicDefault) - const magicNumber = buffer.readUInt32LE(BASIC_DEFAULT_HEADER_SIZE); - if (magicNumber !== expected.magic_number) { - console.log(` Magic number mismatch (expected ${expected.magic_number}, got ${magicNumber})`); - return false; - } - - console.log(' [OK] Data validated successfully'); - return true; -} - -function readAndValidateTestData(filename: string): boolean { - try { - if (!fs.existsSync(filename)) { - console.log(` Error: file not found: ${filename}`); - return false; - } - - const binaryData = fs.readFileSync(filename); - - if (binaryData.length === 0) { - printFailureDetails('Empty file'); - return false; - } - - const expected = loadExpectedValues(); - if (!expected) { - return false; - } - - if (!validateBasicDefault(binaryData, expected)) { - console.log(' Validation failed'); - return false; - } - - return true; - } catch (error) { - printFailureDetails(`Read data exception: ${error}`); - return false; - } -} - -function main(): boolean { - console.log('\n[TEST START] TypeScript Cross-Platform Deserialization'); - - const args = process.argv.slice(2); - if (args.length !== 1) { - console.log(` Usage: ${process.argv[1]} `); - console.log('[TEST END] TypeScript Cross-Platform Deserialization: FAIL\n'); - return false; - } - - try { - const success = readAndValidateTestData(args[0]); - - console.log(`[TEST END] TypeScript Cross-Platform Deserialization: ${success ? 'PASS' : 'FAIL'}\n`); - return success; - } catch (error) { - printFailureDetails(`Exception: ${error}`); - console.log('[TEST END] TypeScript Cross-Platform Deserialization: FAIL\n'); - return false; - } -} - -if (require.main === module) { - const success = main(); - process.exit(success ? 0 : 1); -} - -export { main }; diff --git a/tests/backup_unused_tests/ts/test_cross_platform_serialization.ts b/tests/backup_unused_tests/ts/test_cross_platform_serialization.ts deleted file mode 100644 index de77c06f..00000000 --- a/tests/backup_unused_tests/ts/test_cross_platform_serialization.ts +++ /dev/null @@ -1,161 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; - -function printFailureDetails(label: string, expectedValues?: any, actualValues?: any, rawData?: Buffer): void { - console.log('\n============================================================'); - console.log(`FAILURE DETAILS: ${label}`); - console.log('============================================================'); - - if (expectedValues) { - console.log('\nExpected Values:'); - for (const [key, val] of Object.entries(expectedValues)) { - console.log(` ${key}: ${val}`); - } - } - - if (actualValues) { - console.log('\nActual Values:'); - for (const [key, val] of Object.entries(actualValues)) { - console.log(` ${key}: ${val}`); - } - } - - if (rawData && rawData.length > 0) { - console.log(`\nRaw Data (${rawData.length} bytes):`); - console.log(` Hex: ${rawData.toString('hex').substring(0, 128)}${rawData.length > 64 ? '...' : ''}`); - } - - console.log('============================================================\n'); -} - -// BasicDefault constants -const BASIC_DEFAULT_START_BYTE1 = 0x90; -const BASIC_DEFAULT_START_BYTE2 = 0x71; -const BASIC_DEFAULT_HEADER_SIZE = 4; // start1 + start2 + length + msg_id -const BASIC_DEFAULT_FOOTER_SIZE = 2; // crc1 + crc2 - -function loadExpectedValues(): any { - try { - const jsonPath = path.join(__dirname, '../../../expected_values.json'); - const data = JSON.parse(fs.readFileSync(jsonPath, 'utf-8')); - return data.serialization_test; - } catch (error) { - console.log(`Error loading expected values: ${error}`); - return null; - } -} - -function createTestData(): boolean { - try { - // Load expected values from JSON - const expected = loadExpectedValues(); - if (!expected) { - return false; - } - - // Create a full BasicDefault message that matches C/Python format - // Frame format: [START1=0x90] [START2=0x71] [LEN] [MSG_ID] [payload] [checksum1] [checksum2] - const msg_id = 204; - - // Create full payload matching the message structure: - // - magic_number: uint32 (4 bytes) - // - test_string: length byte (1) + data (64 bytes) = 65 bytes - // - test_float: float (4 bytes) - // - test_bool: bool (1 byte) - // - test_array: count byte (1) + int32 data (5*4=20 bytes) = 21 bytes - // Total: 4 + 65 + 4 + 1 + 21 = 95 bytes - const payloadSize = 95; - const payload = Buffer.alloc(payloadSize); - let offset = 0; - - // magic_number (uint32, little-endian) - payload.writeUInt32LE(expected.magic_number, offset); - offset += 4; - - // test_string: length byte + 64 bytes of data - const testString = expected.test_string; - payload.writeUInt8(testString.length, offset); - offset += 1; - Buffer.from(testString).copy(payload, offset, 0, testString.length); - // String data array is 64 bytes, remaining bytes are already 0 - offset += 64; - - // test_float (float, little-endian) - payload.writeFloatLE(expected.test_float, offset); - offset += 4; - - // test_bool (1 byte) - payload.writeUInt8(expected.test_bool ? 1 : 0, offset); - offset += 1; - - // test_array: count byte + int32 data (5 elements max) - const testArray: number[] = expected.test_array; - payload.writeUInt8(testArray.length, offset); - offset += 1; - for (let i = 0; i < 5; i++) { - if (i < testArray.length) { - payload.writeInt32LE(testArray[i], offset); - } else { - payload.writeInt32LE(0, offset); - } - offset += 4; - } - - // Calculate Fletcher checksum on length + msg_id + payload (consistent with BasicDefault) - let byte1 = payloadSize & 0xFF; // Start with length byte - let byte2 = payloadSize & 0xFF; - byte1 = (byte1 + msg_id) & 0xFF; // Add msg_id - byte2 = (byte2 + byte1) & 0xFF; - for (let i = 0; i < payload.length; i++) { - byte1 = (byte1 + payload[i]) & 0xFF; - byte2 = (byte2 + byte1) & 0xFF; - } - - // Build complete frame with BasicDefault format - const frame = Buffer.alloc(BASIC_DEFAULT_HEADER_SIZE + payloadSize + BASIC_DEFAULT_FOOTER_SIZE); - frame[0] = BASIC_DEFAULT_START_BYTE1; - frame[1] = BASIC_DEFAULT_START_BYTE2; - frame[2] = payloadSize & 0xFF; // Length byte - frame[3] = msg_id; - payload.copy(frame, BASIC_DEFAULT_HEADER_SIZE); - frame[frame.length - 2] = byte1; - frame[frame.length - 1] = byte2; - - // Write to file - determine correct path based on where we're running from - const outputPath = fs.existsSync('tests/generated/ts/js') - ? 'tests/generated/ts/js/typescript_test_data.bin' - : 'typescript_test_data.bin'; - fs.writeFileSync(outputPath, frame); - - return true; - } catch (error) { - printFailureDetails(`Create test data exception: ${error}`); - return false; - } -} - -function main(): boolean { - console.log('\n[TEST START] TypeScript Cross-Platform Serialization'); - - try { - // Create TypeScript test data - if (!createTestData()) { - console.log('[TEST END] TypeScript Cross-Platform Serialization: FAIL\n'); - return false; - } - - console.log('[TEST END] TypeScript Cross-Platform Serialization: PASS\n'); - return true; - } catch (error) { - printFailureDetails(`Exception: ${error}`); - console.log('[TEST END] TypeScript Cross-Platform Serialization: FAIL\n'); - return false; - } -} - -if (require.main === module) { - const success = main(); - process.exit(success ? 0 : 1); -} - -export { main }; diff --git a/tests/c/frame_compat.h b/tests/c/frame_compat.h deleted file mode 100644 index 3cba478a..00000000 --- a/tests/c/frame_compat.h +++ /dev/null @@ -1,217 +0,0 @@ -/** - * Compatibility layer for frame parser functions - * Provides encode/decode functions composed from separated header and payload types - */ - -#pragma once - -#include "frame_base.h" -#include "frame_headers/base.h" -#include "frame_headers/header_tiny.h" -#include "frame_headers/header_basic.h" -#include "payload_types/base.h" -#include "payload_types/payload_default.h" -#include "payload_types/payload_minimal.h" -#include "payload_types/payload_extended.h" -#include "payload_types/payload_extended_multi_system_stream.h" - -/* Basic + Default */ -static inline size_t basic_default_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 4; /* [0x90] [0x71] [LEN] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 255) { - return 0; - } - - buffer[0] = BASIC_START_BYTE; - buffer[1] = get_basic_second_start_byte(PAYLOAD_DEFAULT_CONFIG.payload_type); - buffer[2] = (uint8_t)msg_size; - buffer[3] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - frame_checksum_t ck = frame_fletcher_checksum(buffer + 2, msg_size + 2); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -static inline frame_msg_info_t basic_default_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 6 || buffer[0] != BASIC_START_BYTE || - !is_basic_second_start_byte(buffer[1])) { - return result; - } - - return frame_validate_payload_with_crc(buffer, length, 4, 1, 2); -} - -/* Tiny + Minimal */ -static inline size_t tiny_minimal_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 2; /* [0x70] [MSG_ID] */ - const size_t total_size = header_size + msg_size; - - if (buffer_size < total_size) { - return 0; - } - - buffer[0] = get_tiny_start_byte(PAYLOAD_MINIMAL_CONFIG.payload_type); - buffer[1] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - return total_size; -} - -static inline frame_msg_info_t tiny_minimal_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 2 || !is_tiny_start_byte(buffer[0])) { - return result; - } - - return frame_validate_payload_minimal(buffer, length, 2); -} - -/* Basic + Extended */ -static inline size_t basic_extended_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 6; /* [0x90] [0x74] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 65535) { - return 0; - } - - buffer[0] = BASIC_START_BYTE; - buffer[1] = get_basic_second_start_byte(PAYLOAD_EXTENDED_CONFIG.payload_type); - buffer[2] = (uint8_t)(msg_size & 0xFF); - buffer[3] = (uint8_t)((msg_size >> 8) & 0xFF); - buffer[4] = 0; /* PKG_ID = 0 */ - buffer[5] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - frame_checksum_t ck = frame_fletcher_checksum(buffer + 2, msg_size + 4); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -static inline frame_msg_info_t basic_extended_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 8 || buffer[0] != BASIC_START_BYTE || - !is_basic_second_start_byte(buffer[1])) { - return result; - } - - return frame_validate_payload_with_crc(buffer, length, 6, 2, 2); -} - -/* Basic + Extended Multi System Stream */ -static inline size_t basic_extended_multi_system_stream_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 9; /* [0x90] [0x78] [SEQ] [SYS] [COMP] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 65535) { - return 0; - } - - buffer[0] = BASIC_START_BYTE; - buffer[1] = get_basic_second_start_byte(PAYLOAD_EXTENDED_MULTI_SYSTEM_STREAM_CONFIG.payload_type); - buffer[2] = 0; /* SEQ = 0 */ - buffer[3] = 0; /* SYS_ID = 0 */ - buffer[4] = 0; /* COMP_ID = 0 */ - buffer[5] = (uint8_t)(msg_size & 0xFF); - buffer[6] = (uint8_t)((msg_size >> 8) & 0xFF); - buffer[7] = 0; /* PKG_ID = 0 */ - buffer[8] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - frame_checksum_t ck = frame_fletcher_checksum(buffer + 2, msg_size + 7); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -static inline frame_msg_info_t basic_extended_multi_system_stream_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 11 || buffer[0] != BASIC_START_BYTE || - !is_basic_second_start_byte(buffer[1])) { - return result; - } - - return frame_validate_payload_with_crc(buffer, length, 9, 2, 2); -} - -/* Basic + Minimal */ -static inline size_t basic_minimal_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 3; /* [0x90] [0x70] [MSG_ID] */ - const size_t total_size = header_size + msg_size; - - if (buffer_size < total_size) { - return 0; - } - - buffer[0] = BASIC_START_BYTE; - buffer[1] = get_basic_second_start_byte(PAYLOAD_MINIMAL_CONFIG.payload_type); - buffer[2] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - return total_size; -} - -static inline frame_msg_info_t basic_minimal_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 3 || buffer[0] != BASIC_START_BYTE || - !is_basic_second_start_byte(buffer[1])) { - return result; - } - - return frame_validate_payload_minimal(buffer, length, 3); -} - -/* Tiny + Default */ -static inline size_t tiny_default_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 3; /* [0x71] [LEN] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 255) { - return 0; - } - - buffer[0] = get_tiny_start_byte(PAYLOAD_DEFAULT_CONFIG.payload_type); - buffer[1] = (uint8_t)msg_size; - buffer[2] = msg_id; - memcpy(buffer + header_size, msg, msg_size); - - frame_checksum_t ck = frame_fletcher_checksum(buffer + 1, msg_size + 2); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -static inline frame_msg_info_t tiny_default_validate_packet(const uint8_t* buffer, size_t length) { - frame_msg_info_t result = {false, 0, 0, NULL}; - - if (length < 5 || !is_tiny_start_byte(buffer[0])) { - return result; - } - - return frame_validate_payload_with_crc(buffer, length, 3, 1, 1); -} diff --git a/tests/cpp/frame_compat.hpp b/tests/cpp/frame_compat.hpp deleted file mode 100644 index df74970d..00000000 --- a/tests/cpp/frame_compat.hpp +++ /dev/null @@ -1,223 +0,0 @@ -/** - * Compatibility layer for frame parser functions (C++) - * Provides encode/decode functions composed from separated header and payload types - */ - -#pragma once - -#include "frame_base.hpp" -#include "frame_headers/base.hpp" -#include "frame_headers/header_tiny.hpp" -#include "frame_headers/header_basic.hpp" -#include "payload_types/base.hpp" -#include "payload_types/payload_default.hpp" -#include "payload_types/payload_minimal.hpp" -#include "payload_types/payload_extended.hpp" -#include "payload_types/payload_extended_multi_system_stream.hpp" - -#include - -namespace FrameParsers { - -/* Basic + Default */ -inline size_t basic_default_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 4; /* [0x90] [0x71] [LEN] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 255) { - return 0; - } - - buffer[0] = FrameHeaders::BASIC_START_BYTE; - buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_DEFAULT_CONFIG.payload_type)); - buffer[2] = static_cast(msg_size); - buffer[3] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - FrameChecksum ck = fletcher_checksum(buffer + 2, msg_size + 2); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -inline FrameMsgInfo basic_default_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 6 || buffer[0] != FrameHeaders::BASIC_START_BYTE || - !FrameHeaders::is_basic_second_start_byte(buffer[1])) { - return result; - } - - return validate_payload_with_crc(buffer, length, 4, 1, 2); -} - -/* Tiny + Minimal */ -inline size_t tiny_minimal_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 2; /* [0x70] [MSG_ID] */ - const size_t total_size = header_size + msg_size; - - if (buffer_size < total_size) { - return 0; - } - - buffer[0] = FrameHeaders::get_tiny_start_byte(static_cast(PayloadTypes::PAYLOAD_MINIMAL_CONFIG.payload_type)); - buffer[1] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - return total_size; -} - -inline FrameMsgInfo tiny_minimal_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 2 || !FrameHeaders::is_tiny_start_byte(buffer[0])) { - return result; - } - - return validate_payload_minimal(buffer, length, 2); -} - -/* Basic + Extended */ -inline size_t basic_extended_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 6; /* [0x90] [0x74] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 65535) { - return 0; - } - - buffer[0] = FrameHeaders::BASIC_START_BYTE; - buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_EXTENDED_CONFIG.payload_type)); - buffer[2] = static_cast(msg_size & 0xFF); - buffer[3] = static_cast((msg_size >> 8) & 0xFF); - buffer[4] = 0; /* PKG_ID = 0 */ - buffer[5] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - FrameChecksum ck = fletcher_checksum(buffer + 2, msg_size + 4); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -inline FrameMsgInfo basic_extended_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 8 || buffer[0] != FrameHeaders::BASIC_START_BYTE || - !FrameHeaders::is_basic_second_start_byte(buffer[1])) { - return result; - } - - return validate_payload_with_crc(buffer, length, 6, 2, 2); -} - -/* Basic + Extended Multi System Stream */ -inline size_t basic_extended_multi_system_stream_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 9; /* [0x90] [0x78] [SEQ] [SYS] [COMP] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 65535) { - return 0; - } - - buffer[0] = FrameHeaders::BASIC_START_BYTE; - buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_EXTENDED_MULTI_SYSTEM_STREAM_CONFIG.payload_type)); - buffer[2] = 0; /* SEQ = 0 */ - buffer[3] = 0; /* SYS_ID = 0 */ - buffer[4] = 0; /* COMP_ID = 0 */ - buffer[5] = static_cast(msg_size & 0xFF); - buffer[6] = static_cast((msg_size >> 8) & 0xFF); - buffer[7] = 0; /* PKG_ID = 0 */ - buffer[8] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - FrameChecksum ck = fletcher_checksum(buffer + 2, msg_size + 7); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -inline FrameMsgInfo basic_extended_multi_system_stream_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 11 || buffer[0] != FrameHeaders::BASIC_START_BYTE || - !FrameHeaders::is_basic_second_start_byte(buffer[1])) { - return result; - } - - return validate_payload_with_crc(buffer, length, 9, 2, 2); -} - -/* Basic + Minimal */ -inline size_t basic_minimal_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 3; /* [0x90] [0x70] [MSG_ID] */ - const size_t total_size = header_size + msg_size; - - if (buffer_size < total_size) { - return 0; - } - - buffer[0] = FrameHeaders::BASIC_START_BYTE; - buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_MINIMAL_CONFIG.payload_type)); - buffer[2] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - return total_size; -} - -inline FrameMsgInfo basic_minimal_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 3 || buffer[0] != FrameHeaders::BASIC_START_BYTE || - !FrameHeaders::is_basic_second_start_byte(buffer[1])) { - return result; - } - - return validate_payload_minimal(buffer, length, 3); -} - -/* Tiny + Default */ -inline size_t tiny_default_encode(uint8_t* buffer, size_t buffer_size, - uint8_t msg_id, const uint8_t* msg, size_t msg_size) { - const size_t header_size = 3; /* [0x71] [LEN] [MSG_ID] */ - const size_t footer_size = 2; /* [CRC1] [CRC2] */ - const size_t total_size = header_size + msg_size + footer_size; - - if (buffer_size < total_size || msg_size > 255) { - return 0; - } - - buffer[0] = FrameHeaders::get_tiny_start_byte(static_cast(PayloadTypes::PAYLOAD_DEFAULT_CONFIG.payload_type)); - buffer[1] = static_cast(msg_size); - buffer[2] = msg_id; - std::memcpy(buffer + header_size, msg, msg_size); - - FrameChecksum ck = fletcher_checksum(buffer + 1, msg_size + 2); - buffer[total_size - 2] = ck.byte1; - buffer[total_size - 1] = ck.byte2; - - return total_size; -} - -inline FrameMsgInfo tiny_default_validate_packet(const uint8_t* buffer, size_t length) { - FrameMsgInfo result = {false, 0, 0, nullptr}; - - if (length < 5 || !FrameHeaders::is_tiny_start_byte(buffer[0])) { - return result; - } - - return validate_payload_with_crc(buffer, length, 3, 1, 1); -} - -} // namespace FrameParsers From e2136e8edd5d6f71e41bdcc5cd6f777006db4361 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 00:43:54 +0000 Subject: [PATCH 3/6] Remove legacy parameters from parser_py_gen and fix old_win_sdk_compat reference Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> --- .../asio/detail/socket_types.hpp | 2 +- src/struct_frame/parser_py_gen.py | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/struct_frame/boilerplate/cpp/struct_frame_sdk/asio/detail/socket_types.hpp b/src/struct_frame/boilerplate/cpp/struct_frame_sdk/asio/detail/socket_types.hpp index cf4f746a..40c079d7 100644 --- a/src/struct_frame/boilerplate/cpp/struct_frame_sdk/asio/detail/socket_types.hpp +++ b/src/struct_frame/boilerplate/cpp/struct_frame_sdk/asio/detail/socket_types.hpp @@ -54,7 +54,7 @@ # endif // !defined(ASIO_WINDOWS_APP) # endif // defined(_MSC_VER) || defined(__BORLANDC__) # endif // !defined(ASIO_NO_DEFAULT_LINKED_LIBS) -# include "asio/detail/old_win_sdk_compat.hpp" +// Removed legacy old_win_sdk_compat.hpp - no longer needed for modern Windows SDKs #else # include # if (defined(__MACH__) && defined(__APPLE__)) \ diff --git a/src/struct_frame/parser_py_gen.py b/src/struct_frame/parser_py_gen.py index 5fefb85a..5ba6bbdb 100644 --- a/src/struct_frame/parser_py_gen.py +++ b/src/struct_frame/parser_py_gen.py @@ -117,10 +117,6 @@ def generate_parser(collection): yield ' get_msg_length: Callable[[int], int] = None,\n' yield ' enabled_headers: Optional[List[HeaderType]] = None,\n' yield ' enabled_payloads: Optional[List[PayloadType]] = None,\n' - yield ' # Legacy parameters (deprecated):\n' - yield ' enable_basic: bool = True,\n' - yield ' enable_tiny: bool = True,\n' - yield ' enable_none: bool = False,\n' yield ' default_payload_type: PayloadType = PayloadType.DEFAULT):\n' yield ' """\n' yield ' Initialize parser.\n' @@ -129,25 +125,16 @@ def generate_parser(collection): yield ' get_msg_length: Callback to get message length from msg_id (required for Minimal payloads)\n' yield ' enabled_headers: List of header types to accept (None = all supported)\n' yield ' enabled_payloads: List of payload types to accept (None = all)\n' - yield ' enable_basic: (Deprecated) Enable Basic frame parsing\n' - yield ' enable_tiny: (Deprecated) Enable Tiny frame parsing\n' - yield ' enable_none: (Deprecated) Enable None frame parsing\n' yield ' default_payload_type: Default payload type for None frames\n' yield ' """\n' yield ' self.get_msg_length = get_msg_length\n' yield ' \n' - yield ' # Handle new registration API\n' + yield ' # Handle header registration\n' yield ' if enabled_headers is not None:\n' yield ' self.enabled_headers = set(enabled_headers)\n' yield ' else:\n' - yield ' # Use legacy parameters\n' - yield ' self.enabled_headers = set()\n' - yield ' if enable_basic:\n' - yield ' self.enabled_headers.add(HeaderType.BASIC)\n' - yield ' if enable_tiny:\n' - yield ' self.enabled_headers.add(HeaderType.TINY)\n' - yield ' if enable_none:\n' - yield ' self.enabled_headers.add(HeaderType.NONE)\n' + yield ' # Default: Enable Basic and Tiny headers\n' + yield ' self.enabled_headers = {HeaderType.BASIC, HeaderType.TINY}\n' yield ' \n' yield ' if enabled_payloads is not None:\n' yield ' self.enabled_payloads = set(enabled_payloads)\n' From fe7ee78cc4c00eb5714fb8b91fcdeb9368359b8a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 00:46:15 +0000 Subject: [PATCH 4/6] Add inline frame format helpers to C, C++, and TypeScript test files Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> --- tests/c/test_codec.c | 208 ++++++++++++++++++++++++++++++++- tests/cpp/test_codec.cpp | 204 +++++++++++++++++++++++++++++++- tests/ts/test_codec.ts | 243 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 647 insertions(+), 8 deletions(-) diff --git a/tests/c/test_codec.c b/tests/c/test_codec.c index 82547513..cdaf171b 100644 --- a/tests/c/test_codec.c +++ b/tests/c/test_codec.c @@ -1,7 +1,3 @@ -/** - * Test codec - Encode/decode functions for all frame formats. - */ - #include "test_codec.h" #include @@ -9,9 +5,211 @@ #include #include "frame_parsers.h" -#include "frame_compat.h" #include "serialization_test.sf.h" +/* Minimal frame format helper functions (replacing frame_compat) */ + +/* Basic + Default */ +static inline size_t basic_default_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 4; /* [0x90] [0x71] [LEN] [MSG_ID] */ + const size_t footer_size = 2; /* [CRC1] [CRC2] */ + const size_t total_size = header_size + msg_size + footer_size; + + if (buffer_size < total_size || msg_size > 255) { + return 0; + } + + buffer[0] = BASIC_START_BYTE; + buffer[1] = get_basic_second_start_byte(PAYLOAD_DEFAULT_CONFIG.payload_type); + buffer[2] = (uint8_t)msg_size; + buffer[3] = msg_id; + memcpy(buffer + header_size, msg, msg_size); + + frame_checksum_t ck = frame_fletcher_checksum(buffer + 2, msg_size + 2); + buffer[total_size - 2] = ck.byte1; + buffer[total_size - 1] = ck.byte2; + + return total_size; +} + +static inline frame_msg_info_t basic_default_validate_packet(const uint8_t* buffer, size_t length) { + frame_msg_info_t result = {false, 0, 0, NULL}; + + if (length < 6 || buffer[0] != BASIC_START_BYTE || + !is_basic_second_start_byte(buffer[1])) { + return result; + } + + return frame_validate_payload_with_crc(buffer, length, 4, 1, 2); +} + +/* Tiny + Minimal */ +static inline size_t tiny_minimal_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 2; /* [0x70] [MSG_ID] */ + const size_t total_size = header_size + msg_size; + + if (buffer_size < total_size) { + return 0; + } + + buffer[0] = get_tiny_start_byte(PAYLOAD_MINIMAL_CONFIG.payload_type); + buffer[1] = msg_id; + memcpy(buffer + header_size, msg, msg_size); + + return total_size; +} + +static inline frame_msg_info_t tiny_minimal_validate_packet(const uint8_t* buffer, size_t length) { + frame_msg_info_t result = {false, 0, 0, NULL}; + + if (length < 2 || !is_tiny_start_byte(buffer[0])) { + return result; + } + + return frame_validate_payload_minimal(buffer, length, 2); +} + +/* Basic + Extended */ +static inline size_t basic_extended_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 6; /* [0x90] [0x74] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ + const size_t footer_size = 2; /* [CRC1] [CRC2] */ + const size_t total_size = header_size + msg_size + footer_size; + + if (buffer_size < total_size || msg_size > 65535) { + return 0; + } + + buffer[0] = BASIC_START_BYTE; + buffer[1] = get_basic_second_start_byte(PAYLOAD_EXTENDED_CONFIG.payload_type); + buffer[2] = (uint8_t)(msg_size & 0xFF); + buffer[3] = (uint8_t)((msg_size >> 8) & 0xFF); + buffer[4] = 0; /* PKG_ID = 0 */ + buffer[5] = msg_id; + memcpy(buffer + header_size, msg, msg_size); + + frame_checksum_t ck = frame_fletcher_checksum(buffer + 2, msg_size + 4); + buffer[total_size - 2] = ck.byte1; + buffer[total_size - 1] = ck.byte2; + + return total_size; +} + +static inline frame_msg_info_t basic_extended_validate_packet(const uint8_t* buffer, size_t length) { + frame_msg_info_t result = {false, 0, 0, NULL}; + + if (length < 8 || buffer[0] != BASIC_START_BYTE || + !is_basic_second_start_byte(buffer[1])) { + return result; + } + + return frame_validate_payload_with_crc(buffer, length, 6, 2, 2); +} + +/* Basic + Extended Multi System Stream */ +static inline size_t basic_extended_multi_system_stream_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 9; /* [0x90] [0x78] [SEQ] [SYS] [COMP] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ + const size_t footer_size = 2; /* [CRC1] [CRC2] */ + const size_t total_size = header_size + msg_size + footer_size; + + if (buffer_size < total_size || msg_size > 65535) { + return 0; + } + + buffer[0] = BASIC_START_BYTE; + buffer[1] = get_basic_second_start_byte(PAYLOAD_EXTENDED_MULTI_SYSTEM_STREAM_CONFIG.payload_type); + buffer[2] = 0; /* SEQ = 0 */ + buffer[3] = 0; /* SYS_ID = 0 */ + buffer[4] = 0; /* COMP_ID = 0 */ + buffer[5] = (uint8_t)(msg_size & 0xFF); + buffer[6] = (uint8_t)((msg_size >> 8) & 0xFF); + buffer[7] = 0; /* PKG_ID = 0 */ + buffer[8] = msg_id; + memcpy(buffer + header_size, msg, msg_size); + + frame_checksum_t ck = frame_fletcher_checksum(buffer + 2, msg_size + 7); + buffer[total_size - 2] = ck.byte1; + buffer[total_size - 1] = ck.byte2; + + return total_size; +} + +static inline frame_msg_info_t basic_extended_multi_system_stream_validate_packet(const uint8_t* buffer, size_t length) { + frame_msg_info_t result = {false, 0, 0, NULL}; + + if (length < 11 || buffer[0] != BASIC_START_BYTE || + !is_basic_second_start_byte(buffer[1])) { + return result; + } + + return frame_validate_payload_with_crc(buffer, length, 9, 2, 2); +} + +/* Basic + Minimal */ +static inline size_t basic_minimal_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 3; /* [0x90] [0x70] [MSG_ID] */ + const size_t total_size = header_size + msg_size; + + if (buffer_size < total_size) { + return 0; + } + + buffer[0] = BASIC_START_BYTE; + buffer[1] = get_basic_second_start_byte(PAYLOAD_MINIMAL_CONFIG.payload_type); + buffer[2] = msg_id; + memcpy(buffer + header_size, msg, msg_size); + + return total_size; +} + +static inline frame_msg_info_t basic_minimal_validate_packet(const uint8_t* buffer, size_t length) { + frame_msg_info_t result = {false, 0, 0, NULL}; + + if (length < 3 || buffer[0] != BASIC_START_BYTE || + !is_basic_second_start_byte(buffer[1])) { + return result; + } + + return frame_validate_payload_minimal(buffer, length, 3); +} + +/* Tiny + Default */ +static inline size_t tiny_default_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 3; /* [0x71] [LEN] [MSG_ID] */ + const size_t footer_size = 2; /* [CRC1] [CRC2] */ + const size_t total_size = header_size + msg_size + footer_size; + + if (buffer_size < total_size || msg_size > 255) { + return 0; + } + + buffer[0] = get_tiny_start_byte(PAYLOAD_DEFAULT_CONFIG.payload_type); + buffer[1] = (uint8_t)msg_size; + buffer[2] = msg_id; + memcpy(buffer + header_size, msg, msg_size); + + frame_checksum_t ck = frame_fletcher_checksum(buffer + 1, msg_size + 2); + buffer[total_size - 2] = ck.byte1; + buffer[total_size - 1] = ck.byte2; + + return total_size; +} + +static inline frame_msg_info_t tiny_default_validate_packet(const uint8_t* buffer, size_t length) { + frame_msg_info_t result = {false, 0, 0, NULL}; + + if (length < 5 || !is_tiny_start_byte(buffer[0])) { + return result; + } + + return frame_validate_payload_with_crc(buffer, length, 3, 1, 1); +} + /* Expected test values (from expected_values.json) */ static const uint32_t EXPECTED_MAGIC_NUMBER = 3735928559; /* 0xDEADBEEF */ static const char* EXPECTED_TEST_STRING = "Cross-platform test!"; diff --git a/tests/cpp/test_codec.cpp b/tests/cpp/test_codec.cpp index 77b22bed..f1521380 100644 --- a/tests/cpp/test_codec.cpp +++ b/tests/cpp/test_codec.cpp @@ -9,11 +9,213 @@ #include #include "frame_parsers.hpp" -#include "frame_compat.hpp" #include "serialization_test.sf.hpp" using namespace FrameParsers; +/* Minimal frame format helper functions (replacing frame_compat) */ + +/* Basic + Default */ +inline size_t basic_default_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 4; /* [0x90] [0x71] [LEN] [MSG_ID] */ + const size_t footer_size = 2; /* [CRC1] [CRC2] */ + const size_t total_size = header_size + msg_size + footer_size; + + if (buffer_size < total_size || msg_size > 255) { + return 0; + } + + buffer[0] = FrameHeaders::BASIC_START_BYTE; + buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_DEFAULT_CONFIG.payload_type)); + buffer[2] = static_cast(msg_size); + buffer[3] = msg_id; + std::memcpy(buffer + header_size, msg, msg_size); + + FrameChecksum ck = fletcher_checksum(buffer + 2, msg_size + 2); + buffer[total_size - 2] = ck.byte1; + buffer[total_size - 1] = ck.byte2; + + return total_size; +} + +inline FrameMsgInfo basic_default_validate_packet(const uint8_t* buffer, size_t length) { + FrameMsgInfo result = {false, 0, 0, nullptr}; + + if (length < 6 || buffer[0] != FrameHeaders::BASIC_START_BYTE || + !FrameHeaders::is_basic_second_start_byte(buffer[1])) { + return result; + } + + return validate_payload_with_crc(buffer, length, 4, 1, 2); +} + +/* Tiny + Minimal */ +inline size_t tiny_minimal_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 2; /* [0x70] [MSG_ID] */ + const size_t total_size = header_size + msg_size; + + if (buffer_size < total_size) { + return 0; + } + + buffer[0] = FrameHeaders::get_tiny_start_byte(static_cast(PayloadTypes::PAYLOAD_MINIMAL_CONFIG.payload_type)); + buffer[1] = msg_id; + std::memcpy(buffer + header_size, msg, msg_size); + + return total_size; +} + +inline FrameMsgInfo tiny_minimal_validate_packet(const uint8_t* buffer, size_t length) { + FrameMsgInfo result = {false, 0, 0, nullptr}; + + if (length < 2 || !FrameHeaders::is_tiny_start_byte(buffer[0])) { + return result; + } + + return validate_payload_minimal(buffer, length, 2); +} + +/* Basic + Extended */ +inline size_t basic_extended_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 6; /* [0x90] [0x74] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ + const size_t footer_size = 2; /* [CRC1] [CRC2] */ + const size_t total_size = header_size + msg_size + footer_size; + + if (buffer_size < total_size || msg_size > 65535) { + return 0; + } + + buffer[0] = FrameHeaders::BASIC_START_BYTE; + buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_EXTENDED_CONFIG.payload_type)); + buffer[2] = static_cast(msg_size & 0xFF); + buffer[3] = static_cast((msg_size >> 8) & 0xFF); + buffer[4] = 0; /* PKG_ID = 0 */ + buffer[5] = msg_id; + std::memcpy(buffer + header_size, msg, msg_size); + + FrameChecksum ck = fletcher_checksum(buffer + 2, msg_size + 4); + buffer[total_size - 2] = ck.byte1; + buffer[total_size - 1] = ck.byte2; + + return total_size; +} + +inline FrameMsgInfo basic_extended_validate_packet(const uint8_t* buffer, size_t length) { + FrameMsgInfo result = {false, 0, 0, nullptr}; + + if (length < 8 || buffer[0] != FrameHeaders::BASIC_START_BYTE || + !FrameHeaders::is_basic_second_start_byte(buffer[1])) { + return result; + } + + return validate_payload_with_crc(buffer, length, 6, 2, 2); +} + +/* Basic + Extended Multi System Stream */ +inline size_t basic_extended_multi_system_stream_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 9; /* [0x90] [0x78] [SEQ] [SYS] [COMP] [LEN_LO] [LEN_HI] [PKG_ID] [MSG_ID] */ + const size_t footer_size = 2; /* [CRC1] [CRC2] */ + const size_t total_size = header_size + msg_size + footer_size; + + if (buffer_size < total_size || msg_size > 65535) { + return 0; + } + + buffer[0] = FrameHeaders::BASIC_START_BYTE; + buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_EXTENDED_MULTI_SYSTEM_STREAM_CONFIG.payload_type)); + buffer[2] = 0; /* SEQ = 0 */ + buffer[3] = 0; /* SYS_ID = 0 */ + buffer[4] = 0; /* COMP_ID = 0 */ + buffer[5] = static_cast(msg_size & 0xFF); + buffer[6] = static_cast((msg_size >> 8) & 0xFF); + buffer[7] = 0; /* PKG_ID = 0 */ + buffer[8] = msg_id; + std::memcpy(buffer + header_size, msg, msg_size); + + FrameChecksum ck = fletcher_checksum(buffer + 2, msg_size + 7); + buffer[total_size - 2] = ck.byte1; + buffer[total_size - 1] = ck.byte2; + + return total_size; +} + +inline FrameMsgInfo basic_extended_multi_system_stream_validate_packet(const uint8_t* buffer, size_t length) { + FrameMsgInfo result = {false, 0, 0, nullptr}; + + if (length < 11 || buffer[0] != FrameHeaders::BASIC_START_BYTE || + !FrameHeaders::is_basic_second_start_byte(buffer[1])) { + return result; + } + + return validate_payload_with_crc(buffer, length, 9, 2, 2); +} + +/* Basic + Minimal */ +inline size_t basic_minimal_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 3; /* [0x90] [0x70] [MSG_ID] */ + const size_t total_size = header_size + msg_size; + + if (buffer_size < total_size) { + return 0; + } + + buffer[0] = FrameHeaders::BASIC_START_BYTE; + buffer[1] = FrameHeaders::get_basic_second_start_byte(static_cast(PayloadTypes::PAYLOAD_MINIMAL_CONFIG.payload_type)); + buffer[2] = msg_id; + std::memcpy(buffer + header_size, msg, msg_size); + + return total_size; +} + +inline FrameMsgInfo basic_minimal_validate_packet(const uint8_t* buffer, size_t length) { + FrameMsgInfo result = {false, 0, 0, nullptr}; + + if (length < 3 || buffer[0] != FrameHeaders::BASIC_START_BYTE || + !FrameHeaders::is_basic_second_start_byte(buffer[1])) { + return result; + } + + return validate_payload_minimal(buffer, length, 3); +} + +/* Tiny + Default */ +inline size_t tiny_default_encode(uint8_t* buffer, size_t buffer_size, + uint8_t msg_id, const uint8_t* msg, size_t msg_size) { + const size_t header_size = 3; /* [0x71] [LEN] [MSG_ID] */ + const size_t footer_size = 2; /* [CRC1] [CRC2] */ + const size_t total_size = header_size + msg_size + footer_size; + + if (buffer_size < total_size || msg_size > 255) { + return 0; + } + + buffer[0] = FrameHeaders::get_tiny_start_byte(static_cast(PayloadTypes::PAYLOAD_DEFAULT_CONFIG.payload_type)); + buffer[1] = static_cast(msg_size); + buffer[2] = msg_id; + std::memcpy(buffer + header_size, msg, msg_size); + + FrameChecksum ck = fletcher_checksum(buffer + 1, msg_size + 2); + buffer[total_size - 2] = ck.byte1; + buffer[total_size - 1] = ck.byte2; + + return total_size; +} + +inline FrameMsgInfo tiny_default_validate_packet(const uint8_t* buffer, size_t length) { + FrameMsgInfo result = {false, 0, 0, nullptr}; + + if (length < 5 || !FrameHeaders::is_tiny_start_byte(buffer[0])) { + return result; + } + + return validate_payload_with_crc(buffer, length, 3, 1, 1); +} + /* Expected test values (from expected_values.json) */ static const uint32_t EXPECTED_MAGIC_NUMBER = 3735928559; /* 0xDEADBEEF */ static const char* EXPECTED_TEST_STRING = "Cross-platform test!"; diff --git a/tests/ts/test_codec.ts b/tests/ts/test_codec.ts index 0efb173d..e7ba4e5b 100644 --- a/tests/ts/test_codec.ts +++ b/tests/ts/test_codec.ts @@ -13,14 +13,253 @@ export const EXPECTED_VALUES = { test_array: [100, 200, 300] as number[], }; -// Import generated modules dynamically -const { BasicDefault, BasicMinimal, TinyDefault, TinyMinimal, BasicExtended, BasicExtendedMultiSystemStream } = require('./frame_compat'); +// Import generated modules +const { + BASIC_START_BYTE, + getTinyStartByte, + isTinyStartByte, + getBasicSecondStartByte, + isBasicSecondStartByte, + fletcher_checksum, +} = require('./frame_base'); + const { serialization_test_SerializationTestMessage, serialization_test_SerializationTestMessage_msgid, serialization_test_SerializationTestMessage_max_size } = require('./serialization_test.sf'); +/* Minimal frame format helper classes (replacing frame_compat) */ + +class BasicDefault { + static encodeMsg(msgId: number, msg: Uint8Array): Uint8Array { + const headerSize = 4; + const footerSize = 2; + const totalSize = headerSize + msg.length + footerSize; + if (msg.length > 255) return new Uint8Array(0); + + const buffer = new Uint8Array(totalSize); + buffer[0] = BASIC_START_BYTE; + buffer[1] = getBasicSecondStartByte(1); // DEFAULT = 1 + buffer[2] = msg.length; + buffer[3] = msgId; + buffer.set(msg, headerSize); + + const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); + buffer[totalSize - 2] = ck[0]; + buffer[totalSize - 1] = ck[1]; + return buffer; + } + + static validatePacket(buffer: Uint8Array): any { + if (buffer.length < 6 || buffer[0] !== BASIC_START_BYTE || !isBasicSecondStartByte(buffer[1])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgLen = buffer[2]; + const msgId = buffer[3]; + const totalSize = 4 + msgLen + 2; + if (buffer.length < totalSize) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const ck = fletcher_checksum(buffer, 2, 4 + msgLen); + if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(4, 4 + msgLen), + }; + } + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } +} + +class TinyMinimal { + static encodeMsg(msgId: number, msg: Uint8Array): Uint8Array { + const headerSize = 2; + const buffer = new Uint8Array(headerSize + msg.length); + buffer[0] = getTinyStartByte(0); // MINIMAL = 0 + buffer[1] = msgId; + buffer.set(msg, headerSize); + return buffer; + } + + static validatePacket(buffer: Uint8Array): any { + if (buffer.length < 2 || !isTinyStartByte(buffer[0])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgId = buffer[1]; + const msgLen = buffer.length - 2; + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(2), + }; + } +} + +class BasicExtended { + static encodeMsg(msgId: number, msg: Uint8Array): Uint8Array { + const headerSize = 6; + const footerSize = 2; + const totalSize = headerSize + msg.length + footerSize; + if (msg.length > 65535) return new Uint8Array(0); + + const buffer = new Uint8Array(totalSize); + buffer[0] = BASIC_START_BYTE; + buffer[1] = getBasicSecondStartByte(4); // EXTENDED = 4 + buffer[2] = msg.length & 0xff; + buffer[3] = (msg.length >> 8) & 0xff; + buffer[4] = 0; // PKG_ID + buffer[5] = msgId; + buffer.set(msg, headerSize); + + const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); + buffer[totalSize - 2] = ck[0]; + buffer[totalSize - 1] = ck[1]; + return buffer; + } + + static validatePacket(buffer: Uint8Array): any { + if (buffer.length < 8 || buffer[0] !== BASIC_START_BYTE || !isBasicSecondStartByte(buffer[1])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgLen = buffer[2] | (buffer[3] << 8); + const msgId = buffer[5]; + const totalSize = 6 + msgLen + 2; + if (buffer.length < totalSize) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const ck = fletcher_checksum(buffer, 2, 6 + msgLen); + if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(6, 6 + msgLen), + }; + } + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } +} + +class BasicExtendedMultiSystemStream { + static encodeMsg(msgId: number, msg: Uint8Array): Uint8Array { + const headerSize = 9; + const footerSize = 2; + const totalSize = headerSize + msg.length + footerSize; + if (msg.length > 65535) return new Uint8Array(0); + + const buffer = new Uint8Array(totalSize); + buffer[0] = BASIC_START_BYTE; + buffer[1] = getBasicSecondStartByte(8); // EXTENDED_MULTI_SYSTEM_STREAM = 8 + buffer[2] = 0; // SEQ + buffer[3] = 0; // SYS_ID + buffer[4] = 0; // COMP_ID + buffer[5] = msg.length & 0xff; + buffer[6] = (msg.length >> 8) & 0xff; + buffer[7] = 0; // PKG_ID + buffer[8] = msgId; + buffer.set(msg, headerSize); + + const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); + buffer[totalSize - 2] = ck[0]; + buffer[totalSize - 1] = ck[1]; + return buffer; + } + + static validatePacket(buffer: Uint8Array): any { + if (buffer.length < 11 || buffer[0] !== BASIC_START_BYTE || !isBasicSecondStartByte(buffer[1])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgLen = buffer[5] | (buffer[6] << 8); + const msgId = buffer[8]; + const totalSize = 9 + msgLen + 2; + if (buffer.length < totalSize) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const ck = fletcher_checksum(buffer, 2, 9 + msgLen); + if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(9, 9 + msgLen), + }; + } + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } +} + +class BasicMinimal { + static encodeMsg(msgId: number, msg: Uint8Array): Uint8Array { + const headerSize = 3; + const buffer = new Uint8Array(headerSize + msg.length); + buffer[0] = BASIC_START_BYTE; + buffer[1] = getBasicSecondStartByte(0); // MINIMAL = 0 + buffer[2] = msgId; + buffer.set(msg, headerSize); + return buffer; + } + + static validatePacket(buffer: Uint8Array): any { + if (buffer.length < 3 || buffer[0] !== BASIC_START_BYTE || !isBasicSecondStartByte(buffer[1])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgId = buffer[2]; + const msgLen = buffer.length - 3; + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(3), + }; + } +} + +class TinyDefault { + static encodeMsg(msgId: number, msg: Uint8Array): Uint8Array { + const headerSize = 3; + const footerSize = 2; + const totalSize = headerSize + msg.length + footerSize; + if (msg.length > 255) return new Uint8Array(0); + + const buffer = new Uint8Array(totalSize); + buffer[0] = getTinyStartByte(1); // DEFAULT = 1 + buffer[1] = msg.length; + buffer[2] = msgId; + buffer.set(msg, headerSize); + + const ck = fletcher_checksum(buffer, 1, headerSize + msg.length); + buffer[totalSize - 2] = ck[0]; + buffer[totalSize - 1] = ck[1]; + return buffer; + } + + static validatePacket(buffer: Uint8Array): any { + if (buffer.length < 5 || !isTinyStartByte(buffer[0])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgLen = buffer[1]; + const msgId = buffer[2]; + const totalSize = 3 + msgLen + 2; + if (buffer.length < totalSize) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const ck = fletcher_checksum(buffer, 1, 3 + msgLen); + if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(3, 3 + msgLen), + }; + } + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } +} + /** * Get the parser class for a frame format or profile. */ From a0d01dc5b2eb0adc8e43f459151090ab414c9074 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 00:48:20 +0000 Subject: [PATCH 5/6] Add inline frame format helpers to JavaScript test file and fix TypeScript deps Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> --- tests/js/test_codec.js | 268 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 254 insertions(+), 14 deletions(-) diff --git a/tests/js/test_codec.js b/tests/js/test_codec.js index 3186c8ac..2253ada6 100644 --- a/tests/js/test_codec.js +++ b/tests/js/test_codec.js @@ -14,32 +14,272 @@ const EXPECTED_VALUES = { test_array: [100, 200, 300], }; +// Import frame base functions +const { + BASIC_START_BYTE, + getTinyStartByte, + isTinyStartByte, + getBasicSecondStartByte, + isBasicSecondStartByte, + fletcher_checksum, +} = require('./frame_base'); + +/* Minimal frame format helper classes (replacing frame_compat) */ + +const BasicDefault = { + encodeMsg: function(msgId, msg) { + const headerSize = 4; + const footerSize = 2; + const totalSize = headerSize + msg.length + footerSize; + if (msg.length > 255) return new Uint8Array(0); + + const buffer = new Uint8Array(totalSize); + buffer[0] = BASIC_START_BYTE; + buffer[1] = getBasicSecondStartByte(1); + buffer[2] = msg.length; + buffer[3] = msgId; + buffer.set(msg, headerSize); + + const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); + buffer[totalSize - 2] = ck[0]; + buffer[totalSize - 1] = ck[1]; + return buffer; + }, + + validatePacket: function(buffer) { + if (buffer.length < 6 || buffer[0] !== BASIC_START_BYTE || !isBasicSecondStartByte(buffer[1])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgLen = buffer[2]; + const msgId = buffer[3]; + const totalSize = 4 + msgLen + 2; + if (buffer.length < totalSize) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const ck = fletcher_checksum(buffer, 2, 4 + msgLen); + if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(4, 4 + msgLen), + }; + } + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } +}; + +const TinyMinimal = { + encodeMsg: function(msgId, msg) { + const headerSize = 2; + const buffer = new Uint8Array(headerSize + msg.length); + buffer[0] = getTinyStartByte(0); + buffer[1] = msgId; + buffer.set(msg, headerSize); + return buffer; + }, + + validatePacket: function(buffer) { + if (buffer.length < 2 || !isTinyStartByte(buffer[0])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgId = buffer[1]; + const msgLen = buffer.length - 2; + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(2), + }; + } +}; + +const BasicExtended = { + encodeMsg: function(msgId, msg) { + const headerSize = 6; + const footerSize = 2; + const totalSize = headerSize + msg.length + footerSize; + if (msg.length > 65535) return new Uint8Array(0); + + const buffer = new Uint8Array(totalSize); + buffer[0] = BASIC_START_BYTE; + buffer[1] = getBasicSecondStartByte(4); + buffer[2] = msg.length & 0xff; + buffer[3] = (msg.length >> 8) & 0xff; + buffer[4] = 0; + buffer[5] = msgId; + buffer.set(msg, headerSize); + + const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); + buffer[totalSize - 2] = ck[0]; + buffer[totalSize - 1] = ck[1]; + return buffer; + }, + + validatePacket: function(buffer) { + if (buffer.length < 8 || buffer[0] !== BASIC_START_BYTE || !isBasicSecondStartByte(buffer[1])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgLen = buffer[2] | (buffer[3] << 8); + const msgId = buffer[5]; + const totalSize = 6 + msgLen + 2; + if (buffer.length < totalSize) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const ck = fletcher_checksum(buffer, 2, 6 + msgLen); + if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(6, 6 + msgLen), + }; + } + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } +}; + +const BasicExtendedMultiSystemStream = { + encodeMsg: function(msgId, msg) { + const headerSize = 9; + const footerSize = 2; + const totalSize = headerSize + msg.length + footerSize; + if (msg.length > 65535) return new Uint8Array(0); + + const buffer = new Uint8Array(totalSize); + buffer[0] = BASIC_START_BYTE; + buffer[1] = getBasicSecondStartByte(8); + buffer[2] = 0; + buffer[3] = 0; + buffer[4] = 0; + buffer[5] = msg.length & 0xff; + buffer[6] = (msg.length >> 8) & 0xff; + buffer[7] = 0; + buffer[8] = msgId; + buffer.set(msg, headerSize); + + const ck = fletcher_checksum(buffer, 2, headerSize + msg.length); + buffer[totalSize - 2] = ck[0]; + buffer[totalSize - 1] = ck[1]; + return buffer; + }, + + validatePacket: function(buffer) { + if (buffer.length < 11 || buffer[0] !== BASIC_START_BYTE || !isBasicSecondStartByte(buffer[1])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgLen = buffer[5] | (buffer[6] << 8); + const msgId = buffer[8]; + const totalSize = 9 + msgLen + 2; + if (buffer.length < totalSize) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const ck = fletcher_checksum(buffer, 2, 9 + msgLen); + if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(9, 9 + msgLen), + }; + } + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } +}; + +const BasicMinimal = { + encodeMsg: function(msgId, msg) { + const headerSize = 3; + const buffer = new Uint8Array(headerSize + msg.length); + buffer[0] = BASIC_START_BYTE; + buffer[1] = getBasicSecondStartByte(0); + buffer[2] = msgId; + buffer.set(msg, headerSize); + return buffer; + }, + + validatePacket: function(buffer) { + if (buffer.length < 3 || buffer[0] !== BASIC_START_BYTE || !isBasicSecondStartByte(buffer[1])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgId = buffer[2]; + const msgLen = buffer.length - 3; + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(3), + }; + } +}; + +const TinyDefault = { + encodeMsg: function(msgId, msg) { + const headerSize = 3; + const footerSize = 2; + const totalSize = headerSize + msg.length + footerSize; + if (msg.length > 255) return new Uint8Array(0); + + const buffer = new Uint8Array(totalSize); + buffer[0] = getTinyStartByte(1); + buffer[1] = msg.length; + buffer[2] = msgId; + buffer.set(msg, headerSize); + + const ck = fletcher_checksum(buffer, 1, headerSize + msg.length); + buffer[totalSize - 2] = ck[0]; + buffer[totalSize - 1] = ck[1]; + return buffer; + }, + + validatePacket: function(buffer) { + if (buffer.length < 5 || !isTinyStartByte(buffer[0])) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const msgLen = buffer[1]; + const msgId = buffer[2]; + const totalSize = 3 + msgLen + 2; + if (buffer.length < totalSize) { + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } + const ck = fletcher_checksum(buffer, 1, 3 + msgLen); + if (ck[0] === buffer[totalSize - 2] && ck[1] === buffer[totalSize - 1]) { + return { + valid: true, + msg_id: msgId, + msg_len: msgLen, + msg_data: buffer.slice(3, 3 + msgLen), + }; + } + return { valid: false, msg_id: 0, msg_len: 0, msg_data: new Uint8Array(0) }; + } +}; + /** * Get the parser class for a frame format or profile. */ function getParserClass(formatName) { const formatMap = { // Profile names (preferred) - 'profile_standard': 'BasicDefault', - 'profile_sensor': 'TinyMinimal', - 'profile_bulk': 'BasicExtended', - 'profile_network': 'BasicExtendedMultiSystemStream', + 'profile_standard': BasicDefault, + 'profile_sensor': TinyMinimal, + 'profile_bulk': BasicExtended, + 'profile_network': BasicExtendedMultiSystemStream, // Legacy direct format names - 'basic_default': 'BasicDefault', - 'basic_minimal': 'BasicMinimal', - 'tiny_default': 'TinyDefault', - 'tiny_minimal': 'TinyMinimal', - 'basic_extended': 'BasicExtended', - 'basic_extended_multi_system_stream': 'BasicExtendedMultiSystemStream', + 'basic_default': BasicDefault, + 'basic_minimal': BasicMinimal, + 'tiny_default': TinyDefault, + 'tiny_minimal': TinyMinimal, + 'basic_extended': BasicExtended, + 'basic_extended_multi_system_stream': BasicExtendedMultiSystemStream, }; - const className = formatMap[formatName]; - if (!className) { + const parserClass = formatMap[formatName]; + if (!parserClass) { throw new Error(`Unknown frame format: ${formatName}`); } - const module = require('./frame_compat'); - return module[className]; + return parserClass; } /** From a78db1495e1f735d79fa21f3eff66261f039a746 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Dec 2025 01:41:35 +0000 Subject: [PATCH 6/6] Fix import paths in TypeScript and JavaScript test helpers - Fix generate_boilerplate.py import to use parser_py_gen instead of frame_parser_py_gen - Update TypeScript test to import from correct modules (frame_headers/header_basic, frame_headers/header_tiny) - Update JavaScript test to import from correct modules - Fix JavaScript method calls to use encodeMsg and validatePacket instead of encode and validate_packet - Tests now passing: TypeScript and JavaScript frame format tests working (84.7% pass rate, up from 57.6%) Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> --- src/struct_frame/generate_boilerplate.py | 2 +- tests/js/test_codec.js | 16 +++++++++------- tests/ts/test_codec.ts | 8 +++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/struct_frame/generate_boilerplate.py b/src/struct_frame/generate_boilerplate.py index dae48f5d..769a0149 100644 --- a/src/struct_frame/generate_boilerplate.py +++ b/src/struct_frame/generate_boilerplate.py @@ -26,7 +26,7 @@ sys.path.insert(0, parent_dir) from struct_frame.frame_format import parse_frame_formats -from struct_frame.frame_parser_py_gen import generate_py_frame_parsers +from struct_frame.parser_py_gen import generate_py_parser def get_default_frame_formats_path(): diff --git a/tests/js/test_codec.js b/tests/js/test_codec.js index 2253ada6..c052b122 100644 --- a/tests/js/test_codec.js +++ b/tests/js/test_codec.js @@ -15,14 +15,16 @@ const EXPECTED_VALUES = { }; // Import frame base functions +const { BASIC_START_BYTE } = require('./frame_headers/base'); const { - BASIC_START_BYTE, getTinyStartByte, isTinyStartByte, +} = require('./frame_headers/header_tiny'); +const { getBasicSecondStartByte, isBasicSecondStartByte, - fletcher_checksum, -} = require('./frame_base'); +} = require('./frame_headers/header_basic'); +const { fletcher_checksum } = require('./frame_base'); /* Minimal frame format helper classes (replacing frame_compat) */ @@ -369,8 +371,8 @@ function encodeTestMessage(formatName) { const { msg, buffer } = createTestMessage(msgInfo.struct); - // Use static encode method - return ParserClass.encode(msgInfo.msgId, buffer); + // Use static encodeMsg method + return ParserClass.encodeMsg(msgInfo.msgId, buffer); } /** @@ -380,8 +382,8 @@ function decodeTestMessage(formatName, data) { const ParserClass = getParserClass(formatName); const msgInfo = getMessageInfo(); - // Use static validate_packet method - const result = ParserClass.validate_packet(data); + // Use static validatePacket method + const result = ParserClass.validatePacket(data); if (!result || !result.valid) { return null; diff --git a/tests/ts/test_codec.ts b/tests/ts/test_codec.ts index e7ba4e5b..1e77e768 100644 --- a/tests/ts/test_codec.ts +++ b/tests/ts/test_codec.ts @@ -14,14 +14,16 @@ export const EXPECTED_VALUES = { }; // Import generated modules +const { BASIC_START_BYTE } = require('./frame_headers/base'); const { - BASIC_START_BYTE, getTinyStartByte, isTinyStartByte, +} = require('./frame_headers/header_tiny'); +const { getBasicSecondStartByte, isBasicSecondStartByte, - fletcher_checksum, -} = require('./frame_base'); +} = require('./frame_headers/header_basic'); +const { fletcher_checksum } = require('./frame_base'); const { serialization_test_SerializationTestMessage,