1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
package org.uic.barcode.ssbFrame;
import org.uic.barcode.asn1.uper.BitBuffer;
import org.uic.barcode.asn1.uper.ByteBitBuffer;
import org.uic.barcode.ticket.EncodingFormatException;
public class SsbReservation extends SsbCommonTicketPart {
private SsbStations stations = new SsbStations();
private int ticketSubType = 0;
private int departureDate = 0;
private int departureTime = 0;
private String train = null;
private int coach = 0;
private String place = null;
private boolean overbooking = false;
private int infoCode = 0;
private String text = null;
@Override
protected int decodeContent(byte[] bytes, int offset) {
offset = offset + decodeCommonPart(bytes);
BitBuffer bits = new ByteBitBuffer(bytes);
ticketSubType = bits.getInteger(offset, 2);
offset = offset + 2;
stations = new SsbStations();
offset = stations.decode(offset, bytes);
/*
* Departure date : First day of validity from the issuing date Num (<367) 9,000
Departure Time Num (<1440) 11,000
Train number AlphaNum + 5 Car 30,000
Coach number Num (< 999) 10,000
Seat/berth number 3 AlphaNum 18,000
Overbooking indicator Bit Flag 1,000
Information Messages Num (< 9999) 14,000
Open Tekst 6 Bit ASCII (27 Car) 162,000
*/
departureDate = bits.getInteger(offset, 9);
offset = offset + 9;
departureTime = bits.getInteger(offset, 11);
offset = offset + 11;
train = bits.getChar6String(offset, 30);
offset = offset + 30;
coach = bits.getInteger(offset, 10);
offset = offset + 10;
place = bits.getChar6String(offset, 18);
offset = offset + 18;
overbooking = bits.get(offset);
offset++;
infoCode = bits.getInteger(offset, 14);
offset = offset + 14;
text = bits.getChar6String(offset, 162);
offset = offset + 162;
return offset;
}
@Override
protected int encodeContent(byte[] bytes, int offset) throws EncodingFormatException {
offset = offset + encodeCommonPart(bytes, offset);
BitBuffer bits = new ByteBitBuffer(bytes);
if (ticketSubType < 0 || ticketSubType > 3) {
throw new EncodingFormatException("SSB pass type too big");
}
bits.putInteger(offset, 2,ticketSubType);
offset = offset + 2;
offset = stations.encode(offset, bytes);
/*
* Departure date : First day of validity from the issuing date Num (<367) 9,000
Departure Time Num (<1440) 11,000
Train number AlphaNum + 5 Car 30,000
Coach number Num (< 999) 10,000
Seat/berth number 3 AlphaNum 18,000
Overbooking indicator Bit Flag 1,000
Information Messages Num (< 9999) 14,000
Open Tekst 6 Bit ASCII (27 Car) 162,000
*/
if (departureDate < 0 || departureDate > 512) {
throw new EncodingFormatException("SSB departure date too big");
}
bits.putInteger(offset, 9, departureDate);
offset = offset + 9;
if (departureTime < 0 || departureTime > 1440) {
throw new EncodingFormatException("SSB departure time too big");
}
bits.putInteger(offset, 11,departureTime);
offset = offset + 11;
if (train.length() > 5) {
throw new EncodingFormatException("SSB train too big");
}
bits.putChar6String(offset, 30,train);
offset = offset + 30;
if (coach < 0 || coach > 999) {
throw new EncodingFormatException("SSB coach too big");
}
bits.putInteger(offset, 10,coach);
offset = offset + 10;
if (place.length() > 3) {
throw new EncodingFormatException("SSB coach too big");
}
bits.putChar6String(offset, 18,place);
offset = offset + 18;
bits.put(offset, overbooking);
offset++;
if (infoCode < 0 || infoCode > 9999) {
throw new EncodingFormatException("SSB info code too big");
}
bits.putInteger(offset, 14, infoCode);
offset = offset + 14;
if (text.length() > 27) {
throw new EncodingFormatException("SSB text too big");
}
bits.putChar6String(offset, 162, text);
offset = offset + 162;
return offset;
}
public SsbStations getStations() {
return stations;
}
public int getTicketSubType() {
return ticketSubType;
}
public void setTicketSubType(int ticketSubType) {
this.ticketSubType = ticketSubType;
}
public int getDepartureDate() {
return departureDate;
}
public void setDepartureDate(int departureDate) {
this.departureDate = departureDate;
}
public int getDepartureTime() {
return departureTime;
}
public void setDepartureTime(int departureTime) {
this.departureTime = departureTime;
}
public String getTrain() {
return train;
}
public void setTrain(String train) {
this.train = train;
}
public int getCoach() {
return coach;
}
public void setCoach(int coach) {
this.coach = coach;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public boolean isOverbooking() {
return overbooking;
}
public void setOverbooking(boolean overbooking) {
this.overbooking = overbooking;
}
public int getInfoCode() {
return infoCode;
}
public void setInfoCode(int infoCode) {
this.infoCode = infoCode;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
|