Defined some user-defined tags for protocol elements. Currently they're just adding redundancy, but in future they'll be used for parsing nested elements.

This commit is contained in:
akwizgran
2011-07-18 17:44:18 +01:00
parent 427142ae51
commit 30fc6c1a92
14 changed files with 146 additions and 52 deletions

View File

@@ -1,7 +1,10 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
import java.util.Arrays;
import net.sf.briar.api.serial.Writer;
/** Type-safe wrapper for a byte array that uniquely identifies an author. */
public class AuthorId extends UniqueId {
@@ -9,6 +12,11 @@ public class AuthorId extends UniqueId {
super(id);
}
public void writeTo(Writer w) throws IOException {
w.writeUserDefinedTag(Tags.AUTHOR_ID);
w.writeRaw(id);
}
@Override
public boolean equals(Object o) {
if(o instanceof AuthorId)

View File

@@ -1,7 +1,10 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
import java.util.Arrays;
import net.sf.briar.api.serial.Writer;
/**
* Type-safe wrapper for a byte array that uniquely identifies a batch of
* messages.
@@ -12,6 +15,11 @@ public class BatchId extends UniqueId {
super(id);
}
public void writeTo(Writer w) throws IOException {
w.writeUserDefinedTag(Tags.BATCH_ID);
w.writeRaw(id);
}
@Override
public boolean equals(Object o) {
if(o instanceof BatchId)

View File

@@ -1,7 +1,10 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
import java.util.Arrays;
import net.sf.briar.api.serial.Writer;
/**
* Type-safe wrapper for a byte array that uniquely identifies a group to which
* users may subscribe.
@@ -12,6 +15,11 @@ public class GroupId extends UniqueId {
super(id);
}
public void writeTo(Writer w) throws IOException {
w.writeUserDefinedTag(Tags.GROUP_ID);
w.writeRaw(id);
}
@Override
public boolean equals(Object o) {
if(o instanceof GroupId)

View File

@@ -1,7 +1,10 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
import java.util.Arrays;
import net.sf.briar.api.serial.Writer;
/** Type-safe wrapper for a byte array that uniquely identifies a message. */
public class MessageId extends UniqueId {
@@ -15,6 +18,11 @@ public class MessageId extends UniqueId {
super(id);
}
public void writeTo(Writer w) throws IOException {
w.writeUserDefinedTag(Tags.MESSAGE_ID);
w.writeRaw(id);
}
@Override
public boolean equals(Object o) {
if(o instanceof MessageId)

View File

@@ -0,0 +1,16 @@
package net.sf.briar.api.protocol;
public interface Tags {
static final int HEADER = 0;
static final int BATCH_ID = 1;
static final int GROUP_ID = 2;
static final int TIMESTAMP = 3;
static final int SIGNATURE = 4;
static final int BATCH = 5;
static final int MESSAGE = 6;
static final int MESSAGE_ID = 7;
static final int AUTHOR = 8;
static final int MESSAGE_BODY = 9;
static final int AUTHOR_ID = 10;
}

View File

@@ -3,8 +3,9 @@ package net.sf.briar.api.protocol;
import java.util.Arrays;
import net.sf.briar.api.serial.Raw;
import net.sf.briar.api.serial.Writable;
public abstract class UniqueId implements Raw {
public abstract class UniqueId implements Raw, Writable {
public static final int LENGTH = 32;

View File

@@ -59,4 +59,5 @@ public interface Reader {
boolean hasUserDefinedTag() throws IOException;
int readUserDefinedTag() throws IOException;
void readUserDefinedTag(int i) throws IOException;
}

View File

@@ -2,30 +2,30 @@ package net.sf.briar.api.serial;
public interface Tag {
public static final byte FALSE = -1; // 1111 1111
public static final byte TRUE = -2; // 1111 1110
public static final byte INT8 = -3; // 1111 1101
public static final byte INT16 = -4; // 1111 1100
public static final byte INT32 = -5; // 1111 1011
public static final byte INT64 = -6; // 1111 1010
public static final byte FLOAT32 = -7; // 1111 1001
public static final byte FLOAT64 = -8; // 1111 1000
public static final byte STRING = -9; // 1111 0111
public static final byte RAW = -10; // 1111 0110
public static final byte LIST = -11; // 1111 0101
public static final byte MAP = -12; // 1111 0100
public static final byte LIST_START = -13; // 1111 0011
public static final byte MAP_START = -14; // 1111 0010
public static final byte END = -15; // 1111 0001
public static final byte NULL = -16; // 1111 0000
static final byte FALSE = -1; // 1111 1111
static final byte TRUE = -2; // 1111 1110
static final byte INT8 = -3; // 1111 1101
static final byte INT16 = -4; // 1111 1100
static final byte INT32 = -5; // 1111 1011
static final byte INT64 = -6; // 1111 1010
static final byte FLOAT32 = -7; // 1111 1001
static final byte FLOAT64 = -8; // 1111 1000
static final byte STRING = -9; // 1111 0111
static final byte RAW = -10; // 1111 0110
static final byte LIST = -11; // 1111 0101
static final byte MAP = -12; // 1111 0100
static final byte LIST_START = -13; // 1111 0011
static final byte MAP_START = -14; // 1111 0010
static final byte END = -15; // 1111 0001
static final byte NULL = -16; // 1111 0000
static final byte USER = -17; // 1110 1111
public static final byte USER = -32; // 1110 0000
static final int SHORT_MASK = 0xF0; // Match first four bits
static final int SHORT_STRING = 0x80; // 1000 xxxx
static final int SHORT_RAW = 0x90; // 1001 xxxx
static final int SHORT_LIST = 0xA0; // 1010 xxxx
static final int SHORT_MAP = 0xB0; // 1011 xxxx
public static final int SHORT_MASK = 0xF0; // Match first four bits
public static final int SHORT_STRING = 0x80; // 1000 xxxx
public static final int SHORT_RAW = 0x90; // 1001 xxxx
public static final int SHORT_LIST = 0xA0; // 1010 xxxx
public static final int SHORT_MAP = 0xB0; // 1011 xxxx
public static final int SHORT_USER_MASK = 0xE0; // Match first three bits
public static final int SHORT_USER = 0xC0; // 110x xxxx
static final int SHORT_USER_MASK = 0xE0; // Match first three bits
static final int SHORT_USER = 0xC0; // 110x xxxx
}

View File

@@ -0,0 +1,8 @@
package net.sf.briar.api.serial;
import java.io.IOException;
public interface Writable {
void writeTo(Writer w) throws IOException;
}