mzaks / FlatBuffersSwift

This project brings FlatBuffers (an efficient cross platform serialization library) to Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSONString to Data?

long-fu opened this issue · comments

JSONString to Data?

@onelcat Sorry, I am not sure what you mean.

Can I read the JSON string ?

Ah you mean JSON to FlatBuffers. You can use googles flatc to convert compatible JSON file to binary file, given a schema. For Swift we could enhance the code generator to generate a static API from(dict: [String: Any]) for root type. This way you could use JSONSerialization class to parse the JSON string and create object graph from it. We could also add custom JSON parser and add from(jsonString: String) API to root type, but I don't think it is worth the hassle. It will be a couple times faster than JSONSerialization, but I don't think performance is a big issue if you already decided to use JSON. It is rather about convenience and for that using JSONSerialization should be enough.

Is this what you meant, or did I misunderstood?

Closing this one because it is a code generator issue: mzaks/FlatBuffersSwiftCodeGen#8

@onelcat the new code generator provides now the feature you wanted.
Here is how it can be used https://github.com/mzaks/FlatBuffersSwift/blob/master/FlatBuffersSwiftTests/ContactsTest.swift#L259