同時在另一個程序中,我有一個客戶端,其 "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()},
}
}
我的問題是...
我的問題是
雇員
public class Employee
{
public Guid EmployeeId { get; set; }
public string Name { get; set; }
public 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>("地址")。
}
}
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")。
}
}
uj5u.com熱心網友回復:
簡而言之,是的,你需要每個節點上的這些資訊。 雙方都必須知道如何正確地反序列化和序列化一條記錄。
盡管有可能使用BinaryObjectBuilder直接在二進制模式下作業,而無需明確的模型定義。定義一個自定義的 IBinarySerializer 也不是強制性的,內部序列化器將很好地解決這個問題,除非你有一些定義了幾十個欄位的大模型。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/323073.html
標籤:
