1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.beep4j.internal.tcp;
17
18 import net.sf.beep4j.ProtocolException;
19 import net.sf.beep4j.internal.util.ByteUtil;
20
21
22
23
24
25
26
27 public class SEQHeader {
28
29 public static final String TYPE = "SEQ";
30
31 private int channel;
32
33 private long acknowledgeNumber;
34
35 private int windowSize;
36
37 public SEQHeader(int channel, long acknowledgeNumber, int windowSize) {
38 this.channel = channel;
39 this.acknowledgeNumber = acknowledgeNumber;
40 this.windowSize = windowSize;
41 }
42
43 public SEQHeader(String[] tokens) {
44 if (tokens.length != 4) {
45 throw new ProtocolException("header must consist of 4 tokens");
46 }
47 if (!TYPE.equals(tokens[0])) {
48 throw new ProtocolException("unkown header type: " + tokens[0]);
49 }
50 this.channel = ByteUtil.parseUnsignedInt("channel", tokens[1]);
51 this.acknowledgeNumber = ByteUtil.parseUnsignedLong("acknowledge number", tokens[2]);
52 this.windowSize = ByteUtil.parseUnsignedInt("window size", tokens[3]);
53 }
54
55 public final String getType() {
56 return TYPE;
57 }
58
59 public int getPayloadSize() {
60 return 0;
61 }
62
63 public long getAcknowledgeNumber() {
64 return acknowledgeNumber;
65 }
66
67 public int getChannel() {
68 return channel;
69 }
70
71 public int getWindowSize() {
72 return windowSize;
73 }
74
75 public String[] getTokens() {
76 return new String[] {
77 "SEQ", "" + getChannel(), "" + getAcknowledgeNumber(), "" + getWindowSize()
78 };
79 }
80
81 @Override
82 public String toString() {
83 return "SEQ " + channel + " " + acknowledgeNumber + " " + windowSize;
84 }
85
86 }