netty 私有协议栈开发的坑

2017-09-21 10:29:36 +08:00
 qingfengxm

package com.netty.protocol;

import io.netty.handler.codec.marshalling.DefaultMarshallerProvider; import io.netty.handler.codec.marshalling.DefaultUnmarshallerProvider; import io.netty.handler.codec.marshalling.MarshallerProvider; import io.netty.handler.codec.marshalling.UnmarshallerProvider; import org.jboss.marshalling.MarshallerFactory; import org.jboss.marshalling.Marshalling; import org.jboss.marshalling.MarshallingConfiguration;

public class MarshallingCodeCFactory { public static NettyMarshallingDecoder buildMarshallingDecoder(){ final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial"); final MarshallingConfiguration configuration = new MarshallingConfiguration(); configuration.setVersion(5); UnmarshallerProvider provider = new DefaultUnmarshallerProvider(marshallerFactory, configuration); int maxSize = 1024 << 2; NettyMarshallingDecoder decoder = new NettyMarshallingDecoder(provider, maxSize); return decoder; }

public static NettyMarshallingEncoder buildMarshallingEncoder(){
	final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
	final MarshallingConfiguration configuration = new MarshallingConfiguration();
	configuration.setVersion(5);
	MarshallerProvider provider = new DefaultMarshallerProvider(marshallerFactory, configuration);
	NettyMarshallingEncoder encoder = new NettyMarshallingEncoder(provider);
	return encoder;
}

}

marshallerFactory 获取到为 null,是什么情况?用下边构造 encoder decoder 直接就报错了,各位大神有懂的吗?

3015 次点击
所在节点    Java
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/392467

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX