mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Renamed user-defined tags "user-defined type identifiers".
This commit is contained in:
@@ -16,7 +16,7 @@ public class AuthorId extends UniqueId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeTo(Writer w) throws IOException {
|
public void writeTo(Writer w) throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.AUTHOR_ID);
|
w.writeUserDefinedTag(Types.AUTHOR_ID);
|
||||||
w.writeBytes(id);
|
w.writeBytes(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class BatchId extends UniqueId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeTo(Writer w) throws IOException {
|
public void writeTo(Writer w) throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.BATCH_ID);
|
w.writeUserDefinedTag(Types.BATCH_ID);
|
||||||
w.writeBytes(id);
|
w.writeBytes(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class GroupId extends UniqueId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeTo(Writer w) throws IOException {
|
public void writeTo(Writer w) throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.GROUP_ID);
|
w.writeUserDefinedTag(Types.GROUP_ID);
|
||||||
w.writeBytes(id);
|
w.writeBytes(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class MessageId extends UniqueId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeTo(Writer w) throws IOException {
|
public void writeTo(Writer w) throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.MESSAGE_ID);
|
w.writeUserDefinedTag(Types.MESSAGE_ID);
|
||||||
w.writeBytes(id);
|
w.writeBytes(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package net.sf.briar.api.protocol;
|
package net.sf.briar.api.protocol;
|
||||||
|
|
||||||
/**
|
/** User-defined type identifiers for encoding and decoding protocol objects. */
|
||||||
* User-defined tags for encoding and decoding protocol objects. An object
|
public interface Types {
|
||||||
* should have a user-defined tag if it appears in a list or a map, or if
|
|
||||||
* objects of different types may be encountered in a given protocol state.
|
|
||||||
*/
|
|
||||||
public interface Tags {
|
|
||||||
|
|
||||||
static final int ACK = 0;
|
static final int ACK = 0;
|
||||||
static final int AUTHOR = 1;
|
static final int AUTHOR = 1;
|
||||||
@@ -18,8 +18,8 @@ public interface Reader {
|
|||||||
void addConsumer(Consumer c);
|
void addConsumer(Consumer c);
|
||||||
void removeConsumer(Consumer c);
|
void removeConsumer(Consumer c);
|
||||||
|
|
||||||
void addObjectReader(int tag, ObjectReader<?> o);
|
void addObjectReader(int id, ObjectReader<?> o);
|
||||||
void removeObjectReader(int tag);
|
void removeObjectReader(int id);
|
||||||
|
|
||||||
boolean hasBoolean() throws IOException;
|
boolean hasBoolean() throws IOException;
|
||||||
boolean readBoolean() throws IOException;
|
boolean readBoolean() throws IOException;
|
||||||
@@ -69,7 +69,7 @@ public interface Reader {
|
|||||||
boolean hasNull() throws IOException;
|
boolean hasNull() throws IOException;
|
||||||
void readNull() throws IOException;
|
void readNull() throws IOException;
|
||||||
|
|
||||||
boolean hasUserDefined(int tag) throws IOException;
|
boolean hasUserDefined(int id) throws IOException;
|
||||||
<T> T readUserDefined(int tag, Class<T> t) throws IOException;
|
<T> T readUserDefined(int id, Class<T> t) throws IOException;
|
||||||
void readUserDefinedTag(int tag) throws IOException;
|
void readUserDefinedId(int id) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.sf.briar.api.FormatException;
|
|||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -28,11 +28,11 @@ class AckReader implements ObjectReader<Ack> {
|
|||||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
// Read and digest the data
|
// Read and digest the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readUserDefinedTag(Tags.ACK);
|
r.readUserDefinedId(Types.ACK);
|
||||||
r.addObjectReader(Tags.BATCH_ID, batchIdReader);
|
r.addObjectReader(Types.BATCH_ID, batchIdReader);
|
||||||
Collection<BatchId> batches = r.readList(BatchId.class);
|
Collection<BatchId> batches = r.readList(BatchId.class);
|
||||||
if(batches.size() > Ack.MAX_IDS_PER_ACK) throw new FormatException();
|
if(batches.size() > Ack.MAX_IDS_PER_ACK) throw new FormatException();
|
||||||
r.removeObjectReader(Tags.BATCH_ID);
|
r.removeObjectReader(Types.BATCH_ID);
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
// Build and return the ack
|
// Build and return the ack
|
||||||
return ackFactory.createAck(batches);
|
return ackFactory.createAck(batches);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import net.sf.briar.api.protocol.Author;
|
import net.sf.briar.api.protocol.Author;
|
||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
|
|
||||||
class AuthorImpl implements Author {
|
class AuthorImpl implements Author {
|
||||||
@@ -32,7 +32,7 @@ class AuthorImpl implements Author {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeTo(Writer w) throws IOException {
|
public void writeTo(Writer w) throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.AUTHOR);
|
w.writeUserDefinedTag(Types.AUTHOR);
|
||||||
w.writeString(name);
|
w.writeString(name);
|
||||||
w.writeBytes(publicKey);
|
w.writeBytes(publicKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
|||||||
import net.sf.briar.api.protocol.Author;
|
import net.sf.briar.api.protocol.Author;
|
||||||
import net.sf.briar.api.protocol.AuthorFactory;
|
import net.sf.briar.api.protocol.AuthorFactory;
|
||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ class AuthorReader implements ObjectReader<Author> {
|
|||||||
messageDigest.reset();
|
messageDigest.reset();
|
||||||
// Read and digest the data
|
// Read and digest the data
|
||||||
r.addConsumer(digesting);
|
r.addConsumer(digesting);
|
||||||
r.readUserDefinedTag(Tags.AUTHOR);
|
r.readUserDefinedId(Types.AUTHOR);
|
||||||
String name = r.readString(Author.MAX_NAME_LENGTH);
|
String name = r.readString(Author.MAX_NAME_LENGTH);
|
||||||
byte[] publicKey = r.readBytes(Author.MAX_PUBLIC_KEY_LENGTH);
|
byte[] publicKey = r.readBytes(Author.MAX_PUBLIC_KEY_LENGTH);
|
||||||
r.removeConsumer(digesting);
|
r.removeConsumer(digesting);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
import net.sf.briar.api.protocol.UniqueId;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -12,7 +12,7 @@ import net.sf.briar.api.serial.Reader;
|
|||||||
class BatchIdReader implements ObjectReader<BatchId> {
|
class BatchIdReader implements ObjectReader<BatchId> {
|
||||||
|
|
||||||
public BatchId readObject(Reader r) throws IOException {
|
public BatchId readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(Tags.BATCH_ID);
|
r.readUserDefinedId(Types.BATCH_ID);
|
||||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
byte[] b = r.readBytes(UniqueId.LENGTH);
|
||||||
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
||||||
return new BatchId(b);
|
return new BatchId(b);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import net.sf.briar.api.protocol.Batch;
|
|||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -36,10 +36,10 @@ class BatchReader implements ObjectReader<Batch> {
|
|||||||
// Read and digest the data
|
// Read and digest the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.addConsumer(digesting);
|
r.addConsumer(digesting);
|
||||||
r.readUserDefinedTag(Tags.BATCH);
|
r.readUserDefinedId(Types.BATCH);
|
||||||
r.addObjectReader(Tags.MESSAGE, messageReader);
|
r.addObjectReader(Types.MESSAGE, messageReader);
|
||||||
List<Message> messages = r.readList(Message.class);
|
List<Message> messages = r.readList(Message.class);
|
||||||
r.removeObjectReader(Tags.MESSAGE);
|
r.removeObjectReader(Types.MESSAGE);
|
||||||
r.removeConsumer(digesting);
|
r.removeConsumer(digesting);
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
// Build and return the batch
|
// Build and return the batch
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
import net.sf.briar.api.protocol.GroupId;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
import net.sf.briar.api.protocol.UniqueId;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -12,7 +12,7 @@ import net.sf.briar.api.serial.Reader;
|
|||||||
class GroupIdReader implements ObjectReader<GroupId> {
|
class GroupIdReader implements ObjectReader<GroupId> {
|
||||||
|
|
||||||
public GroupId readObject(Reader r) throws IOException {
|
public GroupId readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(Tags.GROUP_ID);
|
r.readUserDefinedId(Types.GROUP_ID);
|
||||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
byte[] b = r.readBytes(UniqueId.LENGTH);
|
||||||
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
||||||
return new GroupId(b);
|
return new GroupId(b);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
import net.sf.briar.api.protocol.GroupId;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
|
|
||||||
class GroupImpl implements Group {
|
class GroupImpl implements Group {
|
||||||
@@ -32,7 +32,7 @@ class GroupImpl implements Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeTo(Writer w) throws IOException {
|
public void writeTo(Writer w) throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.GROUP);
|
w.writeUserDefinedTag(Types.GROUP);
|
||||||
w.writeString(name);
|
w.writeString(name);
|
||||||
if(publicKey == null) w.writeNull();
|
if(publicKey == null) w.writeNull();
|
||||||
else w.writeBytes(publicKey);
|
else w.writeBytes(publicKey);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
|||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.GroupFactory;
|
import net.sf.briar.api.protocol.GroupFactory;
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
import net.sf.briar.api.protocol.GroupId;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ class GroupReader implements ObjectReader<Group> {
|
|||||||
messageDigest.reset();
|
messageDigest.reset();
|
||||||
// Read and digest the data
|
// Read and digest the data
|
||||||
r.addConsumer(digesting);
|
r.addConsumer(digesting);
|
||||||
r.readUserDefinedTag(Tags.GROUP);
|
r.readUserDefinedId(Types.GROUP);
|
||||||
String name = r.readString(Group.MAX_NAME_LENGTH);
|
String name = r.readString(Group.MAX_NAME_LENGTH);
|
||||||
byte[] publicKey = null;
|
byte[] publicKey = null;
|
||||||
if(r.hasNull()) r.readNull();
|
if(r.hasNull()) r.readNull();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import net.sf.briar.api.protocol.Group;
|
|||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
import net.sf.briar.api.protocol.MessageEncoder;
|
import net.sf.briar.api.protocol.MessageEncoder;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ class MessageEncoderImpl implements MessageEncoder {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
// Write the message
|
// Write the message
|
||||||
w.writeUserDefinedTag(Tags.MESSAGE);
|
w.writeUserDefinedTag(Types.MESSAGE);
|
||||||
parent.writeTo(w);
|
parent.writeTo(w);
|
||||||
group.writeTo(w);
|
group.writeTo(w);
|
||||||
if(author == null) w.writeNull();
|
if(author == null) w.writeNull();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
import net.sf.briar.api.protocol.UniqueId;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -12,7 +12,7 @@ import net.sf.briar.api.serial.Reader;
|
|||||||
class MessageIdReader implements ObjectReader<MessageId> {
|
class MessageIdReader implements ObjectReader<MessageId> {
|
||||||
|
|
||||||
public MessageId readObject(Reader r) throws IOException {
|
public MessageId readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(Tags.MESSAGE_ID);
|
r.readUserDefinedId(Types.MESSAGE_ID);
|
||||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
byte[] b = r.readBytes(UniqueId.LENGTH);
|
||||||
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
||||||
return new MessageId(b);
|
return new MessageId(b);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import net.sf.briar.api.protocol.Group;
|
|||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
|
|
||||||
@@ -47,21 +47,21 @@ class MessageReader implements ObjectReader<Message> {
|
|||||||
r.addConsumer(copying);
|
r.addConsumer(copying);
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
// Read the initial tag
|
// Read the initial tag
|
||||||
r.readUserDefinedTag(Tags.MESSAGE);
|
r.readUserDefinedId(Types.MESSAGE);
|
||||||
// Read the parent's message ID
|
// Read the parent's message ID
|
||||||
r.addObjectReader(Tags.MESSAGE_ID, messageIdReader);
|
r.addObjectReader(Types.MESSAGE_ID, messageIdReader);
|
||||||
MessageId parent = r.readUserDefined(Tags.MESSAGE_ID, MessageId.class);
|
MessageId parent = r.readUserDefined(Types.MESSAGE_ID, MessageId.class);
|
||||||
r.removeObjectReader(Tags.MESSAGE_ID);
|
r.removeObjectReader(Types.MESSAGE_ID);
|
||||||
// Read the group
|
// Read the group
|
||||||
r.addObjectReader(Tags.GROUP, groupReader);
|
r.addObjectReader(Types.GROUP, groupReader);
|
||||||
Group group = r.readUserDefined(Tags.GROUP, Group.class);
|
Group group = r.readUserDefined(Types.GROUP, Group.class);
|
||||||
r.removeObjectReader(Tags.GROUP);
|
r.removeObjectReader(Types.GROUP);
|
||||||
// Read the author, if there is one
|
// Read the author, if there is one
|
||||||
r.addObjectReader(Tags.AUTHOR, authorReader);
|
r.addObjectReader(Types.AUTHOR, authorReader);
|
||||||
Author author = null;
|
Author author = null;
|
||||||
if(r.hasNull()) r.readNull();
|
if(r.hasNull()) r.readNull();
|
||||||
else author = r.readUserDefined(Tags.AUTHOR, Author.class);
|
else author = r.readUserDefined(Types.AUTHOR, Author.class);
|
||||||
r.removeObjectReader(Tags.AUTHOR);
|
r.removeObjectReader(Types.AUTHOR);
|
||||||
// Read the timestamp
|
// Read the timestamp
|
||||||
long timestamp = r.readInt64();
|
long timestamp = r.readInt64();
|
||||||
if(timestamp < 0L) throw new FormatException();
|
if(timestamp < 0L) throw new FormatException();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.sf.briar.api.FormatException;
|
|||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -29,12 +29,12 @@ class OfferReader implements ObjectReader<Offer> {
|
|||||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readUserDefinedTag(Tags.OFFER);
|
r.readUserDefinedId(Types.OFFER);
|
||||||
r.addObjectReader(Tags.MESSAGE_ID, messageIdReader);
|
r.addObjectReader(Types.MESSAGE_ID, messageIdReader);
|
||||||
Collection<MessageId> messages = r.readList(MessageId.class);
|
Collection<MessageId> messages = r.readList(MessageId.class);
|
||||||
if(messages.size() > Offer.MAX_IDS_PER_OFFER)
|
if(messages.size() > Offer.MAX_IDS_PER_OFFER)
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
r.removeObjectReader(Tags.MESSAGE_ID);
|
r.removeObjectReader(Types.MESSAGE_ID);
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
// Build and return the offer
|
// Build and return the offer
|
||||||
return offerFactory.createOffer(messages);
|
return offerFactory.createOffer(messages);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import net.sf.briar.api.protocol.Offer;
|
|||||||
import net.sf.briar.api.protocol.ProtocolReader;
|
import net.sf.briar.api.protocol.ProtocolReader;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -26,60 +26,60 @@ class ProtocolReaderImpl implements ProtocolReader {
|
|||||||
ObjectReader<SubscriptionUpdate> subscriptionReader,
|
ObjectReader<SubscriptionUpdate> subscriptionReader,
|
||||||
ObjectReader<TransportUpdate> transportReader) {
|
ObjectReader<TransportUpdate> transportReader) {
|
||||||
reader = readerFactory.createReader(in);
|
reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.ACK, ackReader);
|
reader.addObjectReader(Types.ACK, ackReader);
|
||||||
reader.addObjectReader(Tags.BATCH, batchReader);
|
reader.addObjectReader(Types.BATCH, batchReader);
|
||||||
reader.addObjectReader(Tags.OFFER, offerReader);
|
reader.addObjectReader(Types.OFFER, offerReader);
|
||||||
reader.addObjectReader(Tags.REQUEST, requestReader);
|
reader.addObjectReader(Types.REQUEST, requestReader);
|
||||||
reader.addObjectReader(Tags.SUBSCRIPTION_UPDATE, subscriptionReader);
|
reader.addObjectReader(Types.SUBSCRIPTION_UPDATE, subscriptionReader);
|
||||||
reader.addObjectReader(Tags.TRANSPORT_UPDATE, transportReader);
|
reader.addObjectReader(Types.TRANSPORT_UPDATE, transportReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAck() throws IOException {
|
public boolean hasAck() throws IOException {
|
||||||
return reader.hasUserDefined(Tags.ACK);
|
return reader.hasUserDefined(Types.ACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ack readAck() throws IOException {
|
public Ack readAck() throws IOException {
|
||||||
return reader.readUserDefined(Tags.ACK, Ack.class);
|
return reader.readUserDefined(Types.ACK, Ack.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBatch() throws IOException {
|
public boolean hasBatch() throws IOException {
|
||||||
return reader.hasUserDefined(Tags.BATCH);
|
return reader.hasUserDefined(Types.BATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Batch readBatch() throws IOException {
|
public Batch readBatch() throws IOException {
|
||||||
return reader.readUserDefined(Tags.BATCH, Batch.class);
|
return reader.readUserDefined(Types.BATCH, Batch.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasOffer() throws IOException {
|
public boolean hasOffer() throws IOException {
|
||||||
return reader.hasUserDefined(Tags.OFFER);
|
return reader.hasUserDefined(Types.OFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Offer readOffer() throws IOException {
|
public Offer readOffer() throws IOException {
|
||||||
return reader.readUserDefined(Tags.OFFER, Offer.class);
|
return reader.readUserDefined(Types.OFFER, Offer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRequest() throws IOException {
|
public boolean hasRequest() throws IOException {
|
||||||
return reader.hasUserDefined(Tags.REQUEST);
|
return reader.hasUserDefined(Types.REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request readRequest() throws IOException {
|
public Request readRequest() throws IOException {
|
||||||
return reader.readUserDefined(Tags.REQUEST, Request.class);
|
return reader.readUserDefined(Types.REQUEST, Request.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSubscriptionUpdate() throws IOException {
|
public boolean hasSubscriptionUpdate() throws IOException {
|
||||||
return reader.hasUserDefined(Tags.SUBSCRIPTION_UPDATE);
|
return reader.hasUserDefined(Types.SUBSCRIPTION_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubscriptionUpdate readSubscriptionUpdate() throws IOException {
|
public SubscriptionUpdate readSubscriptionUpdate() throws IOException {
|
||||||
return reader.readUserDefined(Tags.SUBSCRIPTION_UPDATE,
|
return reader.readUserDefined(Types.SUBSCRIPTION_UPDATE,
|
||||||
SubscriptionUpdate.class);
|
SubscriptionUpdate.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasTransportUpdate() throws IOException {
|
public boolean hasTransportUpdate() throws IOException {
|
||||||
return reader.hasUserDefined(Tags.TRANSPORT_UPDATE);
|
return reader.hasUserDefined(Types.TRANSPORT_UPDATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportUpdate readTransportUpdate() throws IOException {
|
public TransportUpdate readTransportUpdate() throws IOException {
|
||||||
return reader.readUserDefined(Tags.TRANSPORT_UPDATE, TransportUpdate.class);
|
return reader.readUserDefined(Types.TRANSPORT_UPDATE, TransportUpdate.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.util.BitSet;
|
|||||||
|
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -24,7 +24,7 @@ class RequestReader implements ObjectReader<Request> {
|
|||||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readUserDefinedTag(Tags.REQUEST);
|
r.readUserDefinedId(Types.REQUEST);
|
||||||
byte[] bitmap = r.readBytes(ProtocolConstants.MAX_PACKET_LENGTH);
|
byte[] bitmap = r.readBytes(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
// Convert the bitmap into a BitSet
|
// Convert the bitmap into a BitSet
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
|||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
@@ -28,10 +28,10 @@ class SubscriptionReader implements ObjectReader<SubscriptionUpdate> {
|
|||||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readUserDefinedTag(Tags.SUBSCRIPTION_UPDATE);
|
r.readUserDefinedId(Types.SUBSCRIPTION_UPDATE);
|
||||||
r.addObjectReader(Tags.GROUP, groupReader);
|
r.addObjectReader(Types.GROUP, groupReader);
|
||||||
Map<Group, Long> subs = r.readMap(Group.class, Long.class);
|
Map<Group, Long> subs = r.readMap(Group.class, Long.class);
|
||||||
r.removeObjectReader(Tags.GROUP);
|
r.removeObjectReader(Types.GROUP);
|
||||||
long timestamp = r.readInt64();
|
long timestamp = r.readInt64();
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
// Build and return the subscription update
|
// Build and return the subscription update
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
@@ -29,12 +29,12 @@ class TransportReader implements ObjectReader<TransportUpdate> {
|
|||||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readUserDefinedTag(Tags.TRANSPORT_UPDATE);
|
r.readUserDefinedId(Types.TRANSPORT_UPDATE);
|
||||||
r.addObjectReader(Tags.TRANSPORT_PROPERTIES, propertiesReader);
|
r.addObjectReader(Types.TRANSPORT_PROPERTIES, propertiesReader);
|
||||||
r.setMaxStringLength(ProtocolConstants.MAX_PACKET_LENGTH);
|
r.setMaxStringLength(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
List<TransportProperties> l = r.readList(TransportProperties.class);
|
List<TransportProperties> l = r.readList(TransportProperties.class);
|
||||||
r.resetMaxStringLength();
|
r.resetMaxStringLength();
|
||||||
r.removeObjectReader(Tags.TRANSPORT_PROPERTIES);
|
r.removeObjectReader(Types.TRANSPORT_PROPERTIES);
|
||||||
if(l.size() > TransportUpdate.MAX_PLUGINS_PER_UPDATE)
|
if(l.size() > TransportUpdate.MAX_PLUGINS_PER_UPDATE)
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
Map<String, Map<String, String>> transports =
|
Map<String, Map<String, String>> transports =
|
||||||
@@ -64,7 +64,7 @@ class TransportReader implements ObjectReader<TransportUpdate> {
|
|||||||
implements ObjectReader<TransportProperties> {
|
implements ObjectReader<TransportProperties> {
|
||||||
|
|
||||||
public TransportProperties readObject(Reader r) throws IOException {
|
public TransportProperties readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(Tags.TRANSPORT_PROPERTIES);
|
r.readUserDefinedId(Types.TRANSPORT_PROPERTIES);
|
||||||
String name = r.readString(TransportUpdate.MAX_NAME_LENGTH);
|
String name = r.readString(TransportUpdate.MAX_NAME_LENGTH);
|
||||||
r.setMaxStringLength(TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
r.setMaxStringLength(TransportUpdate.MAX_KEY_OR_VALUE_LENGTH);
|
||||||
Map<String, String> properties =
|
Map<String, String> properties =
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.writers.AckWriter;
|
import net.sf.briar.api.protocol.writers.AckWriter;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
@@ -25,7 +25,7 @@ class AckWriterImpl implements AckWriter {
|
|||||||
|
|
||||||
public boolean writeBatchId(BatchId b) throws IOException {
|
public boolean writeBatchId(BatchId b) throws IOException {
|
||||||
if(!started) {
|
if(!started) {
|
||||||
w.writeUserDefinedTag(Tags.ACK);
|
w.writeUserDefinedTag(Types.ACK);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ class AckWriterImpl implements AckWriter {
|
|||||||
|
|
||||||
public void finish() throws IOException {
|
public void finish() throws IOException {
|
||||||
if(!started) {
|
if(!started) {
|
||||||
w.writeUserDefinedTag(Tags.ACK);
|
w.writeUserDefinedTag(Types.ACK);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.security.MessageDigest;
|
|||||||
|
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.writers.BatchWriter;
|
import net.sf.briar.api.protocol.writers.BatchWriter;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
@@ -36,7 +36,7 @@ class BatchWriterImpl implements BatchWriter {
|
|||||||
public boolean writeMessage(byte[] message) throws IOException {
|
public boolean writeMessage(byte[] message) throws IOException {
|
||||||
if(!started) {
|
if(!started) {
|
||||||
messageDigest.reset();
|
messageDigest.reset();
|
||||||
w.writeUserDefinedTag(Tags.BATCH);
|
w.writeUserDefinedTag(Types.BATCH);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ class BatchWriterImpl implements BatchWriter {
|
|||||||
public BatchId finish() throws IOException {
|
public BatchId finish() throws IOException {
|
||||||
if(!started) {
|
if(!started) {
|
||||||
messageDigest.reset();
|
messageDigest.reset();
|
||||||
w.writeUserDefinedTag(Tags.BATCH);
|
w.writeUserDefinedTag(Types.BATCH);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.writers.OfferWriter;
|
import net.sf.briar.api.protocol.writers.OfferWriter;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
@@ -25,7 +25,7 @@ class OfferWriterImpl implements OfferWriter {
|
|||||||
|
|
||||||
public boolean writeMessageId(MessageId m) throws IOException {
|
public boolean writeMessageId(MessageId m) throws IOException {
|
||||||
if(!started) {
|
if(!started) {
|
||||||
w.writeUserDefinedTag(Tags.OFFER);
|
w.writeUserDefinedTag(Types.OFFER);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ class OfferWriterImpl implements OfferWriter {
|
|||||||
|
|
||||||
public void finish() throws IOException {
|
public void finish() throws IOException {
|
||||||
if(!started) {
|
if(!started) {
|
||||||
w.writeUserDefinedTag(Tags.OFFER);
|
w.writeUserDefinedTag(Types.OFFER);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.writers.RequestWriter;
|
import net.sf.briar.api.protocol.writers.RequestWriter;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
@@ -21,7 +21,7 @@ class RequestWriterImpl implements RequestWriter {
|
|||||||
|
|
||||||
public void writeRequest(BitSet b, int length)
|
public void writeRequest(BitSet b, int length)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.REQUEST);
|
w.writeUserDefinedTag(Types.REQUEST);
|
||||||
// If the number of bits isn't a multiple of 8, round up to a byte
|
// If the number of bits isn't a multiple of 8, round up to a byte
|
||||||
int bytes = length % 8 == 0 ? length / 8 : length / 8 + 1;
|
int bytes = length % 8 == 0 ? length / 8 : length / 8 + 1;
|
||||||
byte[] bitmap = new byte[bytes];
|
byte[] bitmap = new byte[bytes];
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.io.OutputStream;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.writers.SubscriptionWriter;
|
import net.sf.briar.api.protocol.writers.SubscriptionWriter;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
@@ -22,7 +22,7 @@ class SubscriptionWriterImpl implements SubscriptionWriter {
|
|||||||
|
|
||||||
public void writeSubscriptions(Map<Group, Long> subs, long timestamp)
|
public void writeSubscriptions(Map<Group, Long> subs, long timestamp)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.SUBSCRIPTION_UPDATE);
|
w.writeUserDefinedTag(Types.SUBSCRIPTION_UPDATE);
|
||||||
w.writeMap(subs);
|
w.writeMap(subs);
|
||||||
w.writeInt64(timestamp);
|
w.writeInt64(timestamp);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.io.OutputStream;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.writers.TransportWriter;
|
import net.sf.briar.api.protocol.writers.TransportWriter;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
@@ -22,10 +22,10 @@ class TransportWriterImpl implements TransportWriter {
|
|||||||
|
|
||||||
public void writeTransports(Map<String, Map<String, String>> transports,
|
public void writeTransports(Map<String, Map<String, String>> transports,
|
||||||
long timestamp) throws IOException {
|
long timestamp) throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.TRANSPORT_UPDATE);
|
w.writeUserDefinedTag(Types.TRANSPORT_UPDATE);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
for(Entry<String, Map<String, String>> e : transports.entrySet()) {
|
for(Entry<String, Map<String, String>> e : transports.entrySet()) {
|
||||||
w.writeUserDefinedTag(Tags.TRANSPORT_PROPERTIES);
|
w.writeUserDefinedTag(Types.TRANSPORT_PROPERTIES);
|
||||||
w.writeString(e.getKey());
|
w.writeString(e.getKey());
|
||||||
w.writeMap(e.getValue());
|
w.writeMap(e.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,21 +110,21 @@ class ReaderImpl implements Reader {
|
|||||||
else throw new IllegalArgumentException();
|
else throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addObjectReader(int tag, ObjectReader<?> o) {
|
public void addObjectReader(int id, ObjectReader<?> o) {
|
||||||
if(tag < 0 || tag > 255) throw new IllegalArgumentException();
|
if(id < 0 || id > 255) throw new IllegalArgumentException();
|
||||||
if(objectReaders.length < tag + 1) {
|
if(objectReaders.length < id + 1) {
|
||||||
ObjectReader<?>[] newObjectReaders = new ObjectReader<?>[tag + 1];
|
ObjectReader<?>[] newObjectReaders = new ObjectReader<?>[id + 1];
|
||||||
System.arraycopy(objectReaders, 0, newObjectReaders, 0,
|
System.arraycopy(objectReaders, 0, newObjectReaders, 0,
|
||||||
objectReaders.length);
|
objectReaders.length);
|
||||||
objectReaders = newObjectReaders;
|
objectReaders = newObjectReaders;
|
||||||
}
|
}
|
||||||
objectReaders[tag] = o;
|
objectReaders[id] = o;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeObjectReader(int tag) {
|
public void removeObjectReader(int id) {
|
||||||
if(tag < 0 || tag > objectReaders.length)
|
if(id < 0 || id > objectReaders.length)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
objectReaders[tag] = null;
|
objectReaders[id] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBoolean() throws IOException {
|
public boolean hasBoolean() throws IOException {
|
||||||
@@ -551,21 +551,21 @@ class ReaderImpl implements Reader {
|
|||||||
consumeLookahead();
|
consumeLookahead();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasUserDefined(int tag) throws IOException {
|
public boolean hasUserDefined(int id) throws IOException {
|
||||||
if(tag < 0 || tag > 255) throw new IllegalArgumentException();
|
if(id < 0 || id > 255) throw new IllegalArgumentException();
|
||||||
if(!hasLookahead) readLookahead(true);
|
if(!hasLookahead) readLookahead(true);
|
||||||
if(eof) return false;
|
if(eof) return false;
|
||||||
if(next == Tag.USER)
|
if(next == Tag.USER)
|
||||||
return tag == (0xFF & nextNext);
|
return id == (0xFF & nextNext);
|
||||||
else if((next & Tag.SHORT_USER_MASK) == Tag.SHORT_USER)
|
else if((next & Tag.SHORT_USER_MASK) == Tag.SHORT_USER)
|
||||||
return tag == (0xFF & next ^ Tag.SHORT_USER);
|
return id == (0xFF & next ^ Tag.SHORT_USER);
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T readUserDefined(int tag, Class<T> t) throws IOException {
|
public <T> T readUserDefined(int id, Class<T> t) throws IOException {
|
||||||
if(!hasUserDefined(tag)) throw new FormatException();
|
if(!hasUserDefined(id)) throw new FormatException();
|
||||||
if(tag >= objectReaders.length) throw new FormatException();
|
if(id >= objectReaders.length) throw new FormatException();
|
||||||
ObjectReader<?> o = objectReaders[tag];
|
ObjectReader<?> o = objectReaders[id];
|
||||||
if(o == null) throw new FormatException();
|
if(o == null) throw new FormatException();
|
||||||
try {
|
try {
|
||||||
return t.cast(o.readObject(this));
|
return t.cast(o.readObject(this));
|
||||||
@@ -574,8 +574,8 @@ class ReaderImpl implements Reader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readUserDefinedTag(int tag) throws IOException {
|
public void readUserDefinedId(int id) throws IOException {
|
||||||
if(!hasUserDefined(tag)) throw new FormatException();
|
if(!hasUserDefined(id)) throw new FormatException();
|
||||||
consumeLookahead();
|
consumeLookahead();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import net.sf.briar.api.FormatException;
|
|||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
import net.sf.briar.api.protocol.UniqueId;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.ReaderFactory;
|
import net.sf.briar.api.serial.ReaderFactory;
|
||||||
@@ -48,10 +48,10 @@ public class AckReaderTest extends TestCase {
|
|||||||
byte[] b = createAck(true);
|
byte[] b = createAck(true);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.ACK, ackReader);
|
reader.addObjectReader(Types.ACK, ackReader);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.readUserDefined(Tags.ACK, Ack.class);
|
reader.readUserDefined(Types.ACK, Ack.class);
|
||||||
fail();
|
fail();
|
||||||
} catch(FormatException expected) {}
|
} catch(FormatException expected) {}
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -71,9 +71,9 @@ public class AckReaderTest extends TestCase {
|
|||||||
byte[] b = createAck(false);
|
byte[] b = createAck(false);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.ACK, ackReader);
|
reader.addObjectReader(Types.ACK, ackReader);
|
||||||
|
|
||||||
assertEquals(ack, reader.readUserDefined(Tags.ACK, Ack.class));
|
assertEquals(ack, reader.readUserDefined(Types.ACK, Ack.class));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,27 +91,27 @@ public class AckReaderTest extends TestCase {
|
|||||||
byte[] b = createEmptyAck();
|
byte[] b = createEmptyAck();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.ACK, ackReader);
|
reader.addObjectReader(Types.ACK, ackReader);
|
||||||
|
|
||||||
assertEquals(ack, reader.readUserDefined(Tags.ACK, Ack.class));
|
assertEquals(ack, reader.readUserDefined(Types.ACK, Ack.class));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] createAck(boolean tooBig) throws Exception {
|
private byte[] createAck(boolean tooBig) throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeUserDefinedTag(Tags.ACK);
|
w.writeUserDefinedTag(Types.ACK);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
byte[] b = new byte[UniqueId.LENGTH];
|
byte[] b = new byte[UniqueId.LENGTH];
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
while(out.size() + BatchId.LENGTH + 3
|
while(out.size() + BatchId.LENGTH + 3
|
||||||
< ProtocolConstants.MAX_PACKET_LENGTH) {
|
< ProtocolConstants.MAX_PACKET_LENGTH) {
|
||||||
w.writeUserDefinedTag(Tags.BATCH_ID);
|
w.writeUserDefinedTag(Types.BATCH_ID);
|
||||||
random.nextBytes(b);
|
random.nextBytes(b);
|
||||||
w.writeBytes(b);
|
w.writeBytes(b);
|
||||||
}
|
}
|
||||||
if(tooBig) {
|
if(tooBig) {
|
||||||
w.writeUserDefinedTag(Tags.BATCH_ID);
|
w.writeUserDefinedTag(Types.BATCH_ID);
|
||||||
random.nextBytes(b);
|
random.nextBytes(b);
|
||||||
w.writeBytes(b);
|
w.writeBytes(b);
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ public class AckReaderTest extends TestCase {
|
|||||||
private byte[] createEmptyAck() throws Exception {
|
private byte[] createEmptyAck() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeUserDefinedTag(Tags.ACK);
|
w.writeUserDefinedTag(Types.ACK);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
w.writeListEnd();
|
w.writeListEnd();
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import net.sf.briar.api.protocol.Batch;
|
|||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
import net.sf.briar.api.serial.ObjectReader;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.ReaderFactory;
|
import net.sf.briar.api.serial.ReaderFactory;
|
||||||
@@ -58,10 +58,10 @@ public class BatchReaderTest extends TestCase {
|
|||||||
byte[] b = createBatch(ProtocolConstants.MAX_PACKET_LENGTH + 1);
|
byte[] b = createBatch(ProtocolConstants.MAX_PACKET_LENGTH + 1);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.BATCH, batchReader);
|
reader.addObjectReader(Types.BATCH, batchReader);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.readUserDefined(Tags.BATCH, Batch.class);
|
reader.readUserDefined(Types.BATCH, Batch.class);
|
||||||
fail();
|
fail();
|
||||||
} catch(FormatException expected) {}
|
} catch(FormatException expected) {}
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -83,9 +83,9 @@ public class BatchReaderTest extends TestCase {
|
|||||||
byte[] b = createBatch(ProtocolConstants.MAX_PACKET_LENGTH);
|
byte[] b = createBatch(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.BATCH, batchReader);
|
reader.addObjectReader(Types.BATCH, batchReader);
|
||||||
|
|
||||||
assertEquals(batch, reader.readUserDefined(Tags.BATCH, Batch.class));
|
assertEquals(batch, reader.readUserDefined(Types.BATCH, Batch.class));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,9 +112,9 @@ public class BatchReaderTest extends TestCase {
|
|||||||
|
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.BATCH, batchReader);
|
reader.addObjectReader(Types.BATCH, batchReader);
|
||||||
|
|
||||||
assertEquals(batch, reader.readUserDefined(Tags.BATCH, Batch.class));
|
assertEquals(batch, reader.readUserDefined(Types.BATCH, Batch.class));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,19 +134,19 @@ public class BatchReaderTest extends TestCase {
|
|||||||
byte[] b = createEmptyBatch();
|
byte[] b = createEmptyBatch();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.BATCH, batchReader);
|
reader.addObjectReader(Types.BATCH, batchReader);
|
||||||
|
|
||||||
assertEquals(batch, reader.readUserDefined(Tags.BATCH, Batch.class));
|
assertEquals(batch, reader.readUserDefined(Types.BATCH, Batch.class));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] createBatch(int size) throws Exception {
|
private byte[] createBatch(int size) throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream(size);
|
ByteArrayOutputStream out = new ByteArrayOutputStream(size);
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeUserDefinedTag(Tags.BATCH);
|
w.writeUserDefinedTag(Types.BATCH);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
// We're using a fake message reader, so it's OK to use a fake message
|
// We're using a fake message reader, so it's OK to use a fake message
|
||||||
w.writeUserDefinedTag(Tags.MESSAGE);
|
w.writeUserDefinedTag(Types.MESSAGE);
|
||||||
w.writeBytes(new byte[size - 10]);
|
w.writeBytes(new byte[size - 10]);
|
||||||
w.writeListEnd();
|
w.writeListEnd();
|
||||||
byte[] b = out.toByteArray();
|
byte[] b = out.toByteArray();
|
||||||
@@ -157,7 +157,7 @@ public class BatchReaderTest extends TestCase {
|
|||||||
private byte[] createEmptyBatch() throws Exception {
|
private byte[] createEmptyBatch() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeUserDefinedTag(Tags.BATCH);
|
w.writeUserDefinedTag(Types.BATCH);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
w.writeListEnd();
|
w.writeListEnd();
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
@@ -166,7 +166,7 @@ public class BatchReaderTest extends TestCase {
|
|||||||
private class TestMessageReader implements ObjectReader<Message> {
|
private class TestMessageReader implements ObjectReader<Message> {
|
||||||
|
|
||||||
public Message readObject(Reader r) throws IOException {
|
public Message readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(Tags.MESSAGE);
|
r.readUserDefinedId(Types.MESSAGE);
|
||||||
r.readBytes();
|
r.readBytes();
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import junit.framework.TestCase;
|
|||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.ReaderFactory;
|
import net.sf.briar.api.serial.ReaderFactory;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
@@ -44,10 +44,10 @@ public class RequestReaderTest extends TestCase {
|
|||||||
byte[] b = createRequest(true);
|
byte[] b = createRequest(true);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.REQUEST, requestReader);
|
reader.addObjectReader(Types.REQUEST, requestReader);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.readUserDefined(Tags.REQUEST, Request.class);
|
reader.readUserDefined(Types.REQUEST, Request.class);
|
||||||
fail();
|
fail();
|
||||||
} catch(FormatException expected) {}
|
} catch(FormatException expected) {}
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
@@ -67,9 +67,9 @@ public class RequestReaderTest extends TestCase {
|
|||||||
byte[] b = createRequest(false);
|
byte[] b = createRequest(false);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
reader.addObjectReader(Tags.REQUEST, requestReader);
|
reader.addObjectReader(Types.REQUEST, requestReader);
|
||||||
|
|
||||||
assertEquals(request, reader.readUserDefined(Tags.REQUEST,
|
assertEquals(request, reader.readUserDefined(Types.REQUEST,
|
||||||
Request.class));
|
Request.class));
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -98,8 +98,8 @@ public class RequestReaderTest extends TestCase {
|
|||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
RequestReader requestReader =
|
RequestReader requestReader =
|
||||||
new RequestReader(new RequestFactoryImpl());
|
new RequestReader(new RequestFactoryImpl());
|
||||||
reader.addObjectReader(Tags.REQUEST, requestReader);
|
reader.addObjectReader(Types.REQUEST, requestReader);
|
||||||
Request r = reader.readUserDefined(Tags.REQUEST, Request.class);
|
Request r = reader.readUserDefined(Types.REQUEST, Request.class);
|
||||||
BitSet decoded = r.getBitmap();
|
BitSet decoded = r.getBitmap();
|
||||||
// Check that the decoded BitSet matches the original - we can't
|
// Check that the decoded BitSet matches the original - we can't
|
||||||
// use equals() because of padding, but the first i bits should
|
// use equals() because of padding, but the first i bits should
|
||||||
@@ -115,7 +115,7 @@ public class RequestReaderTest extends TestCase {
|
|||||||
private byte[] createRequest(boolean tooBig) throws Exception {
|
private byte[] createRequest(boolean tooBig) throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeUserDefinedTag(Tags.REQUEST);
|
w.writeUserDefinedTag(Types.REQUEST);
|
||||||
// Allow one byte for the REQUEST tag, one byte for the BYTES tag,
|
// Allow one byte for the REQUEST tag, one byte for the BYTES tag,
|
||||||
// and five bytes for the length as an int32
|
// and five bytes for the length as an int32
|
||||||
int size = ProtocolConstants.MAX_PACKET_LENGTH - 7;
|
int size = ProtocolConstants.MAX_PACKET_LENGTH - 7;
|
||||||
@@ -128,7 +128,7 @@ public class RequestReaderTest extends TestCase {
|
|||||||
private byte[] createRequest(byte[] bitmap) throws Exception {
|
private byte[] createRequest(byte[] bitmap) throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeUserDefinedTag(Tags.REQUEST);
|
w.writeUserDefinedTag(Types.REQUEST);
|
||||||
w.writeBytes(bitmap);
|
w.writeBytes(bitmap);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -375,13 +375,13 @@ public class ReaderImplTest extends TestCase {
|
|||||||
// Add object readers for two user-defined types
|
// Add object readers for two user-defined types
|
||||||
r.addObjectReader(0, new ObjectReader<Foo>() {
|
r.addObjectReader(0, new ObjectReader<Foo>() {
|
||||||
public Foo readObject(Reader r) throws IOException {
|
public Foo readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(0);
|
r.readUserDefinedId(0);
|
||||||
return new Foo(r.readString());
|
return new Foo(r.readString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
r.addObjectReader(255, new ObjectReader<Bar>() {
|
r.addObjectReader(255, new ObjectReader<Bar>() {
|
||||||
public Bar readObject(Reader r) throws IOException {
|
public Bar readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(255);
|
r.readUserDefinedId(255);
|
||||||
return new Bar(r.readString());
|
return new Bar(r.readString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -398,13 +398,13 @@ public class ReaderImplTest extends TestCase {
|
|||||||
// Add object readers for two user-defined types
|
// Add object readers for two user-defined types
|
||||||
r.addObjectReader(0, new ObjectReader<Foo>() {
|
r.addObjectReader(0, new ObjectReader<Foo>() {
|
||||||
public Foo readObject(Reader r) throws IOException {
|
public Foo readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(0);
|
r.readUserDefinedId(0);
|
||||||
return new Foo(r.readString());
|
return new Foo(r.readString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
r.addObjectReader(255, new ObjectReader<Bar>() {
|
r.addObjectReader(255, new ObjectReader<Bar>() {
|
||||||
public Bar readObject(Reader r) throws IOException {
|
public Bar readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(255);
|
r.readUserDefinedId(255);
|
||||||
return new Bar(r.readString());
|
return new Bar(r.readString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -451,7 +451,7 @@ public class ReaderImplTest extends TestCase {
|
|||||||
// Add an object reader for tag 0, class Foo
|
// Add an object reader for tag 0, class Foo
|
||||||
r.addObjectReader(0, new ObjectReader<Foo>() {
|
r.addObjectReader(0, new ObjectReader<Foo>() {
|
||||||
public Foo readObject(Reader r) throws IOException {
|
public Foo readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(0);
|
r.readUserDefinedId(0);
|
||||||
return new Foo(r.readString());
|
return new Foo(r.readString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -469,7 +469,7 @@ public class ReaderImplTest extends TestCase {
|
|||||||
// Add an object reader for a user-defined type
|
// Add an object reader for a user-defined type
|
||||||
r.addObjectReader(0, new ObjectReader<Foo>() {
|
r.addObjectReader(0, new ObjectReader<Foo>() {
|
||||||
public Foo readObject(Reader r) throws IOException {
|
public Foo readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(0);
|
r.readUserDefinedId(0);
|
||||||
return new Foo(r.readString());
|
return new Foo(r.readString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -485,13 +485,13 @@ public class ReaderImplTest extends TestCase {
|
|||||||
// Add object readers for two user-defined types
|
// Add object readers for two user-defined types
|
||||||
r.addObjectReader(0, new ObjectReader<Foo>() {
|
r.addObjectReader(0, new ObjectReader<Foo>() {
|
||||||
public Foo readObject(Reader r) throws IOException {
|
public Foo readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(0);
|
r.readUserDefinedId(0);
|
||||||
return new Foo(r.readString());
|
return new Foo(r.readString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
r.addObjectReader(1, new ObjectReader<Bar>() {
|
r.addObjectReader(1, new ObjectReader<Bar>() {
|
||||||
public Bar readObject(Reader r) throws IOException {
|
public Bar readObject(Reader r) throws IOException {
|
||||||
r.readUserDefinedTag(1);
|
r.readUserDefinedId(1);
|
||||||
return new Bar(r.readString());
|
return new Bar(r.readString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user