msgpack-cli icon indicating copy to clipboard operation
msgpack-cli copied to clipboard

It is possible to pre-compile serialized objects?

Open fanoI opened this issue 7 years ago • 2 comments

To avoid to have a slow time (1.5 seconds) in my case to get the Serializer is possible to compile them?

fanoI avatar Apr 01 '17 16:04 fanoI

I've tried to use this:

SerializerGenerator.GenerateCode(
            new SerializerCodeGenerationConfiguration
            {
                Namespace = "Example.MessagePackSerializers",
                OutputDirectory = "../../GeneratedSerializers",
                EnumSerializationMethod = EnumSerializationMethod.ByName, // You can tweak it to use ByUnderlyingValue as you like.
                IsRecursive = true, // Set depenendent serializers are also generated.
                PreferReflectionBasedSerializer = false, // Set true if you want to use reflection based collection serializer, false if you want to get generated collection serializers.
                SerializationMethod = SerializationMethod.Array // You tweak it to generate 'map' based serializers.
            }
    }

but I've not understood well where this method call should be written? An external application that generate serializers? But how this would find what should serialize? Using Namespace maybe?

One time something is generated in OutputDirectory how I'll use them?

Thanks for your help!

fanoI avatar Apr 03 '17 13:04 fanoI

Sorry, I missed this issue. Specify types as rest arguments like following:

SerializerGenerator.GenerateCode(
            new SerializerCodeGenerationConfiguration
            {...},
            typeof(Foo), typeof(Bar)
)

Note that you can specify types as IEnumerable<Type>, so you can use LINQ to filter types from some assemblies.

You can also use mpu.exe utility to generate serializer code.

yfakariya avatar Apr 10 '17 13:04 yfakariya