如何格式化以下 erlang 术语:
{ atom, "message" }
在 jInterface 到我可以在 erlang shell 中调用的外部格式
erlang:binary_to_term( Binary )
示例:请注意,由于元组将通过网络发送,因此我通过转换为 byte[] 来完成。
OtpErlangObject[] msg = new OtpErlangObject[2];
msg[0] = new OtpErlangAtom( "atom" );
msg[1] = new OtpErlangString( "message" );
OtpErlangTuple reply = new OtpErlangTuple(msg);
OtpOutputStream stream = new OtpOutputStream(reply);
stream.toByteArray() // byte[] which I send over net
Erlang 接收到的二进制文件是:
B = <<104,2,100,0,4,97,116,111,109,107,0,7,109,101,115,115,97,103,101>>
然后在 erlang shell 中将接收到的术语转换为二进制会给出一个 badarg。
binary_to_term( B ).
** exception error: bad argument
in function binary_to_term/1
called as binary_to_term(<<104,2,107,0,4,97,116,111,109,107,0,7,109,
101,115,115,97,103,101>>)