Check erl term format magic number

The magic number seems to be availble only at build time in eiext.h.

eiext.h is provided as part of the installation in:

lib/erl_interface-<version>/src/misc/eiext.h
pid/1,2: ensure the buffer won't overflow
Check the length of the buffer when encoding

Add wrappers around the ei encoding functions that check the length of
the destination buffer to prevent overflows.