public static byte[] ServerToClient <T>(this Regulus.Serialization.ISerializer serializer, ServerToClientOpCode opcode, T instance) { ResponsePackage pkg = new Regulus.Remote.ResponsePackage() { Code = opcode, Data = serializer.Serialize(instance) }; return(serializer.Serialize(pkg)); }
public void TestSerializerResponsePackage() { Type[] types = new[] { typeof(Regulus.Remote.ResponsePackage), typeof(Remote.ServerToClientOpCode), typeof(byte), typeof(byte[]) }; Serializer ser = new Serializer(new DescriberBuilder(types).Describers); Remote.ResponsePackage pkg = new Regulus.Remote.ResponsePackage(); pkg.Code = Remote.ServerToClientOpCode.SetProperty; pkg.Data = new byte[1] { 255 }; byte[] buffer = ser.ObjectToBuffer(pkg); Remote.ResponsePackage dPkg = ser.BufferToObject(buffer) as Remote.ResponsePackage; Assert.Equal(Remote.ServerToClientOpCode.SetProperty, dPkg.Code); }