【发布时间】:2021-09-20 05:00:57
【问题描述】:
我有一个基于https://github.com/apache/ignite/blob/master/modules/platforms/dotnet/examples/ServerNode/Program.cs中提到的示例的服务器节点
另外,在另一个进程中,我有一个“ClientMode = true”的客户端,如下所示。
return new IgniteConfiguration(GetServerNodeConfiguration())
{
ClientMode = true
};
缓存将保存“Employee”类的信息,我正在使用 IBinarySerializer 对“Employee”和“Address”类进行序列化,并将序列化器添加到 IgniteConfiguration 中,如下所示...
IgniteConfiguration.BinaryConfiguration = new BinaryConfiguration
{
TypeConfigurations = new List<BinaryTypeConfiguration>
{
new(typeof(Employee)){Serializer = new EmployeeSerializer()},
new(typeof(Address)){Serializer = new AddressSerializer()},
}
}
我的问题是……
- 我们是否需要在服务器和客户端代码上都有“Employee”和“Address”类?还是我只是在客户端提及它们?
- 我们是否需要在服务器和客户端代码中都使用 IBinarySerializer 序列化程序来启动 BinaryConfiguration?还是我只是在客户端提及它们?
员工
public class Employee
{
public Guid EmployeeId { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
地址
public class Address
{
public string Street { get; set; }
public string Zip { get; set; }
}
IBinarySerializer 实现
public sealed class EmployeeSerializer : IBinarySerializer
{
public void WriteBinary(object obj, IBinaryWriter writer)
{
var employee = (Employee)obj;
writer.WriteGuid("employeeId", employee.EmployeeId );
writer.WriteString("name", employee.Name);
writer.WriteObject("address", employee.Address);
}
public void ReadBinary(object obj, IBinaryReader reader)
{
var employee = (employee)obj;
employee.EmployeeId = reader.ReadObject<Guid>("employeeId");
employee.Name = reader.ReadString("name");
employee.Address = reader.ReadObject<Address>("address");
}
}
public sealed class AddressSerializer : IBinarySerializer
{
public void WriteBinary(object obj, IBinaryWriter writer)
{
var address = (Address)obj;
writer.WriteString("street", address.Street);
writer.WriteString("zip", address.Zip);
}
public void ReadBinary(object obj, IBinaryReader reader)
{
var address = (Address)obj;
address.Street = reader.ReadString("street");
address.Zip = reader.ReadString("zip");
}
}
【问题讨论】: