Alex Rivera | Logout

Is Erlang's external term format definition stable? If not, what to use?

Asked 2011-11-27T05:13:55.483
12

The Erlang external term format has changed at least once (but this change appears to predate the history stored in the Erlang/OTP github repository); clearly, it could change in the future.

However, as a practical matter, is it generally considered safe to assume that this format is stable now? By "stable," I mean specifically that, for any term T, term_to_binary will return the same binary in any current or future version of Erlang (not merely whether it will return a binary that binary_to_term will convert back to a term identical to T). I'm interested in this property because I'd like to store hashes of arbitrary Erlang terms on disk and I want identical terms to have the same hash value now and in the future.

If it isn't safe to assume that the term format is stable, what are people using for efficient and stable term serialization?

Edit
Report

1 Answer

4

erlang:phash2 is guaranteed to be a stable hash of an Erlang term.

I don't think OTP makes the guarantee made that term_to_binary(T) in vX =:= term_to_binary(T) in vY. Lots of things could change if they introduce new term codes for optimized representations of things. Or if we need to add unicode strings to the ETF or something. Or in the vanishingly unlikely future in which we introduce a new fundamental datatype. For an example of change that has happened in external representation only (stored terms compare equal, but are not byte equal) see float_ext vs. new_float_ext.

In practical terms, if you stick to atoms, lists, tuples, integers, floats and binaries, then you're probably safe with term_to_binary for quite some time. If the time comes that their ETF representation changes, then you can always write your own version of term_to_binary that doesn't change with the ETF.

answered 2011-12-05T19:36:03.487

Your Answer