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
|
package org.uic.barcode.ssbFrame;
import org.uic.barcode.asn1.uper.BitBuffer;
import org.uic.barcode.asn1.uper.ByteBitBuffer;
public abstract class SsbCommonTicketPart extends SsbTicketPart {
/*
Number of adult passengers Num (<100) 7,000
Number of child passengers Num (<100) 7,000
"specimen" code Bit Flag 1,000
Class of travel Lookup of 64 options 6,000
TCN: Issuing unique Ticket number 14 AlphaNum 84,000
Year of issue Num (0..9) 4,000
Issuing day, from first of January Num (<512) 9,000
*/
protected int numberOfAdults = 0;
protected int numberOfChildren = 0;
protected boolean specimen = true;
protected SsbClass classCode = null;
protected String ticketNumber = null;
protected int year = 0;
protected int day = 0;
protected int decodeCommonPart(byte[] bytes) {
BitBuffer bits = new ByteBitBuffer(bytes);
int offset = 27; // header offset
numberOfAdults = bits.getInteger(offset, 7);
offset = offset + 7;
numberOfChildren = bits.getInteger(offset, 7);
offset = offset + 7;
specimen = bits.get(offset);
offset++;
int classIndex = bits.getInteger(offset, 6);
classCode = SsbClass.values()[classIndex];
offset = offset + 6;
ticketNumber = bits.getChar6String(offset, 84);
offset = offset + 84;
year = bits.getInteger(offset, 4);
offset = offset + 4;
day = bits.getInteger(offset, 9);
offset = offset + 9;
return offset;
}
protected int encodeCommonPart(byte[] bytes) {
BitBuffer bits = new ByteBitBuffer(bytes);
int offset = 27; // header offset
bits.putInteger(offset,7, numberOfAdults);
offset = offset + 7;
bits.putInteger(numberOfChildren,offset, 7);
offset = offset + 7;
bits.put(offset,specimen);
offset++;
bits.putInteger(offset, 6,classCode.ordinal());
offset = offset + 6;
bits.putChar6String(offset, 84, ticketNumber);
offset = offset + 84;
bits.putInteger(offset, 4, year);
offset = offset + 4;
bits.putInteger(offset, 9, day);
offset = offset + 9;
return offset;
}
public int getNumberOfAdults() {
return numberOfAdults;
}
public void setNumberOfAdults(int numberOfAdults) {
this.numberOfAdults = numberOfAdults;
}
public int getNumberOfChildren() {
return numberOfChildren;
}
public void setNumberOfChildren(int numberOfChildren) {
this.numberOfChildren = numberOfChildren;
}
public boolean isSpecimen() {
return specimen;
}
public void setSpecimen(boolean specimen) {
this.specimen = specimen;
}
public SsbClass getClassCode() {
return classCode;
}
public void setClassCode(SsbClass classCode) {
this.classCode = classCode;
}
public String getTicketNumber() {
return ticketNumber;
}
public void setTicketNumber(String ticketNumber) {
this.ticketNumber = ticketNumber;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
}
|