Newer
Older
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
/**
* @author ETSI / STF462 / Alexandre Berge
* @version $URL$
* $Id$
*/
package org.etsi.ttcn.codec;
import org.etsi.ttcn.tci.Type;
import org.etsi.ttcn.tci.Value;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ICodec {
public ICodec(MainCodec mainCodec) {
this.mainCodec = mainCodec;
this.len = -1;
}
public Value decode(CodecBuffer buf, Type decodingHypothesis) {
return null;
}
public CodecBuffer encode(Value value) {
return null;
}
protected int getVariantBitLength(String variant) {
try {
Matcher matcher = PATTERN_VARIANT.matcher(variant);
if(matcher.find()) {
return java.lang.Integer.parseInt(matcher.group(3));
}
}
catch(Exception e) {
// Empty on purpose
}
return 0;
}
protected int getEncodingLength(String encoding) {
try {
Matcher matcher = PATTERN_ENCODING.matcher(encoding);
if(matcher.find()) {
return java.lang.Integer.parseInt(matcher.group(1));
}
}
catch(Exception e) {
// Empty on purpose
}
return 0;
}
protected void setLength(int len) {
this.len = len;
}
protected int getLength() {
return len;
}
protected void preDecode(CodecBuffer buf, Type decodingHypothesis) {
return;
}
public CodecBuffer preEncode(Value value) {
return null;
}
protected final static Pattern PATTERN_VARIANT = Pattern.compile("((\\w+)\\s+)?((\\d+))\\s+bit");
protected final static Pattern PATTERN_ENCODING = Pattern.compile("length\\((\\d+)\\)");
protected MainCodec mainCodec;
private int len;
}