mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Modifying Protocol Buffers (or Thrift, or MessagePack, or any of the free ASN.1 implementations I could find) to support length constraints was more work than writing a custom serialisation format, so I wrote a custom format.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,13 +0,0 @@
|
||||
package protocol;
|
||||
|
||||
option java_package = "net.sf.briar.api.protocol";
|
||||
|
||||
message TransportDetails {
|
||||
|
||||
message TransportDetail {
|
||||
required string key = 1;
|
||||
optional string value = 2;
|
||||
}
|
||||
|
||||
repeated TransportDetail details = 1;
|
||||
}
|
||||
9
api/net/sf/briar/api/serial/FormatException.java
Normal file
9
api/net/sf/briar/api/serial/FormatException.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FormatException extends IOException {
|
||||
|
||||
private static final long serialVersionUID = 2274966775687766337L;
|
||||
|
||||
}
|
||||
6
api/net/sf/briar/api/serial/Raw.java
Normal file
6
api/net/sf/briar/api/serial/Raw.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
public interface Raw {
|
||||
|
||||
byte[] getBytes();
|
||||
}
|
||||
54
api/net/sf/briar/api/serial/Reader.java
Normal file
54
api/net/sf/briar/api/serial/Reader.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Reader {
|
||||
|
||||
boolean eof() throws IOException;
|
||||
|
||||
boolean hasBoolean() throws IOException;
|
||||
boolean readBoolean() throws IOException;
|
||||
|
||||
boolean hasUint7() throws IOException;
|
||||
byte readUint7() throws IOException;
|
||||
boolean hasInt8() throws IOException;
|
||||
byte readInt8() throws IOException;
|
||||
boolean hasInt16() throws IOException;
|
||||
short readInt16() throws IOException;
|
||||
boolean hasInt32() throws IOException;
|
||||
int readInt32() throws IOException;
|
||||
boolean hasInt64() throws IOException;
|
||||
long readInt64() throws IOException;
|
||||
boolean hasIntAny() throws IOException;
|
||||
long readIntAny() throws IOException;
|
||||
|
||||
boolean hasFloat32() throws IOException;
|
||||
float readFloat32() throws IOException;
|
||||
boolean hasFloat64() throws IOException;
|
||||
double readFloat64() throws IOException;
|
||||
|
||||
boolean hasUtf8() throws IOException;
|
||||
String readUtf8() throws IOException;
|
||||
String readUtf8(int maxLength) throws IOException;
|
||||
|
||||
boolean hasRaw() throws IOException;
|
||||
byte[] readRaw() throws IOException;
|
||||
byte[] readRaw(int maxLength) throws IOException;
|
||||
|
||||
// FIXME: Add type-safe readers and iterator readers
|
||||
|
||||
boolean hasList(boolean definite) throws IOException;
|
||||
List<?> readList(boolean definite) throws IOException;
|
||||
boolean hasList() throws IOException;
|
||||
List<?> readList() throws IOException;
|
||||
|
||||
boolean hasMap(boolean definite) throws IOException;
|
||||
Map<?, ?> readMap(boolean definite) throws IOException;
|
||||
boolean hasMap() throws IOException;
|
||||
Map<?, ?> readMap() throws IOException;
|
||||
|
||||
boolean hasNull() throws IOException;
|
||||
void readNull() throws IOException;
|
||||
}
|
||||
8
api/net/sf/briar/api/serial/ReaderFactory.java
Normal file
8
api/net/sf/briar/api/serial/ReaderFactory.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface ReaderFactory {
|
||||
|
||||
Reader createReader(InputStream in);
|
||||
}
|
||||
13
api/net/sf/briar/api/serial/Tag.java
Normal file
13
api/net/sf/briar/api/serial/Tag.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
public interface Tag {
|
||||
|
||||
// FIXME: Definite lists and maps
|
||||
public static final byte FALSE = -1, TRUE = -2;
|
||||
public static final byte INT8 = -3, INT16 = -4, INT32 = -5, INT64 = -6;
|
||||
public static final byte FLOAT32 = -7, FLOAT64 = -8;
|
||||
public static final byte UTF8 = -9, RAW = -10;
|
||||
public static final byte LIST_DEF = -11, MAP_DEF = -12;
|
||||
public static final byte LIST_INDEF = -13, MAP_INDEF = -14, END = -15;
|
||||
public static final byte NULL = -16;
|
||||
}
|
||||
32
api/net/sf/briar/api/serial/Writer.java
Normal file
32
api/net/sf/briar/api/serial/Writer.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Writer {
|
||||
|
||||
void writeBoolean(boolean b) throws IOException;
|
||||
|
||||
void writeUint7(byte b) throws IOException;
|
||||
void writeInt8(byte b) throws IOException;
|
||||
void writeInt16(short s) throws IOException;
|
||||
void writeInt32(int i) throws IOException;
|
||||
void writeInt64(long l) throws IOException;
|
||||
void writeIntAny(long l) throws IOException;
|
||||
|
||||
void writeFloat32(float f) throws IOException;
|
||||
void writeFloat64(double d) throws IOException;
|
||||
|
||||
void writeUtf8(String s) throws IOException;
|
||||
void writeRaw(byte[] b) throws IOException;
|
||||
void writeRaw(Raw r) throws IOException;
|
||||
|
||||
void writeList(List<?> l, boolean definite) throws IOException;
|
||||
void writeList(List<?> l) throws IOException;
|
||||
|
||||
void writeMap(Map<?, ?> m, boolean definite) throws IOException;
|
||||
void writeMap(Map<?, ?> m) throws IOException;
|
||||
|
||||
void writeNull() throws IOException;
|
||||
}
|
||||
8
api/net/sf/briar/api/serial/WriterFactory.java
Normal file
8
api/net/sf/briar/api/serial/WriterFactory.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface WriterFactory {
|
||||
|
||||
Writer createWriter(OutputStream out);
|
||||
}
|
||||
Reference in New Issue
Block a user