Removed unnecessary Raw interface.

This commit is contained in:
akwizgran
2011-07-24 17:47:17 +01:00
parent 941460e3bc
commit c98c968b87
24 changed files with 80 additions and 115 deletions

View File

@@ -14,7 +14,7 @@ public class AuthorId extends UniqueId {
public void writeTo(Writer w) throws IOException {
w.writeUserDefinedTag(Tags.AUTHOR_ID);
w.writeRaw(id);
w.writeBytes(id);
}
@Override

View File

@@ -17,7 +17,7 @@ public class BatchId extends UniqueId {
public void writeTo(Writer w) throws IOException {
w.writeUserDefinedTag(Tags.BATCH_ID);
w.writeRaw(id);
w.writeBytes(id);
}
@Override

View File

@@ -17,7 +17,7 @@ public class GroupId extends UniqueId {
public void writeTo(Writer w) throws IOException {
w.writeUserDefinedTag(Tags.GROUP_ID);
w.writeRaw(id);
w.writeBytes(id);
}
@Override

View File

@@ -1,10 +1,8 @@
package net.sf.briar.api.protocol;
import net.sf.briar.api.serial.Raw;
public interface Message {
public interface Message extends Raw {
static final int MAX_SIZE = 1024 * 1023; // Not a typo
static final int MAX_SIZE = (1024 * 1024) - 200;
/** Returns the message's unique identifier. */
MessageId getId();
@@ -26,4 +24,7 @@ public interface Message extends Raw {
/** Returns the size of the message in bytes. */
int getSize();
/** Returns the serialised representation of the message. */
byte[] getBytes();
}

View File

@@ -20,7 +20,7 @@ public class MessageId extends UniqueId {
public void writeTo(Writer w) throws IOException {
w.writeUserDefinedTag(Tags.MESSAGE_ID);
w.writeRaw(id);
w.writeBytes(id);
}
@Override

View File

@@ -2,10 +2,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, Writable {
public abstract class UniqueId implements Writable {
public static final int LENGTH = 32;
public static final int SERIALISED_LENGTH = LENGTH + 3;

View File

@@ -2,13 +2,12 @@ package net.sf.briar.api.serial;
import java.util.Arrays;
/** A byte array wrapped in the Raw interface. */
public class RawByteArray implements Raw {
/** A wrapper around a byte array, to allow it to be stored in maps etc. */
public class Bytes {
private final byte[] bytes;
public RawByteArray(byte[] bytes) {
public Bytes(byte[] bytes) {
this.bytes = bytes;
}
@@ -23,7 +22,8 @@ public class RawByteArray implements Raw {
@Override
public boolean equals(Object o) {
if(o instanceof Raw) return Arrays.equals(bytes, ((Raw) o).getBytes());
if(o instanceof Bytes)
return Arrays.equals(bytes, ((Bytes) o).bytes);
return false;
}
}

View File

@@ -1,10 +0,0 @@
package net.sf.briar.api.serial;
/**
* Generic interface for any object that knows how to serialise itself as a
* raw byte array.
*/
public interface Raw {
byte[] getBytes();
}

View File

@@ -38,8 +38,8 @@ public interface Reader {
boolean hasString() throws IOException;
String readString() throws IOException;
boolean hasRaw() throws IOException;
byte[] readRaw() throws IOException;
boolean hasBytes() throws IOException;
byte[] readBytes() throws IOException;
boolean hasList() throws IOException;
List<Object> readList() throws IOException;

View File

@@ -11,7 +11,7 @@ public interface Tag {
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 BYTES = -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
@@ -22,7 +22,7 @@ public interface Tag {
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_BYTES = 0x90; // 1001 xxxx
static final int SHORT_LIST = 0xA0; // 1010 xxxx
static final int SHORT_MAP = 0xB0; // 1011 xxxx

View File

@@ -21,8 +21,7 @@ public interface Writer {
void writeFloat64(double d) throws IOException;
void writeString(String s) throws IOException;
void writeRaw(byte[] b) throws IOException;
void writeRaw(Raw r) throws IOException;
void writeBytes(byte[] b) throws IOException;
void writeList(Collection<?> c) throws IOException;
void writeListStart() throws IOException;