문제

I'm working on a protocol handling data exchange that somehow a little complex, then I found TLV is the one I need. Is there a formal way to read and write TLV in erlang? or some lib / code example handling this? thanks.

도움이 되었습니까?

해결책

The "default" in Erlang is LTV rather than TLV, but it is rather easy to handle:

case gen_tcp:recv(Socket, 8) of
  <<Type:32/integer, Len:32/integer>> ->
      Payload = gen_tcp:recv(Socket, Len),
      {type_of(Type), Payload};
  ...
end,

You will need passive sockets to get this to work, but it is rather easy to do. If you have the freedom to pick your format, the LTV encoding is better because you can then put the socket in {active, once} mode which means the underlying layer decodes stuff for you.

다른 팁

I haven't actually used it, but how about this one: https://github.com/essiene/smpp34pdu/blob/master/src/tlv.erl

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top