1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec;
17
18 import io.netty.buffer.ByteBuf;
19 import io.netty.channel.ChannelHandlerContext;
20 import io.netty.channel.ChannelPipeline;
21 import io.netty.channel.socket.DatagramPacket;
22 import static io.netty.util.internal.ObjectUtil.checkNotNull;
23
24 import java.util.List;
25
26
27
28
29
30
31
32
33
34
35 public class DatagramPacketDecoder extends MessageToMessageDecoder<DatagramPacket> {
36
37 private final MessageToMessageDecoder<ByteBuf> decoder;
38
39
40
41
42
43
44 public DatagramPacketDecoder(MessageToMessageDecoder<ByteBuf> decoder) {
45 this.decoder = checkNotNull(decoder, "decoder");
46 }
47
48 @Override
49 public boolean acceptInboundMessage(Object msg) throws Exception {
50 if (msg instanceof DatagramPacket) {
51 return decoder.acceptInboundMessage(((DatagramPacket) msg).content());
52 }
53 return false;
54 }
55
56 @Override
57 protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, List<Object> out) throws Exception {
58 decoder.decode(ctx, msg.content(), out);
59 }
60
61 @Override
62 public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
63 decoder.channelRegistered(ctx);
64 }
65
66 @Override
67 public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
68 decoder.channelUnregistered(ctx);
69 }
70
71 @Override
72 public void channelActive(ChannelHandlerContext ctx) throws Exception {
73 decoder.channelActive(ctx);
74 }
75
76 @Override
77 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
78 decoder.channelInactive(ctx);
79 }
80
81 @Override
82 public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
83 decoder.channelReadComplete(ctx);
84 }
85
86 @Override
87 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
88 decoder.userEventTriggered(ctx, evt);
89 }
90
91 @Override
92 public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
93 decoder.channelWritabilityChanged(ctx);
94 }
95
96 @Override
97 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
98 decoder.exceptionCaught(ctx, cause);
99 }
100
101 @Override
102 public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
103 decoder.handlerAdded(ctx);
104 }
105
106 @Override
107 public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
108 decoder.handlerRemoved(ctx);
109 }
110
111 @Override
112 public boolean isSharable() {
113 return decoder.isSharable();
114 }
115 }