Without using the hton* function, this won't be portable, will it?

Also, how would this be different from encode_int(output, -1)?  If you're trying to encode a NULL string, then encode_short(output, -1) might do what you want, if you're right about negative length values having special significance.  If you're trying to encode a NULL integer (or floating point), then how do you distinguish NULL from any valid value?  I don't know the binary spec, but based on this implementation, there is no room in the representation for NULL integer values.