Comments (2)
This is about MessagePack for C# and you need pre code generation.
https://github.com/neuecc/MessagePack-CSharp/#pre-code-generationunityxamarin-supports
from magiconion.
For code generation I’m using moc.exe (https://github.com/neuecc/MagicOnion#unity-supports) That generates the following:
#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 168
namespace MagicOnion.Resolvers
{
using System;
using MessagePack;
public class MagicOnionResolver : global::MessagePack.IFormatterResolver
{
public static readonly global::MessagePack.IFormatterResolver Instance = new MagicOnionResolver();
MagicOnionResolver()
{
}
public global::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
{
return FormatterCache<T>.formatter;
}
static class FormatterCache<T>
{
public static readonly global::MessagePack.Formatters.IMessagePackFormatter<T> formatter;
static FormatterCache()
{
var f = MagicOnionResolverGetFormatterHelper.GetFormatter(typeof(T));
if (f != null)
{
formatter = (global::MessagePack.Formatters.IMessagePackFormatter<T>)f;
}
}
}
}
internal static class MagicOnionResolverGetFormatterHelper
{
static readonly global::System.Collections.Generic.Dictionary<Type, int> lookup;
static MagicOnionResolverGetFormatterHelper()
{
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(4)
{
{typeof(global::MagicOnion.DynamicArgumentTuple<int, int[]>), 0 },
{typeof(global::MagicOnion.DynamicArgumentTuple<string, string, string, string>), 1 },
{typeof(global::MagicOnion.DynamicArgumentTuple<string, string>), 2 },
{typeof(global::Definitions.Shared.SumType), 3 },
};
}
internal static object GetFormatter(Type t)
{
int key;
if (!lookup.TryGetValue(t, out key))
{
if (t == typeof(UniRx.Unit))
{
return MagicOnion.Resolvers.UniRxIntegrate.UnitFormatter.Instance;
}
else if (t == typeof(Nullable<UniRx.Unit>))
{
return MagicOnion.Resolvers.UniRxIntegrate.NullableUnitFormatter.Instance;
}
return null;
}
switch (key)
{
case 0: return new global::MagicOnion.DynamicArgumentTupleFormatter<int, int[]>(default(int), default(int[]));
case 1: return new global::MagicOnion.DynamicArgumentTupleFormatter<string, string, string, string>(default(string), default(string), default(string), default(string));
case 2: return new global::MagicOnion.DynamicArgumentTupleFormatter<string, string>(default(string), default(string));
case 3: return new MagicOnion.Formatters.Sumwcl.Definitions.Shared.SumTypeFormatter();
default: return null;
}
}
}
}
namespace MagicOnion.Resolvers.UniRxIntegrate
{
using System;
using UniRx;
using MessagePack;
using MessagePack.Formatters;
public class UnitFormatter : IMessagePackFormatter<Unit>
{
public static readonly IMessagePackFormatter<Unit> Instance = new UnitFormatter();
UnitFormatter()
{
}
public int Serialize(ref byte[] bytes, int offset, Unit value, IFormatterResolver typeResolver)
{
return MessagePackBinary.WriteNil(ref bytes, offset);
}
public Unit Deserialize(byte[] bytes, int offset, IFormatterResolver typeResolver, out int readSize)
{
if (bytes[offset] == MessagePackCode.Nil)
{
readSize = 1;
return Unit.Default;
}
else
{
throw new InvalidOperationException(string.Format("code is invalid. code:{0} format:{1}", bytes[offset], MessagePackCode.ToFormatName(bytes[offset])));
}
}
}
public class NullableUnitFormatter : IMessagePackFormatter<Unit?>
{
public static readonly IMessagePackFormatter<Unit?> Instance = new NullableUnitFormatter();
NullableUnitFormatter()
{
}
public int Serialize(ref byte[] bytes, int offset, Unit? value, IFormatterResolver typeResolver)
{
return MessagePackBinary.WriteNil(ref bytes, offset);
}
public Unit? Deserialize(byte[] bytes, int offset, IFormatterResolver typeResolver, out int readSize)
{
if (bytes[offset] == MessagePackCode.Nil)
{
readSize = 1;
return Unit.Default;
}
else
{
throw new InvalidOperationException(string.Format("code is invalid. code:{0} format:{1}", bytes[offset], MessagePackCode.ToFormatName(bytes[offset])));
}
}
}
}
#pragma warning disable 168
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612
As a result, the following code appears on all platforms (PC(Editor), Mac(Editor), Android(Device)):
public static IMessagePackFormatter GetFormatterWithVerify(this IFormatterResolver resolver)
{
IMessagePackFormatter formatter;
try
{
formatter = resolver.GetFormatter();
}
catch (TypeInitializationException ex)
{
Exception inner = ex;
while (inner.InnerException != null)
{
inner = inner.InnerException;
}
throw inner;
}
if (formatter == null)
{
throw new FormatterNotRegisteredException(typeof(T).FullName + " is not registered in this resolver. resolver:" + resolver.GetType().Name);
}
return formatter;
}
**For my model (Definitions.Models.MyModel), from the resolver (CompositeResolver)
It returns the formatter Definitions_Models_MyModelFormatter .
But on IOS device, it returns null for the same model (Definitions.Models.MyModel) from the same resolver (CompositeResolver).**
from magiconion.
Related Issues (20)
- Question: How can I connect the TLS protocol to the new version (v5.1.8)? HOT 1
- Question: Possible to use Task and ValueTask instead of UnaryResult and such? HOT 1
- Question: ObjectDisposedException on proxy side
- Question: Is a MagicOnion server possible from within Unity?
- can support Webgl http2 and net8?
- I can't have multiple implementations!
- .NET 8 Support
- Client filter is not triggered for ServerStreamingResult method in services. HOT 1
- Performance is very slow, taking 355ms for the Add function to return the result HOT 2
- How can I disconnect a client by server?
- InternalsVisibleTo lead to warnings on dependent project HOT 1
- Implement Protobuf Endpoint
- ServerReflection does not work
- Cannot work after changing to MemoryPack HOT 2
- Console app probem: PlatformNotSupportedException HOT 1
- support webgl? HOT 2
- error CS0305: Using the generic type 'MemoryPackWriter<TBufferWriter>' requires 1 type arguments HOT 3
- Memory leak when reusing GrpcChannel on many clients HOT 1
- Can't lunch Swagger if I use Vector2 for the communication
- The type or namespace name 'MessagePack' does not exist in the namespace 'MagicOnion.Serialization' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magiconion.