-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Swift] Reference in Object API to underlying type #6058
Comments
@jackflips thanks for opening the issue. I think the serialize method you are mentioning already exists.
So you can write an extension that does the following:
|
Makes sense! But the serialize extension would have to be on Monster, right? Rather than MonsterT? |
@jackflips. func serialize() -> ByteBuffer {
var builder = FlatBufferBuilder(initialSize: 64)
let root = Type.pack(&builder, obj: &self)
builder.finish(root)
return builder.sizedBuffer
} more or less it should look like this, which gives me the idea of actually adding this method to the ObjectApi protocol, instead of letting the users have the control over it. |
On my generated PacketT object (analogous to MonsterT), I don't have a pack function. Pack is a static function on the Packet class. This brings me back to my original question, which is how can I access the Packet class from PacketT to use Pack? Your example seems to imply that pack is a function on MonsterT.
That's a great idea. |
so, pack is indeed a |
I'm confused about this. How am I supposed to call the pack function from an extension on NativeTable? I see the ObjectAPI protocol definition in the FlatBufferObject.swift file but it doesn't seem like any of the generated code conforms to this protocol. |
@jackflips I created the PR, you can take a look at the solution there. plus if you want it urgently you can adapt that solution into your own extension. |
Thank you! |
Would it be possible to have a reference to the underlying FlatBufferObject type in its generated convenience class?
For example, if I have a Request type, and I pass in --gen-object-api to the FlatBuffer schema compiler, I get a RequestT class. I think it would be really nice to have a reference to the Request type in the RequestT class, so that I could write an extension on RequestT that would let users call serialize() and have it spit out FlatBuffer Data, without having to worry about how FlatBuffers work at all.
The text was updated successfully, but these errors were encountered: