Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install proto-schema-parser structured-classes
pip install proto-schema-parser

- name: Install Node.js dependencies
run: npm ci
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ Thumbs.db
*.swp
*.swo
*~
*.bak
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ authors = [
{ name="Rijesh Augustine", email="rijesh@mylonics.com" },
]
dependencies = [
"structured-classes>=3.1.0",
"proto-schema-parser>=1.4.5",
]
description = "A framework for serializing data with headers"
Expand Down
4 changes: 3 additions & 1 deletion src/struct_frame/boilerplate/py/struct_frame_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def encode(self, data, msg_id):
if (len(data)):
for b in data:
output.append(b)
checksum = fletcher_checksum_calculation(data)
# Calculate checksum on msg_id + data (consistent with validate_packet)
checksum_data = [msg_id] + list(data)
checksum = fletcher_checksum_calculation(checksum_data)

output.append(checksum[0])
output.append(checksum[1])
Expand Down
554 changes: 378 additions & 176 deletions src/struct_frame/py_gen.py

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions tests/cross_platform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,13 @@ def test_cross_platform(self, encoder_lang: str, decoder_lang: str, framed: bool

def check_language_available(self, language: str, mode: str = "framed") -> bool:
"""Check if encoder/decoder for a language are available"""
# NOTE: Python and TypeScript are currently disabled due to known limitations:
# - Python: The structured-classes library's pack() method doesn't properly
# serialize variable-length strings and arrays. Only fixed-size primitive
# fields are included in the packed output, preventing proper cross-platform
# message encoding.
# NOTE: TypeScript is currently disabled due to known limitations:
# - TypeScript: Generated code has a runtime error where the .Array() method
# doesn't exist on the typed-struct builder object. This is a code generation
# bug in struct-frame's TypeScript generator.
#
# Once these issues are resolved, remove the early return below.
if language in ["python", "typescript"]:
if language in ["typescript"]:
return False

if language == "c":
Expand Down Expand Up @@ -327,8 +323,8 @@ def run_all_tests(self, test_struct=True, test_framed=True):
print("="*60)
self.log("Struct-based tests are currently NOT IMPLEMENTED", "WARNING")
self.log(
"This is due to limitations in variable-length field serialization", "WARNING")
self.log("in the Python structured-classes library.", "WARNING")
"This is due to encoder/decoder implementations not being complete", "WARNING")
self.log("for all languages in struct mode.", "WARNING")
self.log("TEST FAILED: Struct-based tests not implemented", "ERROR")

# Test framed mode
Expand Down
21 changes: 7 additions & 14 deletions tests/py/encoder_framed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,17 @@
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../generated/py'))

try:
from serialization_test_sf import SerializationTestSerializationTestMessage, _VariableString_test_string, _BoundedArray_test_array
from serialization_test_sf import SerializationTestSerializationTestMessage
from struct_frame_parser import BasicPacket

# Create variable string for test_string (matching the test_serialization.py format)
test_string = _VariableString_test_string(
18, b"Hello from Python!") # length=18, data

# Create bounded array for test_array (matching the test_serialization.py format)
test_array = _BoundedArray_test_array(
3, [100, 200, 300, 0, 0]) # 3 elements in use, max 5

# Create test message with known values
# The new struct-based generator uses direct values instead of wrapper classes
msg = SerializationTestSerializationTestMessage(
0xDEADBEEF, # magic_number
test_string, # test_string
3.14159, # test_float
True, # test_bool
test_array # test_array
magic_number=0xDEADBEEF,
test_string=b"Hello from Python!",
test_float=3.14159,
test_bool=True,
test_array=[100, 200, 300]
)

# Serialize with framing using BasicPacket
Expand Down
13 changes: 6 additions & 7 deletions tests/py/encoder_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
from serialization_test_sf import SerializationTestSerializationTestMessage

# Create test message with known values
# The new struct-based generator uses bytes for strings
msg = SerializationTestSerializationTestMessage(
0xDEADBEEF, # magic_number
3.14159, # test_float
True # test_bool
magic_number=0xDEADBEEF,
test_string=b"Hello from Python!",
test_float=3.14159,
test_bool=True,
test_array=[100, 200, 300]
)

# Set string and array fields
msg.test_string = "Hello from Python!"
msg.test_array = [100, 200, 300]

# Serialize to struct bytes (no framing) using pack()
struct_bytes = msg.pack()

Expand Down
17 changes: 8 additions & 9 deletions tests/py/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ def create_test_data():
"""Create test data for cross-language compatibility testing"""
try:
sys.path.insert(0, '../generated/py')
from serialization_test_sf import (
SerializationTestSerializationTestMessage,
_BoundedArray_test_array,
_VariableString_test_string
)
from serialization_test_sf import SerializationTestSerializationTestMessage
from struct_frame_parser import BasicPacket

test_string = _VariableString_test_string(18, b"Hello from Python!")
test_array = _BoundedArray_test_array(3, [100, 200, 300, 0, 0])

# Create test message with known values
# The new struct-based generator uses direct values instead of wrapper classes
msg = SerializationTestSerializationTestMessage(
0xDEADBEEF, test_string, 3.14159, True, test_array
magic_number=0xDEADBEEF,
test_string=b"Hello from Python!",
test_float=3.14159,
test_bool=True,
test_array=[100, 200, 300]
)

packet = BasicPacket()
Expand Down