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