Skip to content

Adds serialization API#25

Merged
redvers merged 3 commits into
mainfrom
add_serialization
Jan 13, 2026
Merged

Adds serialization API#25
redvers merged 3 commits into
mainfrom
add_serialization

Conversation

@redvers
Copy link
Copy Markdown
Collaborator

@redvers redvers commented Jan 13, 2026

Add document serialization APIs to high-level Pony API.

This adds serialize() and saveToFile() methods to Xml2Doc, enabling
XML documents to be saved to strings or files with optional formatting
and encoding control.

Implementation:
- Added serialize() method using xmlDocDumpFormatMemoryEnc for in-memory
  serialization with format and encoding options
- Added saveToFile() method using xmlSaveFormatFileEnc for direct file
  output
- Added xmlFree wrapper to raw API for proper memory management
- Both methods support pretty-printing and multiple character encodings
  (UTF-8, ISO-8859-1, UTF-16, etc.)

Testing:
- Added 6 comprehensive test cases covering round-trip serialization,
  formatting options, file I/O, encoding support, modified document
  serialization, and error handling
- All 33 tests pass successfully

This feature enables both modifying existing XML documents and provides
the foundation for creating new XML documents from scratch.

redvers and others added 2 commits January 12, 2026 21:57
This adds serialize() and saveToFile() methods to Xml2Doc, enabling
XML documents to be saved to strings or files with optional formatting
and encoding control.

Implementation:
- Added serialize() method using xmlDocDumpFormatMemoryEnc for in-memory
  serialization with format and encoding options
- Added saveToFile() method using xmlSaveFormatFileEnc for direct file
  output
- Added xmlFree wrapper to raw API for proper memory management
- Both methods support pretty-printing and multiple character encodings
  (UTF-8, ISO-8859-1, UTF-16, etc.)

Testing:
- Added 6 comprehensive test cases covering round-trip serialization,
  formatting options, file I/O, encoding support, modified document
  serialization, and error handling
- All 33 tests pass successfully

This feature enables both modifying existing XML documents and provides
the foundation for creating new XML documents from scratch.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Corrected the handling of Pointer[Pointer[T]] parameters in the serialize()
method to use idiomatic Pony FFI patterns.

Changes:
- Use addressof operator with ref variables instead of array workaround
- Retrieve libxml2's free function via xmlMemGet and call it as a
  function pointer instead of calling @xmlMemFree directly
- Use String.from_cpointer() with known size instead of from_cstring()
- Define XmlFreeFunc type for proper function pointer handling
- Fixed xmlMemGet signature in raw API (use Pointer[Pointer[None]] not
  NullablePointer[Pointer[None]])

This is the correct and idiomatic way to handle C output parameters
and function pointers in Pony's FFI.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude Bot commented Jan 13, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@redvers
Copy link
Copy Markdown
Collaborator Author

redvers commented Jan 13, 2026

Hi @redvers,

The changelog - added label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do.

Release notes are added by creating a uniquely named file in the .release-notes directory. We suggest you call the file 25.md to match the number of this pull request.

The basic format of the release notes (using markdown) should be:

## Title

End user description of changes, why it's important,
problems it solves etc.

If a breaking change, make sure to include 1 or more
examples what code would look like prior to this change
and how to update it to work after this change.

Thanks.

@redvers redvers merged commit c7eb0b3 into main Jan 13, 2026
7 checks passed
github-actions Bot pushed a commit that referenced this pull request Jan 13, 2026
github-actions Bot pushed a commit that referenced this pull request Jan 13, 2026
@redvers redvers deleted the add_serialization branch May 21, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant