Ventero/amf-cpp

Deserialization

Closed this issue · 10 comments

Are you working on deserialization? It could be great :)

I'm not actively working on it (yet), but it's definitely planned for the near future.

Once I've figured out some remaining issues (e.g. how to represent a deserialized AmfArray containing elements with different types), I'll start working on it.

Several month ago I was trying to work on it, but till now I didn't have a
lot of free time to finish deserialization...
I can send you what I've done so far, and if you don't mind, I'll try to
continue my work.

2014-02-07 Ventero notifications@github.com:

I'm not actively working on it (yet), but it's definitely planned for the
near future.

Once I've figured out some remaining issues (e.g. how to represent a
deserialized AmfArray containing elements with different types), I'll start
working on it.

Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-34467341
.

Sure, that'd be great! Contributions are always welcome :)

In case anyone is still interested in this, I've just more or less finished deserialization support on the deserialization branch. I do apologize for the delay in implementing this, but it turned out to be quite a lot more work than expected.

Documentation for all this will hopefully follow soon(-ish...). For some examples, you may look at the deserialization tests in the tests/ subfolder. A very general usage example to deserialize a single object of known type from a amf::v8 (typedef for std::vector<unsigned char>) would look like this:

amf::Deserializer d;
amf::v8 data { /* your data ...*/ };
amf::AmfArray a = d.deserialize(data).as<amf::AmfArray>();

If you want to deserialize multiple objects from the same v8, you'll have to use iterators instead:

amf::Deserializer d;
auto it = data.cbegin();
auto end = data.cend();
// this call will increment it to beyond the end of data it uses for deserialization
amf::AmfArray a = d.deserialize(it, end).as<amf::AmfArray>();
amf::AmfDictionary b = d.deserialize(it, end).as<amf::AmfDictionary>();

Again, proper documentation will follow. If you have any suggestions about a cleaner/different API, or encounter any issues, please do let me know. I'll merge the deserialization branch once the docs are complete.

Thanks for you work :)
I wanted to deserialize received QByteArray:

std::vector<unsigned char> test( testArray.begin(), testArray.end());
amf::Deserializer deserializer;
amf::AmfArray a = deserializer.deserialize(test);

It throws me:
conversion from 'amf::AmfItemPtr' to non-scalar type 'amf::AmfArray' requested
amf::AmfArray a = deserializer.deserialize(test);

Anyway, i also tried to run your example:

amf::Deserializer d;
amf::v8 data { };
amf::AmfArray a = d.deserialize(data);

Without effect, it throws also the same error:
conversion from 'amf::AmfItemPtr' to non-scalar type 'amf::AmfArray' requested
amf::AmfArray a = d.deserialize(data);
Could you try to explain me why it's happening?

Oh, sorry, you're right, I forgot something in my previous post.

deserializer.deserialize returns an AmfItemPtr, which is basically like a std::shared_ptr<AmfItem>. This is so that deserialize can return pointers to objects of all different AMF types. So to get a copy of the AmfArray, you'd have to call .as<AmfArray>() (which just casts the stored AmfItem* pointer to AmfArray*, and then returns a copy of the object it points at):

amf::v8 test(testArray.begin(), testArray.end());
amf::Deserializer deserializer;
amf::AmfArray a = deserializer.deserialize(test).as<amf::AmfArray>();

The bot is failing with deserialization objects in objects
http://screenshu.com/static/uploads/temporary/gx/0b/1y/bicfe1.jpg
"path"
"25"
"33"
"prototype_id"
"13"
""
"34"
""
"35"
"11"
""
""
"26"
"�"
""
"27"
"29"
"8"
""
"�"
""

Output of std::string val in std::string deserializeValue
It's not deserializing all of objects from path

@smrodek11: 0505688 should fix your issue. Thanks!

Well, apart from the typo... :P Fixed in c91f541.

I've decided to merge the deserialization support into master now, even though I haven't finished the documentation yet. That will be tracked in #3. If you have any questions the usage/etc., please leave a comment in that issue.

If you encounter any issues (e.g. crashes, incorrect deserialization), please open a new bug report.