Reputation: 7523
I want to stream a series of integers across a Netty channel. Right now , in my code channel.write(Integer.valueOf(val)
, I get the error java.lang.IllegalArgumentException: unsupported message type: class java.lang.Integer
which I understand is because I do not have any integer encoder /decoder as a handler in the pipeline. Is this correct? Do I have to write my own integer decoder or there is one available to use ? Some guidance around this topic will be extremely helpful.
Upvotes: 1
Views: 975
Reputation: 23557
Yes this is the case... You can also just write it in a ChannelBuffer and then write the ChannelBuffer to the Channel.
Something like:
ChannelBuffer buf = ChannelBuffers.buffer(4);
buf.writeInt(Integer.valueOf(val));
channel.write(buf);
Upvotes: 2
Reputation: 10843
Yup, your understanding is correct. Without an appropriate FrameEncoder
in your pipeline, Netty is going to throw up its hands and say it doesn't know how to deal with an Integer
.
If you want to add an off-the-shelf component, you can add an ObjectEncoder and ObjectDecoder to your pipeline. Otherwise, you'll want to implement your own frame encoder and decoders.
Upvotes: 1