1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.sctp;
17
18 import com.sun.nio.sctp.MessageInfo;
19 import io.netty.buffer.ByteBuf;
20 import io.netty.buffer.DefaultByteBufHolder;
21
22
23
24
25 public final class SctpMessage extends DefaultByteBufHolder {
26 private final int streamIdentifier;
27 private final int protocolIdentifier;
28 private final boolean unordered;
29
30 private final MessageInfo msgInfo;
31
32
33
34
35
36
37
38 public SctpMessage(int protocolIdentifier, int streamIdentifier, ByteBuf payloadBuffer) {
39 this(protocolIdentifier, streamIdentifier, false, payloadBuffer);
40 }
41
42
43
44
45
46
47
48
49 public SctpMessage(int protocolIdentifier, int streamIdentifier, boolean unordered, ByteBuf payloadBuffer) {
50 super(payloadBuffer);
51 this.protocolIdentifier = protocolIdentifier;
52 this.streamIdentifier = streamIdentifier;
53 this.unordered = unordered;
54 msgInfo = null;
55 }
56
57
58
59
60
61
62 public SctpMessage(MessageInfo msgInfo, ByteBuf payloadBuffer) {
63 super(payloadBuffer);
64 if (msgInfo == null) {
65 throw new NullPointerException("msgInfo");
66 }
67 this.msgInfo = msgInfo;
68 streamIdentifier = msgInfo.streamNumber();
69 protocolIdentifier = msgInfo.payloadProtocolID();
70 unordered = msgInfo.isUnordered();
71 }
72
73
74
75
76 public int streamIdentifier() {
77 return streamIdentifier;
78 }
79
80
81
82
83 public int protocolIdentifier() {
84 return protocolIdentifier;
85 }
86
87
88
89
90 public boolean isUnordered() {
91 return unordered;
92 }
93
94
95
96
97
98 public MessageInfo messageInfo() {
99 return msgInfo;
100 }
101
102
103
104
105 public boolean isComplete() {
106 if (msgInfo != null) {
107 return msgInfo.isComplete();
108 } else {
109
110 return true;
111 }
112 }
113
114 @Override
115 public boolean equals(Object o) {
116 if (this == o) {
117 return true;
118 }
119
120 if (o == null || getClass() != o.getClass()) {
121 return false;
122 }
123
124 SctpMessage sctpFrame = (SctpMessage) o;
125
126 if (protocolIdentifier != sctpFrame.protocolIdentifier) {
127 return false;
128 }
129
130 if (streamIdentifier != sctpFrame.streamIdentifier) {
131 return false;
132 }
133
134 if (unordered != sctpFrame.unordered) {
135 return false;
136 }
137
138 if (!content().equals(sctpFrame.content())) {
139 return false;
140 }
141
142 return true;
143 }
144
145 @Override
146 public int hashCode() {
147 int result = streamIdentifier;
148 result = 31 * result + protocolIdentifier;
149
150 result = 31 * result + (unordered ? 1231 : 1237);
151 result = 31 * result + content().hashCode();
152 return result;
153 }
154
155 @Override
156 public SctpMessage copy() {
157 if (msgInfo == null) {
158 return new SctpMessage(protocolIdentifier, streamIdentifier, unordered, content().copy());
159 } else {
160 return new SctpMessage(msgInfo, content().copy());
161 }
162 }
163
164 @Override
165 public SctpMessage duplicate() {
166 if (msgInfo == null) {
167 return new SctpMessage(protocolIdentifier, streamIdentifier, unordered, content().duplicate());
168 } else {
169 return new SctpMessage(msgInfo, content().duplicate());
170 }
171 }
172
173 @Override
174 public SctpMessage retain() {
175 super.retain();
176 return this;
177 }
178
179 @Override
180 public SctpMessage retain(int increment) {
181 super.retain(increment);
182 return this;
183 }
184
185 @Override
186 public String toString() {
187 return "SctpFrame{" +
188 "streamIdentifier=" + streamIdentifier + ", protocolIdentifier=" + protocolIdentifier +
189 ", unordered=" + unordered +
190 ", data=" + contentToString() + '}';
191 }
192 }