[erlang-questions] Term to binary in a NIF

Daniel Goertzen daniel.goertzen@REDACTED
Tue Feb 14 15:38:37 CET 2012


Take a look at BERT ( http://bert-rpc.org/ ).  BERT does almost the same
thing as binary_to_term() and term_to_binary(), and there is a C++
implementation that might fit in your NIF.

Dan.

On Mon, Feb 13, 2012 at 10:56 AM, Matthew Evans <mattevans123@REDACTED>wrote:

>  Hi
>
> I've written a NIF that takes data from an external device driver,
> converts it to a term (a tuple) and uses enif_send (from a thread created
> by the nif) to a specific Erlang process.
>
> Unfortunately on some deployments we have been forced to disable SMP in
> the Linux kernel and BEAM due to a third-party driver issue. In these cases
> what I have done is used enif_system_info in the NIF, and if SMP is
> disabled I will send the message via a unix domain socket (I have a driver
> for that) instead of enif_send.
>
> On the Erlang side the UDS is opened, and I use erlang:open_port to pass
> the unix domain socket to the event loop. What is nice here is that I can
> use the same Erlang and C code for both SMP enabled and disabled systems.
> So the Erlang process would get an Erlang message like:
>
> {driver_result,Integer,Integer} - If SMP is enabled
>
> Or:
>
> {#Port<0.647>,{data,SomeBinary}} - If SMP is disabled
>
> What I would like to do is see if I can send the message as an Erlang term
> to the unix domain socket using something like term_to_binary in the NIF (I
> would prefer that instead of sending raw binary to Erlang with enif_send).
>
> Is that possible?
>
> Thanks
>
> Matt
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120214/6c4ad375/attachment.htm>


More information about the erlang-questions mailing list