Is there an equivalent of driver_output_term
in the other direction, i.e. sending an Erlang term to the driver without converting it to an iolist first? If not, I presumably should convert my term using term_to_binary
and parse it on the C side with ei
; any good examples?
Sending terms instead of iolists to an Erlang driver
412 views Asked by Alexey Romanov At
1
According to the docs, you can only send stuff that's in
iodata()
format.If all you want send to the driver is integers and strings, it might be more efficient (and a lot easier) to use your own term-to-iodata encoding, as in this tutorial from the Erlang documentation. They use a function to convert their calls to a mapping that can be sent to the driver directly and therefore doesn't need to be encoded using
term_to_binary()
.This mapping is feasible if
X
andY
are assumed to be small integers. On the C side, the first byte of the input buffer is switched upon to call the appropriate function using the second byte as the argument: