Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    pcharbon70
    @pcharbon70
    I can change the conversation to StreamJson channel, was not sure if its the MessagePack or StreamJson that was related to my issue
    Andrew Arnott
    @AArnott
    @pcharbon70 As this sounds streamjsonrpc specific, I'm happy to continue the conversation over at https://gitter.im/vs-streamjsonrpc/Lobby
    katie33s
    @katie33s

    I want to have a field for adding extra custom Key-Value data, that is rarely present. I see some do this with a Json string:
    Example:

    class Thingy1 {
        [Key(0)] public int Id {get;}
        // ... omitted fields ...
        [Key(7)] public string ExtraJsonData {get;}
    }

    I could do this with an inner messagepack array too:

    class Thingy2 {
        [Key(0)] public int Id {get;}
        // ... omitted fields ...
        [Key(7)] public byte[] ExtraMsgPackData {get;}
    }

    so in this example, if ExtraMsgPackData is non-null (quite rare), then it would be deserialized as String-Key and examined.
    What do you think? Is there a preferred way to do this?

    Andrew Arnott
    @AArnott
    @katie33s Are you hoping that the deserializer will recognize extra arbitrary properties in the Thingy2 structure and somehow pack it into a byte[] for you, or are you imagining that the serialized form of Thingy2 literally has one property called ExtraMsgPackData that is set to a byte[] value?
    Andrew Arnott
    @AArnott
    2.2 now has an empty milestone. I pushed a prerelease to nuget.org. Please help us test and validate this release.
    Dylan Green
    @DylanGTech
    I've been having a lot of issues with MessagePack. Seems any time I deserialize a messagepackobject after sending it over a NetworkStream, it fails. I'm assuming I am not reading the info from the stream properly. Is this approach flawed or has anything that could lead to the data being scrambled or not thread-safe?
    //_netStream: Network stream that is being read from only in this thread
    //tokenSource: CancellationTokenSource from this class
                            while (server.Clients.Contains(this))
                            {
                                if (_netStream.DataAvailable)
                                    using (var streamReader = new MessagePackStreamReader(_netStream))
                                    {
                                        try
                                        {
                                            ReadOnlySequence<byte> sequence = (ReadOnlySequence<byte>)await streamReader.ReadAsync(tokenSource.Token);
                                            ServerPack obj = MessagePackSerializer.Deserialize<ServerPack>(sequence, PlayerdomGame.SerializerSettings, tokenSource.Token);
                                            HandleMessage(obj);
                                        }
                                        catch(MessagePackSerializationException e)
                                        {
    
                                        }
                                    }
                                else Task.Delay(10).Wait();
                              }
    Dylan Green
    @DylanGTech
    Ok, this was a mistake in a different part of the code. Nevermind
    Matt Powell
    @mattpowell-gr

    Hi, is it possible to deserialize to a different type than the one that was serialized? I have a service that is serializing IEnumerable<MyType> where MyType is:

    struct MyType { public DateTime Date {get; set;} public int Value {get; set;} }

    But I eventually want a pair of IEnumerable<DateTime>, IEnumerable<int>, without having to materialize the List<MyType> before splitting. Perhaps a callback api on deserialization?

    Thanks, Matt

    Andrew Arnott
    @AArnott
    @mattpowell-gr Unless you're using Typeless, the types themselves are not serialized, so you're free to deserialize them into any type you want. However the schema of what is serialized will resemble the original type if you're using one of the built-in formatters. So in msgpack you'd have an array of maps where each map has two entries (one for each property). There's no way you can deserialize that as two arrays of simple values each. You'll have to either deserialize the original schema first, or write low-level code to write or read the foreign schema into the object graph you want. For example, you might write a formatter and resolver that will serialize MyType[] into a DateTime[] and Value[] in msgpack form. You wouldn't necessarily have to create these two arrays in the managed heap, but you'd have to use the MessagePackWriter to write it out that way. Or you could bridge the schema difference in the deserialization side using MessagePackReader.
    Matt Powell
    @mattpowell-gr
    @AArnott Thanks for the detailed response. Looks like MessagePackReader is a good option.
    chilipepperhott
    @chilipepperhott
    Hi. The type I am serializing uses generics. Is it possible to serialize it?
    davidrapan
    @davidrapan
    Hey, still without feature to disable for single Views in ASP in InOuFormatter scenario? D. And that DateTime and Type are awesome! Thx ;)
    chilipepperhott
    @chilipepperhott
    I am getting an error and I just want to know if it stems from it using generics.
    chilipepperhott
    @chilipepperhott
    Any help would be appreciated greatly

    Here is the class I am attempting to serialize.

    [MessagePackObject]
        public class RequestPacket<T>
        {
            [Key(0)]
            public bool IsRequest { get; set; }
            [Key(1)]
            public Dictionary<T, byte[]> Messages { get; set; }
        }

    I am just using MessagePackSerializer.Serialize([The packet]);

    Andrew Arnott
    @AArnott
    @chilipepperhott I think generics should be fine. Are you using the mpc tool to generate formatters in advance or are you just using the runtime support? Generics come with some limitations for mpc, but at runtime generics should be fine. What error are you seeing?
    chilipepperhott
    @chilipepperhott
    @AArnott I think I am generating them at runtime. I really just wanted to know if this is a limitation of MessagePack-CSharp itself or it is my fault. Now I know it is the latter. Thanks!
    chilipepperhott
    @chilipepperhott
    @AArnott I am not sure how to interpret this exception:
    System.TypeLoadException
    Type 'MessagePack.Formatters.Small_Shared_Networking_RequestPacket`1\[\[Small_Tests_Networking_RequestTypes\, Small_Tests\]\]Formatter4' from assembly 'MessagePack.Resolvers.DynamicObjectResolver, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is attempting to implement an inaccessible interface.
       at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
       at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
       at MessagePack.Internal.DynamicObjectTypeBuilder.BuildType(DynamicAssembly assembly, Type type, Boolean forceStringKey, Boolean contractless)
       at MessagePack.Resolvers.DynamicObjectResolver.FormatterCache`1..cctor()
    Andrew Arnott
    @AArnott
    @chilipepperhott That looks like the type you're serializing is or has references to non-public types. You should either make them public or use the DynamicObjectResolverAllowPrivate resolver, as specified in our README.
    Andrew Arnott
    @AArnott
    @neuecc @pCYSl5EDgo I'll be on vacation for several days starting tomorrow afternoon. I don't expect to be active on github during that time.
    Ahmed
    @Ahmed310
    aot.png
    I'm using MessagePack.Unity.2.2.60.unitypackage and trying to generate AutoGenerate code for AOT. I set root directory in first field & output-dir in 2nd field. After pressing Generate there is no generate code and no exception either
    Andrew Arnott
    @AArnott
    @neuecc may be able to help you, @Ahmed310
    Yoshifumi Kawai
    @neuecc
    https://github.com/neuecc/MessagePack-CSharp/blob/master/src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Unity/MessagePackWindow.cs#L145-L162
    Generate button run this lines.
    • require more logs(At least the commandline args should be out)
    • If possible, set breakpoint and debug here
    Ahmed
    @Ahmed310
    here is the command log
    Generate MessagePack Files, command:-i D:\Ahmed\projects\Unity\FigNet\FigNetUnity\FigNet_Unity\FigNetCore.csproj -o D:\Ahmed\projects\Unity\FigNet\FigNetUnity\FigNet_Unity\Assets\FigNet\AutoGenerate\Data.cs
    Ahmed
    @Ahmed310
    triedCommandLine.png
    tried via command line getting this error path in the second try is correct
    Ahmed
    @Ahmed310
    able to generate AOT code via cmmandline, before I was putting dotnet mpc -options whereas correct usage is mpc -options
    Andrew Arnott
    @AArnott
    @Ahmed310 I suspect dotnet mpc also works, but switches would default to going to dotnet. To get them to be sent to mpc, you'd have to first use -- like this:
    dotnet mpc -- -options
    claytoncurmi
    @claytoncurmi
    hi all, good morning. I am using Unity 2020.1.4f1 on macOS and I just imported the unitypackage v2.2.60. However the namespace 'MessagePack' is not found. I clear the .csproj and library folder, restarted Unity but still the same. I also update to the latest VS Code Editor 1.2.2 via UPM. Any pointers on what I am missing please?
    vrecluse
    @vrecluse
    Why MessagePackSerializer.Serialize doesn't support in or ref keyword? Isn't it faster when serialize struct and pass by ref?
    Andrew Arnott
    @AArnott
    If the struct is larger than pointer size, then yes using in can be faster. But ultimately that struct is going to be passed to a formatter as well, at least, and the IMessagePackFormatter<T> interface does not use in. So it'll be copied at least once anyways.
    Poyo
    @Poyo-SSB
    Hi. Is there any way to ignore null and/or zero and/or default values when serializing?
    Andrew Arnott
    @AArnott
    @Poyo-SSB Yes, but today it requires you write your own formatter. #678 tracks supporting it in the dynamic resolver that ships with the library.
    Poyo
    @Poyo-SSB
    Gotcha, thanks.
    Denis Petrov
    @petroved
    I have a problem with mpc.exe from messagePack v2.1.194 with simple Union example from the readme, however downgrading to mpc v2.0.323 worked fine
    Fail in console app running on MessagepackCompiler.RunAsync
      System.IndexOutOfRangeException: Index was outside the bounds of the array.
         at System.Collections.Immutable.ImmutableArray`1.get_Item(Int32 index)
         at MessagePackCompiler.CodeAnalysis.TypeCollector.<>c.<CollectUnion>b__20_2(ImmutableArray`1 x)
         at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
         at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
         at System.Linq.OrderedEnumerable`1.ToArray()
         at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
         at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectUnion(INamedTypeSymbol type)
         at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectCore(ITypeSymbol typeSymbol)
         at MessagePackCompiler.CodeAnalysis.TypeCollector.Collect()
         at MessagePackCompiler.CodeGenerator.GenerateFileAsync(String input, String output, String conditionalSymbol, String resolverName, String namespace, Boolean useMapMode, String multipleIfDirectiveOutputSymbols)
         at MessagePack.Generator.MessagepackCompiler.RunAsync(String input, String output, String conditionalSymbol, String resolverName, String namespace, Boolean useMapMode, String multipleIfDirectiveOutputSymbols)
         at ConsoleAppFramework.ConsoleAppEngine.RunCore(ConsoleAppContext ctx, Type type, MethodInfo methodInfo, String[] args, Int32 argsOffset)
    ZagButNoZig
    @ZagButNoZig
    Hi. So I set up an empty project in Unity 2019.4.15f1, I installed MessagePack v2.2.60, I created an example class https://gist.github.com/ZagButNoZig/324181fce77395960050f3c1a0adbf6f. And I ran MessagePack Code generator. But the code generator ("command:-i ../Assembly-CSharp.csproj -o ./Scripts/MessagePackGenerated.cs") does not create c# file called MessagePackGenerated.cs. And when building with il2cpp the serialization is not working. What am I missing?
    ZagButNoZig
    @ZagButNoZig
    When running the code generator from command line I get: " Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'"
    Andrew Arnott
    @AArnott
    @petroved I recommend you file an issue to help track this.
    @ZagButNoZig What version of mpc are you using and how did you install it? What does dotnet --info tell you just after you see this error?
    ZagButNoZig
    @ZagButNoZig
    I fixed it. I needed to have dotnet core 3 installed instead of 5. But I can't find the 'Typeless' api on the 'MessagePackSerializer'. Was it removed or moved? @AArnott
    ZagButNoZig
    @ZagButNoZig
    It seems that TypelessContractlessStandardResolver is removed in '!UNITY_2018_3_OR_NEWER'
    Denis Petrov
    @petroved
    @AArnott created issue neuecc/MessagePack-CSharp#1146
    ZagButNoZig
    @ZagButNoZig
    What I'm trying to do with the typeless API is have a component interface and be able to serialize all components to save their state. But I don't know the type of a component at compile time so I need to be able to serialize and deserialize them without knowing the specific type.
    Kevin Watkins
    @MrKWatkins
    Hi. Is there another release being planned? Pull request neuecc/MessagePack-CSharp#1078 is on master but I don't believe it's been released yet and it fixes an issue I'm having.
    Andrew Arnott
    @AArnott
    @MrKWatkins Sure. I'll spin one up tonight.
    Kevin Watkins
    @MrKWatkins
    That's great, thank you!
    Nuno Silva
    @LittleCodingFox
    Hello. Is there a way to tell what version of MessagePack I am using right now?
    I'd like to figure out which version I was using until now, but I formatted my PC so I don't have access to that version of MPC anymore
    Ben Hymers
    @hymerman
    Hi! We're using MessagePack for a Unity game, and we're finding we get intermittent build failures with il2cpp - Unity support have told us it's likely to be because of our use of generics. It looks like the main source of generics in the codebase, by a long long way, is MessagePack. Has anyone else experienced this? Are there any workarounds? Any ideas for how we could reduce this? I imagine it's the long lists of typed formatters in the resolvers (int16, nullable int16, array of nullable int16 and so on and so on).