Java
@@@codepublic interface DataBodyFormatter<T> {
void Serialize(ByteBuf writer, T value, Version version);
T Deserialize(ByteBuf reader,Version version);
}
public class DataBodyFormatterFactory {
public DataBodyFormatterFactory() {
}
/**
* 系统内的formatters,自动注册
*/
@Autowired
Map<String, DataBodyFormatter> formatters;
}
public <D> DataBodyFormatter<D> getDataBodyFormatter(long code, boolean isReply) {
}
# 使用,默认就是object
dataBodyFormatter = _DataBodyFactory.getDataBodyFormatter(code, isClientMode());
@@#
而在NET中
@@@codepublic interface IDataBodyFormatterBase
{
object Deserialize(IByteBuffer reader, Version version);
}
public interface IDataBodyFormatter<T> : IDataBodyFormatterBase
{
void Serialize(IByteBuffer writer, T value, Version version);
new T Deserialize(IByteBuffer reader, Version version);
}
# 使用一个基类
public abstract class TDataBody<T> : DataBody, IDataBodyFormatter<T>
{
public abstract T Deserialize(IByteBuffer reader, Version version);
public abstract void Serialize(IByteBuffer writer, T value, Version version);
object IDataBodyFormatterBase.Deserialize(IByteBuffer reader, Version version)
{
return this.Deserialize(reader, version);
}
}
public class DataBodyFormatterFactory : IDataBodyFormatterFactory
{
[Autowired()]
public Dictionary<string, IDataBodyFormatterBase> FormatterDict { get; set; }
//不允许的写法
//public Dictionary<string, IDataBodyFormatter> FormatterDict2 { get; set; }
public IDataBodyFormatterBase getDataBodyFormatter(int code, bool isReply = false)
{
}
}
# 使用
dataBodyFormatter = _DataBodyFactory.getDataBodyFormatter(code, IsClientMode);
@@#
原文转载:http://www.shaoqun.com/a/512511.html
kkr:https://www.ikjzd.com/w/1340
淘粉8:https://www.ikjzd.com/w/1725
Java@@@codepublicinterfaceDataBodyFormatter<T>{voidSerialize(ByteBufwriter,Tvalue,Versionversion);TDeserialize(ByteBufreader,Versionversion);} publicclassDataBodyFormatterFa
米兰网:米兰网
淘粉吧:淘粉吧
高尔寺山攻略 :高尔寺山攻略
深圳东门老街就是一条街吗?:深圳东门老街就是一条街吗?
马尔代夫水上飞机介绍 :马尔代夫水上飞机介绍
No comments:
Post a Comment