writer.write(i + 4);
}
<<<<<<< HEAD
public byte[] readByte() throws IOException {
int tag = reader.readUnsignedByte();
return readByte(tag);
}
public byte[] readByte(int tag) throws IOException {
int length = 0;
if (tag == 15)
length = reader.readUnsignedByte();
else if (tag == 16)
length = reader.readInt();
byte[] value = new byte[length];
reader.readFully(value);
return value;
}
public void writeByte(byte[] value) throws IOException {
if (value.length > 255) {
writer.write(15);
writer.writeByte(value.length);
} else {
writer.write(16);
writer.writeInt(value.length);
}
writer.write(value);
}
=======
public TWPStruct readStruct() throws IOException {
TWPStruct struct = new TWPStruct();
int type = reader.readByte();
if (type == 12) {
struct.setId(reader.readInt());
}
while (true) {
type = reader.readByte();
if (type == 0)
break;
if (13 >= type && type <= 14)
struct.add(new Parameter(getParameterType(type), readInteger(type)));
if (17 >= type && type <= 127)
struct.add(new Parameter(getParameterType(type), readString(type)));
}
return struct;
}
public void writeStruct(TWPStruct struct) throws IOException {
if (struct.getId() == (Integer) null) {
writer.write(2);
} else {
writer.write(12);
writer.writeInt(struct.getId());
}
Iterator iterator = struct.getFields().iterator();
while (iterator.hasNext()) {
Parameter param = iterator.next();
if (param.getType() == ParameterType.SHORT_INTEGER || param.getType() == ParameterType.LONG_INTEGER) {
writeInteger((Integer) param.getValue());
}
if (param.getType() == ParameterType.SHORT_STRING || param.getType() == ParameterType.LONG_STRING) {
writeString((String) param.getValue());
}
}
writer.write(0);
}
>>>>>>> af83223a6dfb9f1927540a3c7eef540a1d5092dd
public int readInteger() throws IOException {
int type = reader.readUnsignedByte(); |