Minor changes to serialisation library (mostly renaming).

This commit is contained in:
akwizgran
2012-05-09 13:17:04 +02:00
parent 78e18fb373
commit 46ed0cc4b1
21 changed files with 161 additions and 170 deletions

View File

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

View File

@@ -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 id, ObjectReader<?> o); void addStructReader(int id, StructReader<?> o);
void removeObjectReader(int id); void removeStructReader(int id);
boolean hasBoolean() throws IOException; boolean hasBoolean() throws IOException;
boolean readBoolean() throws IOException; boolean readBoolean() throws IOException;
@@ -51,7 +51,6 @@ public interface Reader {
byte[] readBytes(int maxLength) throws IOException; byte[] readBytes(int maxLength) throws IOException;
boolean hasList() throws IOException; boolean hasList() throws IOException;
List<Object> readList() throws IOException;
<E> List<E> readList(Class<E> e) throws IOException; <E> List<E> readList(Class<E> e) throws IOException;
boolean hasListStart() throws IOException; boolean hasListStart() throws IOException;
void readListStart() throws IOException; void readListStart() throws IOException;
@@ -59,7 +58,6 @@ public interface Reader {
void readListEnd() throws IOException; void readListEnd() throws IOException;
boolean hasMap() throws IOException; boolean hasMap() throws IOException;
Map<Object, Object> readMap() throws IOException;
<K, V> Map<K, V> readMap(Class<K> k, Class<V> v) throws IOException; <K, V> Map<K, V> readMap(Class<K> k, Class<V> v) throws IOException;
boolean hasMapStart() throws IOException; boolean hasMapStart() throws IOException;
void readMapStart() throws IOException; void readMapStart() throws IOException;

View File

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

View File

@@ -16,10 +16,10 @@ 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.Consumer; import net.sf.briar.api.serial.Consumer;
import net.sf.briar.api.serial.CountingConsumer; import net.sf.briar.api.serial.CountingConsumer;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
class AckReader implements ObjectReader<Ack> { class AckReader implements StructReader<Ack> {
private final PacketFactory packetFactory; private final PacketFactory packetFactory;
@@ -27,7 +27,7 @@ class AckReader implements ObjectReader<Ack> {
this.packetFactory = packetFactory; this.packetFactory = packetFactory;
} }
public Ack readObject(Reader r) throws IOException { public Ack readStruct(Reader r) throws IOException {
// Initialise the consumer // Initialise the consumer
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH); Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
// Read the data // Read the data

View File

@@ -10,10 +10,10 @@ import net.sf.briar.api.protocol.AuthorId;
import net.sf.briar.api.protocol.ProtocolConstants; import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.Types; import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.DigestingConsumer; import net.sf.briar.api.serial.DigestingConsumer;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
class AuthorReader implements ObjectReader<Author> { class AuthorReader implements StructReader<Author> {
private final MessageDigest messageDigest; private final MessageDigest messageDigest;
private final AuthorFactory authorFactory; private final AuthorFactory authorFactory;
@@ -23,7 +23,7 @@ class AuthorReader implements ObjectReader<Author> {
this.authorFactory = authorFactory; this.authorFactory = authorFactory;
} }
public Author readObject(Reader r) throws IOException { public Author readStruct(Reader r) throws IOException {
// Initialise the consumer // Initialise the consumer
DigestingConsumer digesting = new DigestingConsumer(messageDigest); DigestingConsumer digesting = new DigestingConsumer(messageDigest);
// Read and digest the data // Read and digest the data

View File

@@ -10,29 +10,29 @@ import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.protocol.UnverifiedBatch; import net.sf.briar.api.protocol.UnverifiedBatch;
import net.sf.briar.api.serial.Consumer; import net.sf.briar.api.serial.Consumer;
import net.sf.briar.api.serial.CountingConsumer; import net.sf.briar.api.serial.CountingConsumer;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
class BatchReader implements ObjectReader<UnverifiedBatch> { class BatchReader implements StructReader<UnverifiedBatch> {
private final ObjectReader<UnverifiedMessage> messageReader; private final StructReader<UnverifiedMessage> messageReader;
private final UnverifiedBatchFactory batchFactory; private final UnverifiedBatchFactory batchFactory;
BatchReader(ObjectReader<UnverifiedMessage> messageReader, BatchReader(StructReader<UnverifiedMessage> messageReader,
UnverifiedBatchFactory batchFactory) { UnverifiedBatchFactory batchFactory) {
this.messageReader = messageReader; this.messageReader = messageReader;
this.batchFactory = batchFactory; this.batchFactory = batchFactory;
} }
public UnverifiedBatch readObject(Reader r) throws IOException { public UnverifiedBatch readStruct(Reader r) throws IOException {
// Initialise the consumer // Initialise the consumer
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH); Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
// Read the data // Read the data
r.addConsumer(counting); r.addConsumer(counting);
r.readStructId(Types.BATCH); r.readStructId(Types.BATCH);
r.addObjectReader(Types.MESSAGE, messageReader); r.addStructReader(Types.MESSAGE, messageReader);
List<UnverifiedMessage> messages = r.readList(UnverifiedMessage.class); List<UnverifiedMessage> messages = r.readList(UnverifiedMessage.class);
r.removeObjectReader(Types.MESSAGE); r.removeStructReader(Types.MESSAGE);
r.removeConsumer(counting); r.removeConsumer(counting);
if(messages.isEmpty()) throw new FormatException(); if(messages.isEmpty()) throw new FormatException();
// Build and return the batch // Build and return the batch

View File

@@ -10,10 +10,10 @@ import net.sf.briar.api.protocol.GroupId;
import net.sf.briar.api.protocol.ProtocolConstants; import net.sf.briar.api.protocol.ProtocolConstants;
import net.sf.briar.api.protocol.Types; import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.DigestingConsumer; import net.sf.briar.api.serial.DigestingConsumer;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
class GroupReader implements ObjectReader<Group> { class GroupReader implements StructReader<Group> {
private final MessageDigest messageDigest; private final MessageDigest messageDigest;
private final GroupFactory groupFactory; private final GroupFactory groupFactory;
@@ -23,7 +23,7 @@ class GroupReader implements ObjectReader<Group> {
this.groupFactory = groupFactory; this.groupFactory = groupFactory;
} }
public Group readObject(Reader r) throws IOException { public Group readStruct(Reader r) throws IOException {
// Initialise the consumer // Initialise the consumer
DigestingConsumer digesting = new DigestingConsumer(messageDigest); DigestingConsumer digesting = new DigestingConsumer(messageDigest);
// Read and digest the data // Read and digest the data

View File

@@ -16,21 +16,21 @@ 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.CopyingConsumer; import net.sf.briar.api.serial.CopyingConsumer;
import net.sf.briar.api.serial.CountingConsumer; import net.sf.briar.api.serial.CountingConsumer;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
class MessageReader implements ObjectReader<UnverifiedMessage> { class MessageReader implements StructReader<UnverifiedMessage> {
private final ObjectReader<Group> groupReader; private final StructReader<Group> groupReader;
private final ObjectReader<Author> authorReader; private final StructReader<Author> authorReader;
MessageReader(ObjectReader<Group> groupReader, MessageReader(StructReader<Group> groupReader,
ObjectReader<Author> authorReader) { StructReader<Author> authorReader) {
this.groupReader = groupReader; this.groupReader = groupReader;
this.authorReader = authorReader; this.authorReader = authorReader;
} }
public UnverifiedMessage readObject(Reader r) throws IOException { public UnverifiedMessage readStruct(Reader r) throws IOException {
CopyingConsumer copying = new CopyingConsumer(); CopyingConsumer copying = new CopyingConsumer();
CountingConsumer counting = new CountingConsumer(MAX_PACKET_LENGTH); CountingConsumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
r.addConsumer(copying); r.addConsumer(copying);
@@ -51,18 +51,18 @@ class MessageReader implements ObjectReader<UnverifiedMessage> {
if(r.hasNull()) { if(r.hasNull()) {
r.readNull(); r.readNull();
} else { } else {
r.addObjectReader(Types.GROUP, groupReader); r.addStructReader(Types.GROUP, groupReader);
group = r.readStruct(Types.GROUP, Group.class); group = r.readStruct(Types.GROUP, Group.class);
r.removeObjectReader(Types.GROUP); r.removeStructReader(Types.GROUP);
} }
// Read the author, if there is one // Read the author, if there is one
Author author = null; Author author = null;
if(r.hasNull()) { if(r.hasNull()) {
r.readNull(); r.readNull();
} else { } else {
r.addObjectReader(Types.AUTHOR, authorReader); r.addStructReader(Types.AUTHOR, authorReader);
author = r.readStruct(Types.AUTHOR, Author.class); author = r.readStruct(Types.AUTHOR, Author.class);
r.removeObjectReader(Types.AUTHOR); r.removeStructReader(Types.AUTHOR);
} }
// Read the subject // Read the subject
String subject = r.readString(MAX_SUBJECT_LENGTH); String subject = r.readString(MAX_SUBJECT_LENGTH);

View File

@@ -16,10 +16,10 @@ 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.Consumer; import net.sf.briar.api.serial.Consumer;
import net.sf.briar.api.serial.CountingConsumer; import net.sf.briar.api.serial.CountingConsumer;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
class OfferReader implements ObjectReader<Offer> { class OfferReader implements StructReader<Offer> {
private final PacketFactory packetFactory; private final PacketFactory packetFactory;
@@ -27,7 +27,7 @@ class OfferReader implements ObjectReader<Offer> {
this.packetFactory = packetFactory; this.packetFactory = packetFactory;
} }
public Offer readObject(Reader r) throws IOException { public Offer readStruct(Reader r) throws IOException {
// Initialise the consumer // Initialise the consumer
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH); Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
// Read the data // Read the data

View File

@@ -18,7 +18,7 @@ import net.sf.briar.api.protocol.SubscriptionUpdate;
import net.sf.briar.api.protocol.TransportUpdate; import net.sf.briar.api.protocol.TransportUpdate;
import net.sf.briar.api.protocol.UnverifiedBatch; import net.sf.briar.api.protocol.UnverifiedBatch;
import net.sf.briar.api.protocol.VerificationExecutor; import net.sf.briar.api.protocol.VerificationExecutor;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.util.BoundedExecutor; import net.sf.briar.util.BoundedExecutor;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@@ -58,54 +58,54 @@ public class ProtocolModule extends AbstractModule {
} }
@Provides @Provides
ObjectReader<Ack> getAckReader(PacketFactory ackFactory) { StructReader<Ack> getAckReader(PacketFactory ackFactory) {
return new AckReader(ackFactory); return new AckReader(ackFactory);
} }
@Provides @Provides
ObjectReader<Author> getAuthorReader(CryptoComponent crypto, StructReader<Author> getAuthorReader(CryptoComponent crypto,
AuthorFactory authorFactory) { AuthorFactory authorFactory) {
return new AuthorReader(crypto, authorFactory); return new AuthorReader(crypto, authorFactory);
} }
@Provides @Provides
ObjectReader<UnverifiedBatch> getBatchReader( StructReader<UnverifiedBatch> getBatchReader(
ObjectReader<UnverifiedMessage> messageReader, StructReader<UnverifiedMessage> messageReader,
UnverifiedBatchFactory batchFactory) { UnverifiedBatchFactory batchFactory) {
return new BatchReader(messageReader, batchFactory); return new BatchReader(messageReader, batchFactory);
} }
@Provides @Provides
ObjectReader<Group> getGroupReader(CryptoComponent crypto, StructReader<Group> getGroupReader(CryptoComponent crypto,
GroupFactory groupFactory) { GroupFactory groupFactory) {
return new GroupReader(crypto, groupFactory); return new GroupReader(crypto, groupFactory);
} }
@Provides @Provides
ObjectReader<UnverifiedMessage> getMessageReader( StructReader<UnverifiedMessage> getMessageReader(
ObjectReader<Group> groupReader, StructReader<Group> groupReader,
ObjectReader<Author> authorReader) { StructReader<Author> authorReader) {
return new MessageReader(groupReader, authorReader); return new MessageReader(groupReader, authorReader);
} }
@Provides @Provides
ObjectReader<Offer> getOfferReader(PacketFactory packetFactory) { StructReader<Offer> getOfferReader(PacketFactory packetFactory) {
return new OfferReader(packetFactory); return new OfferReader(packetFactory);
} }
@Provides @Provides
ObjectReader<Request> getRequestReader(PacketFactory packetFactory) { StructReader<Request> getRequestReader(PacketFactory packetFactory) {
return new RequestReader(packetFactory); return new RequestReader(packetFactory);
} }
@Provides @Provides
ObjectReader<SubscriptionUpdate> getSubscriptionReader( StructReader<SubscriptionUpdate> getSubscriptionReader(
ObjectReader<Group> groupReader, PacketFactory packetFactory) { StructReader<Group> groupReader, PacketFactory packetFactory) {
return new SubscriptionUpdateReader(groupReader, packetFactory); return new SubscriptionUpdateReader(groupReader, packetFactory);
} }
@Provides @Provides
ObjectReader<TransportUpdate> getTransportReader( StructReader<TransportUpdate> getTransportReader(
PacketFactory packetFactory) { PacketFactory packetFactory) {
return new TransportUpdateReader(packetFactory); return new TransportUpdateReader(packetFactory);
} }

View File

@@ -10,7 +10,7 @@ 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.TransportUpdate; import net.sf.briar.api.protocol.TransportUpdate;
import net.sf.briar.api.protocol.UnverifiedBatch; import net.sf.briar.api.protocol.UnverifiedBatch;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.ReaderFactory; import net.sf.briar.api.serial.ReaderFactory;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -19,21 +19,21 @@ import com.google.inject.Provider;
class ProtocolReaderFactoryImpl implements ProtocolReaderFactory { class ProtocolReaderFactoryImpl implements ProtocolReaderFactory {
private final ReaderFactory readerFactory; private final ReaderFactory readerFactory;
private final Provider<ObjectReader<Ack>> ackProvider; private final Provider<StructReader<Ack>> ackProvider;
private final Provider<ObjectReader<UnverifiedBatch>> batchProvider; private final Provider<StructReader<UnverifiedBatch>> batchProvider;
private final Provider<ObjectReader<Offer>> offerProvider; private final Provider<StructReader<Offer>> offerProvider;
private final Provider<ObjectReader<Request>> requestProvider; private final Provider<StructReader<Request>> requestProvider;
private final Provider<ObjectReader<SubscriptionUpdate>> subscriptionProvider; private final Provider<StructReader<SubscriptionUpdate>> subscriptionProvider;
private final Provider<ObjectReader<TransportUpdate>> transportProvider; private final Provider<StructReader<TransportUpdate>> transportProvider;
@Inject @Inject
ProtocolReaderFactoryImpl(ReaderFactory readerFactory, ProtocolReaderFactoryImpl(ReaderFactory readerFactory,
Provider<ObjectReader<Ack>> ackProvider, Provider<StructReader<Ack>> ackProvider,
Provider<ObjectReader<UnverifiedBatch>> batchProvider, Provider<StructReader<UnverifiedBatch>> batchProvider,
Provider<ObjectReader<Offer>> offerProvider, Provider<StructReader<Offer>> offerProvider,
Provider<ObjectReader<Request>> requestProvider, Provider<StructReader<Request>> requestProvider,
Provider<ObjectReader<SubscriptionUpdate>> subscriptionProvider, Provider<StructReader<SubscriptionUpdate>> subscriptionProvider,
Provider<ObjectReader<TransportUpdate>> transportProvider) { Provider<StructReader<TransportUpdate>> transportProvider) {
this.readerFactory = readerFactory; this.readerFactory = readerFactory;
this.ackProvider = ackProvider; this.ackProvider = ackProvider;
this.batchProvider = batchProvider; this.batchProvider = batchProvider;

View File

@@ -11,7 +11,7 @@ import net.sf.briar.api.protocol.SubscriptionUpdate;
import net.sf.briar.api.protocol.TransportUpdate; import net.sf.briar.api.protocol.TransportUpdate;
import net.sf.briar.api.protocol.Types; import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.protocol.UnverifiedBatch; import net.sf.briar.api.protocol.UnverifiedBatch;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
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;
@@ -20,19 +20,19 @@ class ProtocolReaderImpl implements ProtocolReader {
private final Reader reader; private final Reader reader;
ProtocolReaderImpl(InputStream in, ReaderFactory readerFactory, ProtocolReaderImpl(InputStream in, ReaderFactory readerFactory,
ObjectReader<Ack> ackReader, StructReader<Ack> ackReader,
ObjectReader<UnverifiedBatch> batchReader, StructReader<UnverifiedBatch> batchReader,
ObjectReader<Offer> offerReader, StructReader<Offer> offerReader,
ObjectReader<Request> requestReader, StructReader<Request> requestReader,
ObjectReader<SubscriptionUpdate> subscriptionReader, StructReader<SubscriptionUpdate> subscriptionReader,
ObjectReader<TransportUpdate> transportReader) { StructReader<TransportUpdate> transportReader) {
reader = readerFactory.createReader(in); reader = readerFactory.createReader(in);
reader.addObjectReader(Types.ACK, ackReader); reader.addStructReader(Types.ACK, ackReader);
reader.addObjectReader(Types.BATCH, batchReader); reader.addStructReader(Types.BATCH, batchReader);
reader.addObjectReader(Types.OFFER, offerReader); reader.addStructReader(Types.OFFER, offerReader);
reader.addObjectReader(Types.REQUEST, requestReader); reader.addStructReader(Types.REQUEST, requestReader);
reader.addObjectReader(Types.SUBSCRIPTION_UPDATE, subscriptionReader); reader.addStructReader(Types.SUBSCRIPTION_UPDATE, subscriptionReader);
reader.addObjectReader(Types.TRANSPORT_UPDATE, transportReader); reader.addStructReader(Types.TRANSPORT_UPDATE, transportReader);
} }
public boolean eof() throws IOException { public boolean eof() throws IOException {

View File

@@ -11,10 +11,10 @@ import net.sf.briar.api.protocol.Request;
import net.sf.briar.api.protocol.Types; 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.CountingConsumer; import net.sf.briar.api.serial.CountingConsumer;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
class RequestReader implements ObjectReader<Request> { class RequestReader implements StructReader<Request> {
private final PacketFactory packetFactory; private final PacketFactory packetFactory;
@@ -22,7 +22,7 @@ class RequestReader implements ObjectReader<Request> {
this.packetFactory = packetFactory; this.packetFactory = packetFactory;
} }
public Request readObject(Reader r) throws IOException { public Request readStruct(Reader r) throws IOException {
// Initialise the consumer // Initialise the consumer
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH); Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
// Read the data // Read the data

View File

@@ -12,29 +12,29 @@ import net.sf.briar.api.protocol.SubscriptionUpdate;
import net.sf.briar.api.protocol.Types; 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.CountingConsumer; import net.sf.briar.api.serial.CountingConsumer;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
class SubscriptionUpdateReader implements ObjectReader<SubscriptionUpdate> { class SubscriptionUpdateReader implements StructReader<SubscriptionUpdate> {
private final ObjectReader<Group> groupReader; private final StructReader<Group> groupReader;
private final PacketFactory packetFactory; private final PacketFactory packetFactory;
SubscriptionUpdateReader(ObjectReader<Group> groupReader, SubscriptionUpdateReader(StructReader<Group> groupReader,
PacketFactory packetFactory) { PacketFactory packetFactory) {
this.groupReader = groupReader; this.groupReader = groupReader;
this.packetFactory = packetFactory; this.packetFactory = packetFactory;
} }
public SubscriptionUpdate readObject(Reader r) throws IOException { public SubscriptionUpdate readStruct(Reader r) throws IOException {
// Initialise the consumer // Initialise the consumer
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH); Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
// Read the data // Read the data
r.addConsumer(counting); r.addConsumer(counting);
r.readStructId(Types.SUBSCRIPTION_UPDATE); r.readStructId(Types.SUBSCRIPTION_UPDATE);
r.addObjectReader(Types.GROUP, groupReader); r.addStructReader(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(Types.GROUP); r.removeStructReader(Types.GROUP);
long timestamp = r.readInt64(); long timestamp = r.readInt64();
if(timestamp < 0L) throw new FormatException(); if(timestamp < 0L) throw new FormatException();
r.removeConsumer(counting); r.removeConsumer(counting);

View File

@@ -21,28 +21,28 @@ 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.Consumer; import net.sf.briar.api.serial.Consumer;
import net.sf.briar.api.serial.CountingConsumer; import net.sf.briar.api.serial.CountingConsumer;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
class TransportUpdateReader implements ObjectReader<TransportUpdate> { class TransportUpdateReader implements StructReader<TransportUpdate> {
private final PacketFactory packetFactory; private final PacketFactory packetFactory;
private final ObjectReader<Transport> transportReader; private final StructReader<Transport> transportReader;
TransportUpdateReader(PacketFactory packetFactory) { TransportUpdateReader(PacketFactory packetFactory) {
this.packetFactory = packetFactory; this.packetFactory = packetFactory;
transportReader = new TransportReader(); transportReader = new TransportReader();
} }
public TransportUpdate readObject(Reader r) throws IOException { public TransportUpdate readStruct(Reader r) throws IOException {
// Initialise the consumer // Initialise the consumer
Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH); Consumer counting = new CountingConsumer(MAX_PACKET_LENGTH);
// Read the data // Read the data
r.addConsumer(counting); r.addConsumer(counting);
r.readStructId(Types.TRANSPORT_UPDATE); r.readStructId(Types.TRANSPORT_UPDATE);
r.addObjectReader(Types.TRANSPORT, transportReader); r.addStructReader(Types.TRANSPORT, transportReader);
Collection<Transport> transports = r.readList(Transport.class); Collection<Transport> transports = r.readList(Transport.class);
r.removeObjectReader(Types.TRANSPORT); r.removeStructReader(Types.TRANSPORT);
if(transports.size() > MAX_TRANSPORTS) throw new FormatException(); if(transports.size() > MAX_TRANSPORTS) throw new FormatException();
long timestamp = r.readInt64(); long timestamp = r.readInt64();
r.removeConsumer(counting); r.removeConsumer(counting);
@@ -57,9 +57,9 @@ class TransportUpdateReader implements ObjectReader<TransportUpdate> {
return packetFactory.createTransportUpdate(transports, timestamp); return packetFactory.createTransportUpdate(transports, timestamp);
} }
private static class TransportReader implements ObjectReader<Transport> { private static class TransportReader implements StructReader<Transport> {
public Transport readObject(Reader r) throws IOException { public Transport readStruct(Reader r) throws IOException {
r.readStructId(Types.TRANSPORT); r.readStructId(Types.TRANSPORT);
// Read the ID // Read the ID
byte[] b = r.readBytes(UniqueId.LENGTH); byte[] b = r.readBytes(UniqueId.LENGTH);

View File

@@ -12,7 +12,7 @@ import java.util.Map;
import net.sf.briar.api.Bytes; import net.sf.briar.api.Bytes;
import net.sf.briar.api.FormatException; import net.sf.briar.api.FormatException;
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.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
// This class is not thread-safe // This class is not thread-safe
@@ -23,7 +23,7 @@ class ReaderImpl implements Reader {
private final InputStream in; private final InputStream in;
private final Collection<Consumer> consumers = new ArrayList<Consumer>(0); private final Collection<Consumer> consumers = new ArrayList<Consumer>(0);
private ObjectReader<?>[] objectReaders = new ObjectReader<?>[] {}; private StructReader<?>[] structReaders = new StructReader<?>[] {};
private boolean hasLookahead = false, eof = false; private boolean hasLookahead = false, eof = false;
private byte next, nextNext; private byte next, nextNext;
private byte[] buf = null; private byte[] buf = null;
@@ -98,21 +98,22 @@ class ReaderImpl implements Reader {
if(!consumers.remove(c)) throw new IllegalArgumentException(); if(!consumers.remove(c)) throw new IllegalArgumentException();
} }
public void addObjectReader(int id, ObjectReader<?> o) { public void addStructReader(int id, StructReader<?> o) {
if(id < 0 || id > 255) throw new IllegalArgumentException(); if(id < 0 || id > 255) throw new IllegalArgumentException();
if(objectReaders.length < id + 1) { if(structReaders.length < id + 1) {
ObjectReader<?>[] newObjectReaders = new ObjectReader<?>[id + 1]; int len = Math.min(256, Math.max(id + 1, structReaders.length * 2));
System.arraycopy(objectReaders, 0, newObjectReaders, 0, StructReader<?>[] newStructReaders = new StructReader<?>[len];
objectReaders.length); System.arraycopy(structReaders, 0, newStructReaders, 0,
objectReaders = newObjectReaders; structReaders.length);
structReaders = newStructReaders;
} }
objectReaders[id] = o; structReaders[id] = o;
} }
public void removeObjectReader(int id) { public void removeStructReader(int id) {
if(id < 0 || id > objectReaders.length) if(id < 0 || id > structReaders.length)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
objectReaders[id] = null; structReaders[id] = null;
} }
public boolean hasBoolean() throws IOException { public boolean hasBoolean() throws IOException {
@@ -335,10 +336,6 @@ class ReaderImpl implements Reader {
|| (next & Tag.SHORT_MASK) == Tag.SHORT_LIST; || (next & Tag.SHORT_MASK) == Tag.SHORT_LIST;
} }
public List<Object> readList() throws IOException {
return readList(Object.class);
}
public <E> List<E> readList(Class<E> e) throws IOException { public <E> List<E> readList(Class<E> e) throws IOException {
if(!hasList()) throw new FormatException(); if(!hasList()) throw new FormatException();
consumeLookahead(); consumeLookahead();
@@ -385,8 +382,8 @@ class ReaderImpl implements Reader {
if(hasFloat64()) return Double.valueOf(readFloat64()); if(hasFloat64()) return Double.valueOf(readFloat64());
if(hasString()) return readString(); if(hasString()) return readString();
if(hasBytes()) return new Bytes(readBytes()); if(hasBytes()) return new Bytes(readBytes());
if(hasList()) return readList(); if(hasList()) return readList(Object.class);
if(hasMap()) return readMap(); if(hasMap()) return readMap(Object.class, Object.class);
if(hasNull()) { if(hasNull()) {
readNull(); readNull();
return null; return null;
@@ -462,10 +459,6 @@ class ReaderImpl implements Reader {
|| (next & Tag.SHORT_MASK) == Tag.SHORT_MAP; || (next & Tag.SHORT_MASK) == Tag.SHORT_MAP;
} }
public Map<Object, Object> readMap() throws IOException {
return readMap(Object.class, Object.class);
}
public <K, V> Map<K, V> readMap(Class<K> k, Class<V> v) throws IOException { public <K, V> Map<K, V> readMap(Class<K> k, Class<V> v) throws IOException {
if(!hasMap()) throw new FormatException(); if(!hasMap()) throw new FormatException();
consumeLookahead(); consumeLookahead();
@@ -538,11 +531,11 @@ class ReaderImpl implements Reader {
public <T> T readStruct(int id, Class<T> t) throws IOException { public <T> T readStruct(int id, Class<T> t) throws IOException {
if(!hasStruct(id)) throw new FormatException(); if(!hasStruct(id)) throw new FormatException();
if(id >= objectReaders.length) throw new FormatException(); if(id < 0 || id >= structReaders.length) throw new FormatException();
ObjectReader<?> o = objectReaders[id]; StructReader<?> s = structReaders[id];
if(o == null) throw new FormatException(); if(s == null) throw new FormatException();
try { try {
return t.cast(o.readObject(this)); return t.cast(s.readStruct(this));
} catch(ClassCastException e) { } catch(ClassCastException e) {
throw new FormatException(); throw new FormatException();
} }

View File

@@ -49,7 +49,7 @@ public class AckReaderTest extends BriarTestCase {
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(Types.ACK, ackReader); reader.addStructReader(Types.ACK, ackReader);
try { try {
reader.readStruct(Types.ACK, Ack.class); reader.readStruct(Types.ACK, Ack.class);
@@ -72,7 +72,7 @@ public class AckReaderTest extends BriarTestCase {
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(Types.ACK, ackReader); reader.addStructReader(Types.ACK, ackReader);
assertEquals(ack, reader.readStruct(Types.ACK, Ack.class)); assertEquals(ack, reader.readStruct(Types.ACK, Ack.class));
context.assertIsSatisfied(); context.assertIsSatisfied();
@@ -86,7 +86,7 @@ public class AckReaderTest extends BriarTestCase {
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(Types.ACK, ackReader); reader.addStructReader(Types.ACK, ackReader);
try { try {
reader.readStruct(Types.ACK, Ack.class); reader.readStruct(Types.ACK, Ack.class);

View File

@@ -10,7 +10,7 @@ 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.Types; import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.protocol.UnverifiedBatch; import net.sf.briar.api.protocol.UnverifiedBatch;
import net.sf.briar.api.serial.ObjectReader; import net.sf.briar.api.serial.StructReader;
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;
@@ -30,7 +30,7 @@ public class BatchReaderTest extends BriarTestCase {
private final WriterFactory writerFactory; private final WriterFactory writerFactory;
private final Mockery context; private final Mockery context;
private final UnverifiedMessage message; private final UnverifiedMessage message;
private final ObjectReader<UnverifiedMessage> messageReader; private final StructReader<UnverifiedMessage> messageReader;
public BatchReaderTest() throws Exception { public BatchReaderTest() throws Exception {
super(); super();
@@ -51,7 +51,7 @@ public class BatchReaderTest extends BriarTestCase {
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(Types.BATCH, batchReader); reader.addStructReader(Types.BATCH, batchReader);
try { try {
reader.readStruct(Types.BATCH, UnverifiedBatch.class); reader.readStruct(Types.BATCH, UnverifiedBatch.class);
@@ -75,7 +75,7 @@ public class BatchReaderTest extends BriarTestCase {
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(Types.BATCH, batchReader); reader.addStructReader(Types.BATCH, batchReader);
assertEquals(batch, reader.readStruct(Types.BATCH, assertEquals(batch, reader.readStruct(Types.BATCH,
UnverifiedBatch.class)); UnverifiedBatch.class));
@@ -91,7 +91,7 @@ public class BatchReaderTest extends BriarTestCase {
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(Types.BATCH, batchReader); reader.addStructReader(Types.BATCH, batchReader);
try { try {
reader.readStruct(Types.BATCH, UnverifiedBatch.class); reader.readStruct(Types.BATCH, UnverifiedBatch.class);
@@ -123,9 +123,9 @@ public class BatchReaderTest extends BriarTestCase {
return out.toByteArray(); return out.toByteArray();
} }
private class TestMessageReader implements ObjectReader<UnverifiedMessage> { private class TestMessageReader implements StructReader<UnverifiedMessage> {
public UnverifiedMessage readObject(Reader r) throws IOException { public UnverifiedMessage readStruct(Reader r) throws IOException {
r.readStructId(Types.MESSAGE); r.readStructId(Types.MESSAGE);
r.readBytes(); r.readBytes();
return message; return message;

View File

@@ -49,7 +49,7 @@ public class OfferReaderTest extends BriarTestCase {
byte[] b = createOffer(true); byte[] b = createOffer(true);
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in); Reader reader = readerFactory.createReader(in);
reader.addObjectReader(Types.OFFER, offerReader); reader.addStructReader(Types.OFFER, offerReader);
try { try {
reader.readStruct(Types.OFFER, Offer.class); reader.readStruct(Types.OFFER, Offer.class);
@@ -72,7 +72,7 @@ public class OfferReaderTest extends BriarTestCase {
byte[] b = createOffer(false); byte[] b = createOffer(false);
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in); Reader reader = readerFactory.createReader(in);
reader.addObjectReader(Types.OFFER, offerReader); reader.addStructReader(Types.OFFER, offerReader);
assertEquals(offer, reader.readStruct(Types.OFFER, Offer.class)); assertEquals(offer, reader.readStruct(Types.OFFER, Offer.class));
context.assertIsSatisfied(); context.assertIsSatisfied();
@@ -86,7 +86,7 @@ public class OfferReaderTest extends BriarTestCase {
byte[] b = createEmptyOffer(); byte[] b = createEmptyOffer();
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in); Reader reader = readerFactory.createReader(in);
reader.addObjectReader(Types.OFFER, offerReader); reader.addStructReader(Types.OFFER, offerReader);
try { try {
reader.readStruct(Types.OFFER, Offer.class); reader.readStruct(Types.OFFER, Offer.class);

View File

@@ -49,7 +49,7 @@ public class RequestReaderTest extends BriarTestCase {
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(Types.REQUEST, requestReader); reader.addStructReader(Types.REQUEST, requestReader);
try { try {
reader.readStruct(Types.REQUEST, Request.class); reader.readStruct(Types.REQUEST, Request.class);
@@ -72,7 +72,7 @@ public class RequestReaderTest extends BriarTestCase {
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(Types.REQUEST, requestReader); reader.addStructReader(Types.REQUEST, requestReader);
assertEquals(request, reader.readStruct(Types.REQUEST, assertEquals(request, reader.readStruct(Types.REQUEST,
Request.class)); Request.class));
@@ -102,7 +102,7 @@ public class RequestReaderTest extends BriarTestCase {
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in); Reader reader = readerFactory.createReader(in);
RequestReader requestReader = new RequestReader(packetFactory); RequestReader requestReader = new RequestReader(packetFactory);
reader.addObjectReader(Types.REQUEST, requestReader); reader.addStructReader(Types.REQUEST, requestReader);
Request r = reader.readStruct(Types.REQUEST, Request.class); Request r = reader.readStruct(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

View File

@@ -14,7 +14,7 @@ import net.sf.briar.BriarTestCase;
import net.sf.briar.api.Bytes; import net.sf.briar.api.Bytes;
import net.sf.briar.api.FormatException; import net.sf.briar.api.FormatException;
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.StructReader;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
import net.sf.briar.util.StringUtils; import net.sf.briar.util.StringUtils;
@@ -373,15 +373,15 @@ public class ReaderImplTest extends BriarTestCase {
@Test @Test
public void testReadStruct() throws Exception { public void testReadStruct() throws Exception {
setContents("C0" + "83666F6F" + "F1" + "FF" + "83666F6F"); setContents("C0" + "83666F6F" + "F1" + "FF" + "83666F6F");
// Add object readers for two structs // Add readers for two structs
r.addObjectReader(0, new ObjectReader<Foo>() { r.addStructReader(0, new StructReader<Foo>() {
public Foo readObject(Reader r) throws IOException { public Foo readStruct(Reader r) throws IOException {
r.readStructId(0); r.readStructId(0);
return new Foo(r.readString()); return new Foo(r.readString());
} }
}); });
r.addObjectReader(255, new ObjectReader<Bar>() { r.addStructReader(255, new StructReader<Bar>() {
public Bar readObject(Reader r) throws IOException { public Bar readStruct(Reader r) throws IOException {
r.readStructId(255); r.readStructId(255);
return new Bar(r.readString()); return new Bar(r.readString());
} }
@@ -396,15 +396,15 @@ public class ReaderImplTest extends BriarTestCase {
@Test @Test
public void testReadStructWithConsumer() throws Exception { public void testReadStructWithConsumer() throws Exception {
setContents("C0" + "83666F6F" + "F1" + "FF" + "83666F6F"); setContents("C0" + "83666F6F" + "F1" + "FF" + "83666F6F");
// Add object readers for two structs // Add readers for two structs
r.addObjectReader(0, new ObjectReader<Foo>() { r.addStructReader(0, new StructReader<Foo>() {
public Foo readObject(Reader r) throws IOException { public Foo readStruct(Reader r) throws IOException {
r.readStructId(0); r.readStructId(0);
return new Foo(r.readString()); return new Foo(r.readString());
} }
}); });
r.addObjectReader(255, new ObjectReader<Bar>() { r.addStructReader(255, new StructReader<Bar>() {
public Bar readObject(Reader r) throws IOException { public Bar readStruct(Reader r) throws IOException {
r.readStructId(255); r.readStructId(255);
return new Bar(r.readString()); return new Bar(r.readString());
} }
@@ -435,7 +435,7 @@ public class ReaderImplTest extends BriarTestCase {
public void testUnknownStructIdThrowsFormatException() throws Exception { public void testUnknownStructIdThrowsFormatException() throws Exception {
setContents("C0" + "83666F6F"); setContents("C0" + "83666F6F");
assertTrue(r.hasStruct(0)); assertTrue(r.hasStruct(0));
// No object reader has been added for struct ID 0 // No reader has been added for struct ID 0
try { try {
r.readStruct(0, Foo.class); r.readStruct(0, Foo.class);
fail(); fail();
@@ -445,15 +445,15 @@ public class ReaderImplTest extends BriarTestCase {
@Test @Test
public void testWrongClassThrowsFormatException() throws Exception { public void testWrongClassThrowsFormatException() throws Exception {
setContents("C0" + "83666F6F"); setContents("C0" + "83666F6F");
// Add an object reader for struct ID 0, class Foo // Add a reader for struct ID 0, class Foo
r.addObjectReader(0, new ObjectReader<Foo>() { r.addStructReader(0, new StructReader<Foo>() {
public Foo readObject(Reader r) throws IOException { public Foo readStruct(Reader r) throws IOException {
r.readStructId(0); r.readStructId(0);
return new Foo(r.readString()); return new Foo(r.readString());
} }
}); });
assertTrue(r.hasStruct(0)); assertTrue(r.hasStruct(0));
// Trying to read the object as class Bar should throw a FormatException // Trying to read the struct as class Bar should throw a FormatException
try { try {
r.readStruct(0, Bar.class); r.readStruct(0, Bar.class);
fail(); fail();
@@ -461,38 +461,38 @@ public class ReaderImplTest extends BriarTestCase {
} }
@Test @Test
public void testReadListUsingObjectReader() throws Exception { public void testReadListUsingStructReader() throws Exception {
setContents("A" + "1" + "C0" + "83666F6F"); setContents("A" + "1" + "C0" + "83666F6F");
// Add an object reader for a struct // Add a reader for a struct
r.addObjectReader(0, new ObjectReader<Foo>() { r.addStructReader(0, new StructReader<Foo>() {
public Foo readObject(Reader r) throws IOException { public Foo readStruct(Reader r) throws IOException {
r.readStructId(0); r.readStructId(0);
return new Foo(r.readString()); return new Foo(r.readString());
} }
}); });
// Check that the object reader is used for lists // Check that the reader is used for lists
List<Foo> l = r.readList(Foo.class); List<Foo> l = r.readList(Foo.class);
assertEquals(1, l.size()); assertEquals(1, l.size());
assertEquals("foo", l.get(0).s); assertEquals("foo", l.get(0).s);
} }
@Test @Test
public void testReadMapUsingObjectReader() throws Exception { public void testReadMapUsingStructReader() throws Exception {
setContents("B" + "1" + "C0" + "83666F6F" + "C1" + "83626172"); setContents("B" + "1" + "C0" + "83666F6F" + "C1" + "83626172");
// Add object readers for two structs // Add readers for two structs
r.addObjectReader(0, new ObjectReader<Foo>() { r.addStructReader(0, new StructReader<Foo>() {
public Foo readObject(Reader r) throws IOException { public Foo readStruct(Reader r) throws IOException {
r.readStructId(0); r.readStructId(0);
return new Foo(r.readString()); return new Foo(r.readString());
} }
}); });
r.addObjectReader(1, new ObjectReader<Bar>() { r.addStructReader(1, new StructReader<Bar>() {
public Bar readObject(Reader r) throws IOException { public Bar readStruct(Reader r) throws IOException {
r.readStructId(1); r.readStructId(1);
return new Bar(r.readString()); return new Bar(r.readString());
} }
}); });
// Check that the object readers are used for maps // Check that the readers are used for maps
Map<Foo, Bar> m = r.readMap(Foo.class, Bar.class); Map<Foo, Bar> m = r.readMap(Foo.class, Bar.class);
assertEquals(1, m.size()); assertEquals(1, m.size());
Entry<Foo, Bar> e = m.entrySet().iterator().next(); Entry<Foo, Bar> e = m.entrySet().iterator().next();