1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec;
17
18 import io.netty5.buffer.api.Buffer;
19 import io.netty5.channel.ChannelHandlerContext;
20 import io.netty5.channel.ChannelPipeline;
21 import io.netty5.channel.socket.DatagramPacket;
22 import io.netty5.handler.codec.bytes.ByteArrayDecoder;
23
24 import static java.util.Objects.requireNonNull;
25
26
27
28
29
30
31
32
33
34
35 public class DatagramPacketDecoder extends MessageToMessageDecoder<DatagramPacket> {
36
37 private final MessageToMessageDecoder<Buffer> decoder;
38
39
40
41
42
43
44 public DatagramPacketDecoder(MessageToMessageDecoder<Buffer> decoder) {
45 this.decoder = requireNonNull(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) throws Exception {
58 decoder.decode(ctx, msg.content());
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 channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception {
88 decoder.channelInboundEvent(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 channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
98 decoder.channelExceptionCaught(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 }