-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSprotoTypeReader.java
executable file
·64 lines (49 loc) · 1.39 KB
/
SprotoTypeReader.java
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
package com.lxz.sproto;
public class SprotoTypeReader {
public byte[] buffer;
private int begin;
private int pos;
private int size;
public int getPosition() {
return this.pos - this.begin;
}
public int getOffset() {
return this.pos;
}
public int getLength() {
return this.size - this.begin;
}
public SprotoTypeReader (byte[] buffer, int offset, int size) {
this.Init(buffer, offset, size);
}
public SprotoTypeReader() {
}
public void Init(byte[] buffer, int offset, int size) {
this.begin = offset;
this.pos = offset;
this.buffer = buffer;
this.size = offset + size;
this.check ();
}
private void check() {
if(this.pos > this.size || this.begin > this.pos) {
SprotoTypeSize.error("invalid pos.");
}
}
public byte ReadByte () {
this.check();
return this.buffer [this.pos++];
}
public void Seek (int offset) {
this.pos = this.begin + offset;
this.check ();
}
public void Read(byte[] data, int offset, int size) {
int cur_pos = this.pos;
this.pos += size;
check ();
for (int i = cur_pos; i < this.pos; i++) {
data [offset + i - cur_pos] = this.buffer [i];
}
}
}