jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
497 stars 50 forks source link

Unity Support #340

Closed killop closed 1 year ago

killop commented 1 year ago

hi ,i am a unity developer. in unity il2cpp aot model,i generate cs file by fbs file , but i can not use RoslynSerializerGenerator , but without RoslynSerializerGenerator i can not register GeneratedSerializerWrapper to Serializer type cache, on my point FlatBufferSerializer.cs should have interface to register autogen cs class

1 no RoslynSerializerGenerator 2 interface for autogenerate Serializer

sorry for my poor english

jamescourtney commented 1 year ago

You are attempting to use Runtime code generation in an environment that needs AOT support. You should be using the FlatSharp.Compiler package instead of the FlatSharp package.

https://github.com/jamescourtney/FlatSharp/wiki/Compiler/cfd1a8ac0d927ab7330cd153445c70d6d08154b6

Note that the wiki is in a state of flux right now as docs are updated for the upcoming v7 release of FlatSharp.

killop commented 1 year ago

hi 。you are absolute wrong。 i had used FlatSharp.Compiler to generate cs file in commandline ,for example
image i had modify FlatSharpRuntime`s source code that remove RoslynSerializerGenerator in order to adaptive unity aot mode image RoslynSerializerGenerator can not be used in unity

killop commented 1 year ago

i think no one can use FlatSharp in unity without modify your soure code ,because Unity can not use RoslynSerializerGenerator

killop commented 1 year ago

it is the point that Roslyn can only used in FlatSharp Compiler ,and should not be used in FlatSharp.Runtime

jamescourtney commented 1 year ago

Roslyn is not used in FlatSharp.Runtime: https://github.com/jamescourtney/FlatSharp/blob/main/src/FlatSharp.Runtime/FlatSharp.Runtime.csproj

killop commented 1 year ago

you are right that Roslyn is not used in FlatSharp.Runtime,but FlatSharp.Runtime.dll do not any interface exported your api ,just like FlatBufferSerializer in FlatSharp.dl in short,how can i work with FlatSharp.generated,cs in unity without Roslyn

jamescourtney commented 1 year ago

Take a look at the sample here: https://github.com/jamescourtney/FlatSharp/tree/main/samples/Example03-SchemaFiles2. The samples are intended to walk you through how to use FlatSharp. The short version is:

table MyTable (fs_serializer:"{option}") // option defined at: https://github.com/jamescourtney/FlatSharp/wiki/FBS-Annotations#fs_serializer
{
    value : int;
}
var table = new MyTable();
byte[] buffer = new byte[MyTable.Serializer.GetMaxSize(table)];
int bytesWritten = MyTable.Serializer.Write(buffer, table);
var parsed = MyTable.Serializer.Parse(buffer);
killop commented 1 year ago

your example:image but after generate cs file by fbs : image

jamescourtney commented 1 year ago

Have you told FlatSharp that you want a serializer with fs_serializer? Please share your FBS schema.

From: @.> Sent: Wednesday, November 9, 2022 10:32 PM To: @.> Cc: James @.>; State @.> Subject: Re: [jamescourtney/FlatSharp] Unity Support (Issue #340)

your example:[image]https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F4494721%2F201016753-cb69bc80-107f-469a-8924-c0afdf70d443.png&data=05%7C01%7C%7Cd23030ef59ba48a5480b08dac2e5545c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638036587455403236%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Jo6f%2F8vqAMgacwQAjqha9%2FapMOgwkz2yP%2BBgsYiBkig%3D&reserved=0 but after generate cs file by fbs : [image]https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F4494721%2F201017305-9747eaa7-a646-4bda-833c-54519399b188.png&data=05%7C01%7C%7Cd23030ef59ba48a5480b08dac2e5545c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638036587455559461%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2oFEF46QG0rKc3P%2FPAPpGtk0%2Bobx8Shpl1RpU%2BDXgM0%3D&reserved=0

― Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjamescourtney%2FFlatSharp%2Fissues%2F340%23issuecomment-1309835711&data=05%7C01%7C%7Cd23030ef59ba48a5480b08dac2e5545c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638036587455559461%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=KX%2FOmmEFK3otKNQEQFTQE1Lu%2Ba3OWJAWoNQ3QZ%2FTW2M%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAUDYYEDVYFHSADXC6F45YTWHSJHRANCNFSM6AAAAAAR3MAJFA&data=05%7C01%7C%7Cd23030ef59ba48a5480b08dac2e5545c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638036587455871891%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6XvtUJNGazsVRDSngxyr%2Ftkje%2BjqmwxILTuh1qM8eGI%3D&reserved=0. You are receiving this because you modified the open/close state.Message ID: @.***>

killop commented 1 year ago

fs_serializer? i miss it,let me try again

killop commented 1 year ago

holy shit ,it works, fantasy ,what a amzing attibutte "fs_serializer"

killop commented 1 year ago

Thank you for your patience to answer

killop commented 1 year ago

i will tell other people that it also work in unity ,nice code

jamescourtney commented 1 year ago

Thank you :) I hope that FlatSharp works well for you. Please read the wiki and samples. There are lots more features that FlatSharp supports!