mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Read and write user-defined tags.
This commit is contained in:
@@ -459,4 +459,23 @@ class ReaderImpl implements Reader {
|
||||
if(!hasNull()) throw new FormatException();
|
||||
readNext(true);
|
||||
}
|
||||
|
||||
public boolean hasUserDefinedTag() throws IOException {
|
||||
if(!started) readNext(true);
|
||||
if(eof) return false;
|
||||
return next == Tag.USER ||
|
||||
(next & Tag.SHORT_USER_MASK) == Tag.SHORT_USER;
|
||||
}
|
||||
|
||||
public int readUserDefinedTag() throws IOException {
|
||||
if(!hasUserDefinedTag()) throw new FormatException();
|
||||
if(next == Tag.USER) {
|
||||
readNext(false);
|
||||
return readLength();
|
||||
} else {
|
||||
int tag = 0xFF & next ^ Tag.SHORT_USER;
|
||||
readNext(true);
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,4 +211,14 @@ class WriterImpl implements Writer {
|
||||
out.write(Tag.NULL);
|
||||
bytesWritten++;
|
||||
}
|
||||
|
||||
public void writeUserDefinedTag(int tag) throws IOException {
|
||||
if(tag < 0) throw new IllegalArgumentException();
|
||||
if(tag < 32) out.write((byte) (Tag.SHORT_USER | tag));
|
||||
else {
|
||||
out.write(Tag.USER);
|
||||
writeLength(tag);
|
||||
}
|
||||
bytesWritten++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user