Serializing terms with the foreign language interface

In the Foreign Include File section, there is subsection 12.4.9, Serializing and deserializing Prolog terms. If I am reading this correctly, it only discusses de-serialization through PL_put_term_from_chars().

Is the serialization meant to be done with PL_get_chars() and PL_get_nchars(), using the flag CVT_WRITE_CANONICAL?

Yes. There are some more flags than CVT_WRITE_CANONICAL. If you want full control you either have to play tricks with PL_write_term() and I/O streams or, much easier, write a Prolog predicate that does the serialization to a string as you want it and call that.

1 Like