Nested user-defined objects (and collections of them) can now be read

by registering ObjectReaders with the Reader.
This commit is contained in:
akwizgran
2011-07-19 17:17:45 +01:00
parent a9e7cbd05c
commit fb528a85ad
22 changed files with 414 additions and 177 deletions

View File

@@ -2,6 +2,7 @@ package net.sf.briar.api.protocol;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collection;
import java.util.Map;
import net.sf.briar.api.serial.Raw;
@@ -16,12 +17,12 @@ public interface BundleWriter {
long getRemainingCapacity() throws IOException;
/** Adds a header to the bundle. */
void addHeader(Iterable<BatchId> acks, Iterable<GroupId> subs,
void addHeader(Collection<BatchId> acks, Collection<GroupId> subs,
Map<String, String> transports) throws IOException,
GeneralSecurityException;
/** Adds a batch of messages to the bundle and returns its identifier. */
BatchId addBatch(Iterable<Raw> messages) throws IOException,
BatchId addBatch(Collection<Raw> messages) throws IOException,
GeneralSecurityException;
/** Finishes writing the bundle. */

View File

@@ -2,15 +2,17 @@ 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 AUTHOR_ID = 1;
static final int BATCH = 2;
static final int BATCH_ID = 3;
static final int GROUP_ID = 4;
static final int HEADER = 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;
static final int MESSAGE_BODY = 7;
static final int MESSAGE_ID = 8;
static final int NICKNAME = 9;
static final int PUBLIC_KEY = 10;
static final int SIGNATURE = 12;
static final int TIMESTAMP = 13;
static final int TRANSPORTS = 14;
}

View File

@@ -0,0 +1,8 @@
package net.sf.briar.api.serial;
import java.io.IOException;
public interface ObjectReader<T> {
T readObject(Reader r) throws IOException;
}

View File

@@ -12,6 +12,9 @@ public interface Reader {
void addConsumer(Consumer c);
void removeConsumer(Consumer c);
void addObjectReader(int tag, ObjectReader<?> o);
void removeObjectReader(int tag);
boolean hasBoolean() throws IOException;
boolean readBoolean() throws IOException;
@@ -60,4 +63,5 @@ public interface Reader {
boolean hasUserDefinedTag() throws IOException;
int readUserDefinedTag() throws IOException;
void readUserDefinedTag(int tag) throws IOException;
<T> T readUserDefinedObject(int tag) throws IOException;
}

View File

@@ -1,7 +1,7 @@
package net.sf.briar.api.serial;
import java.io.IOException;
import java.util.List;
import java.util.Collection;
import java.util.Map;
public interface Writer {
@@ -25,7 +25,7 @@ public interface Writer {
void writeRaw(byte[] b) throws IOException;
void writeRaw(Raw r) throws IOException;
void writeList(List<?> l) throws IOException;
void writeList(Collection<?> c) throws IOException;
void writeListStart() throws IOException;
void writeListEnd() throws IOException;