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