rustler icon indicating copy to clipboard operation
rustler copied to clipboard

Serde support

Open hansihe opened this issue 8 years ago • 5 comments

Working with these can absolutely be done right now, but doing so is a bit of a chore.

  • Elixir structs
  • Keyword lists

hansihe avatar Jan 19 '17 22:01 hansihe

This would be fantastic.

I was able to get Serde to work very quickly with Rustler. However, this involves encoding/decoding JSON to pass it into the NIF. I suppose other formats like BSON or CBOR could be used, but they all add some overhead.

Serde looks to use a Derive macro for generating the boilerplate required so that any rust structs can have the serialize/deserialize methods automatically generated.

Would have such a macro in Rustler be the right tool for the job?

cgregfreeman avatar May 10 '17 13:05 cgregfreeman

@cgregfreeman using JSON back and forth is unnecessary overhead.

This is issue is geared towards being able to pass in maps or keyword lists (a list of 2-element tuples where the keys are atoms) and be able to extract out items from those data structures more easily.

scrogson avatar May 10 '17 16:05 scrogson

While it is true that Serde wasn't what I thought of when I opened this issue, @cgregfreeman does have a valid point.

Serde has established a very well understood and common interface for serializing and deserializing data from a wide range of formats. While it is true that going through a binary format would be unnecessary overhead, it would be possible to implement a Serde serializer and deserializer for working directly with Erlang terms.

I recall looking at this earlier in the project as a potential alternative to having our custom interface for working with Erlang terms. The reason why I chose to go with our own interface was that it was not possible to work with lifetimes in the way we needed through Serde. This would force us to copy a lot more data than strictly necessary, and we would therefore impose a fairly large non-negotiable performance overhead on the user.

It would be very nice to have a Serde interface in addition to the current interface. While it would be less efficient for some tasks, it would make a lot of things much easier for the user.

hansihe avatar May 10 '17 19:05 hansihe

@cgregfreeman Wrote a library called serde_rustler that should help with this :)

sunny-g avatar Jun 09 '19 04:06 sunny-g

So is the idea to incorporate serde_rustler into the rusterlium codebase in the long run? Or depend on it for code generation?

turion avatar Feb 10 '22 09:02 turion

Closing in favor of https://github.com/rusterlium/rustler/issues/200.

evnu avatar Nov 11 '22 10:11 evnu