deniszykov / msgpack-unity3d

MessagePack and JSON serializer for Unity3D

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cross Platform Usage Problem

sadradelir opened this issue · comments

I am using msgPack in unity with .Net for online game and serialize objects to send over the net to back-end server application which developed in java, and I pack this class for example :

public class MsgPackTestClass  {

    public int stringManipulationForProgrammers;
    public int stringManipulationForProgrammers2;
    public int stringManipulationForProgrammers3;

    public MsgPackTestClass()
    {}
}

with this values :

var m = new MsgPackTestClass();
    m.stringManipulationForProgrammers = 15; 
    m.stringManipulationForProgrammers2 = 255; 
    m.stringManipulationForProgrammers3 = 65537; 

  var s = new MemoryStream();                
  MsgPack.Serialize<MsgPackTestClass>(m, s , SerializationOptions.SuppressTypeInformation );

and finally i got this byte array ( hex converted ) :

83d920737472696e674d616e6970756c6174696f6e466f7250726f6772616d6d6572730fd921737472696e6 74d616e6970756c6174696f6e466f7250726f6772616d6d65727332d1ff00d921737472696e674d616e6970756c6174696f6e466f7250726f6772616d6d65727333d201000100

and java server using - https://github.com/msgpack/msgpack-java/tree/develop/msgpack-jackson - packing same class with same values got this byte array :

  MsgPackTestClass msgPackTestClass = new MsgPackTestClass();

  msgPackTestClass.setStringManipulationForProgrammers(15);
  msgPackTestClass.setStringManipulationForProgrammers2(255);
  msgPackTestClass.setStringManipulationForProgrammers3(65537);

  ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());

  byte[] bytes = objectMapper.writeValueAsBytes(msgPackTestClass);

83D920737472696E674D616E6970756C6174696F6E466F7250726F6772616D6D6572730FD921737472696E674D616E6970756C6174696F6E466F7250726F6772616D6D65727332CCFFD921737472696E674D616E6970756C6174696F6E466F7250726F6772616D6D65727333CE00010001

which is different with mine and we have problems in decode class objects.
why these two libraries pack the same class ( and values ) in different way ?
also please guide me how to use msgPack in cross-platform way between java and C# ?
thank you in advance...

I checked that it generates the current version of the serializer in your test case.

Java:

83D920737472696E674D616E6970756C6174696F6E466F7250726F6772616D6D6572730FD921737472696E674D616E6970756C6174696F6E466F7250726F6772616D6D65727332CCFFD921737472696E674D616E6970756C6174696F6E466F7250726F6772616D6D65727333CE00010001

Tokens:
BeginObject
	Member[stringManipulationForProgrammers] Number[<Byte>15]
	Member[stringManipulationForProgrammers2] Number[<Byte>255]
	Member[stringManipulationForProgrammers3] Number[<UInt32>65537]
EndOfObject

MsgPack.Serialize

83D920737472696E674D616E6970756C6174696F6E466F7250726F6772616D6D6572730FD921737472696E674D616E6970756C6174696F6E466F7250726F6772616D6D65727332D100FFD921737472696E674D616E6970756C6174696F6E466F7250726F6772616D6D65727333D200010001

Tokens:
BeginObject
	Member[stringManipulationForProgrammers] Number[<Int32>15]
	Member[stringManipulationForProgrammers2] Number[<Int32>255]
	Member[stringManipulationForProgrammers3] Number[<Int32>65537]
EndOfObject

I recognize that the choice of data types for numbers does not look the most adequate. But the format and structure is not broken. Are you sure you are using the latest version of the serializer?

Ok , I got that (!) and going to check versions of libraries that we use in java and unity, maybe I should change some lines of code in java or c# to use the appropriate data types.

Another question is what tool did you use to declare data types and message tokens like that ?

This is an extention to IJsonReader called DebugPrintTokens from this commit