[erlang-questions] binary_to_term

Anthony Shipman als@REDACTED
Wed Jun 10 20:37:14 CEST 2009


On Thu, 11 Jun 2009 02:58:31 am Michael Radford wrote:
> Kostis Sagonas writes:
> > You are so kind.  I personally think it is terrible!
> >
> > The issue has been discussed before, both in meetings and in this
> > mailing list, and my understanding is that there are actually
> > applications out there which depend on this "feature" (i.e.,
> > binary_to_term/1 succeeding when there is a prefix of the binary which
> > can be turned into some Erlang term).
>
> I personally don't see what's so terrible about this behavior.
>
> The external term format has to be self-delimiting anyway for safety.
> All types are prefixed with a header, including a length if
> variable-length, so it's not possible for a prefix of a valid encoded
> term to also be a valid encoded term.
>
> So behaving "correctly" in this case would just mean a check for extra
> bytes after the term has already been successfully decoded -- a pop quiz
> to force the programmer to construct a binary with the exact length of
> the term data.
>
> The only apparent benefit would be that we all get to feel more
> comfortable that binary_to_term is the exact mathematical inverse of
> term_to_binary.  But there may be a real cost in forcing the
> construction of an extra binary.
>
> Mike

It would be fine if there was a binary_to_term that returned the trailing 
binary so that we could continue to decode the following terms.


-- 
Anthony Shipman                    Mamas don't let your babies 
als@REDACTED                   grow up to be outsourced.


More information about the erlang-questions mailing list