Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Netty Protostuff-Unity protobuf-net:&x201C;源数据0”中的字段无效;_C#_Unity3d_Netty_Protostuff - Fatal编程技术网

C# Netty Protostuff-Unity protobuf-net:&x201C;源数据0”中的字段无效;

C# Netty Protostuff-Unity protobuf-net:&x201C;源数据0”中的字段无效;,c#,unity3d,netty,protostuff,C#,Unity3d,Netty,Protostuff,我创建了一个java server base Netty并使用Protostuff处理数据,但当我在游戏客户端base unity中接收到数据时,会对其进行反序列化,但会抛出一个错误:“源数据0中的字段无效”。我如何修复它 Java代码: private Schema<SocketModel> schema=RuntimeSchema.getSchema(SocketModel.class); LinkedBuffer buffer = LinkedBuffer.allocate(1

我创建了一个java server base Netty并使用Protostuff处理数据,但当我在游戏客户端base unity中接收到数据时,会对其进行反序列化,但会抛出一个错误:“源数据0中的字段无效”。我如何修复它

Java代码:

private Schema<SocketModel> schema=RuntimeSchema.getSchema(SocketModel.class);
LinkedBuffer buffer = LinkedBuffer.allocate(1024);
    byte[] data = ProtobufIOUtil.toByteArray(message, schema, buffer);  
    ByteBuf buf = Unpooled.copiedBuffer(CoderUtil.IntToBytes(data.length),data); 
private Schema=RuntimeSchema.getSchema(SocketModel.class);
LinkedBuffer buffer=LinkedBuffer.allocate(1024);
byte[]data=ProtobufIOUtil.toByteArray(消息、模式、缓冲区);
ByteBuf buf=unmooled.copiedBuffer(CoderUtil.IntToBytes(data.length),data);
外写字节(buf)

C#代码:

private SocketModel反序列化(字节[]msg)
{
使用(MemoryStream ms=新的MemoryStream(msg))
{
SocketModel SocketModel=序列化程序。反序列化(ms);
返回socketModel;
}
}

SocketModel是否在proto文件中定义并生成java代码?您可以尝试使用JsonIOUtil查看序列化数据的外观,以及有哪些字段,并将其与proto中的SocketModel进行比较?您可以尝试使用JsonIOUtil查看序列化数据的外观,以及有哪些字段,并将其与proto中的SocketModel进行比较。
 private SocketModel DeSerial(byte[] msg)
{
    using (MemoryStream ms = new MemoryStream(msg))
    {

            SocketModel socketModel = Serializer.Deserialize<SocketModel>(ms);
            return socketModel;
    }
}