mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Retrieve messages from the database in raw form to avoid creating unnecessary short-lived objects. Added timestamps to headers.
This commit is contained in:
@@ -4,6 +4,8 @@ import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.briar.api.serial.Raw;
|
||||
|
||||
/**
|
||||
* An interface for writing a bundle of acknowledgements, subscriptions,
|
||||
* transport details and batches.
|
||||
@@ -18,8 +20,8 @@ public interface BundleWriter {
|
||||
Map<String, String> transports) throws IOException,
|
||||
GeneralSecurityException;
|
||||
|
||||
/** Adds a batch to the bundle and returns its identifier. */
|
||||
BatchId addBatch(Iterable<Message> messages) throws IOException,
|
||||
/** Adds a batch of messages to the bundle and returns its identifier. */
|
||||
BatchId addBatch(Iterable<Raw> messages) throws IOException,
|
||||
GeneralSecurityException;
|
||||
|
||||
/** Finishes writing the bundle. */
|
||||
|
||||
@@ -16,4 +16,7 @@ public interface Header {
|
||||
|
||||
/** Returns the transport details contained in the header. */
|
||||
Map<String, String> getTransports();
|
||||
|
||||
/** Returns the header's timestamp. */
|
||||
long getTimestamp();
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package net.sf.briar.api.protocol;
|
||||
|
||||
public interface MessageFactory {
|
||||
|
||||
Message createMessage(MessageId id, MessageId parent, GroupId group,
|
||||
AuthorId author, long timestamp, byte[] raw);
|
||||
}
|
||||
29
api/net/sf/briar/api/serial/RawByteArray.java
Normal file
29
api/net/sf/briar/api/serial/RawByteArray.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package net.sf.briar.api.serial;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/** A byte array wrapped in the Raw interface. */
|
||||
public class RawByteArray implements Raw {
|
||||
|
||||
private final byte[] bytes;
|
||||
|
||||
public RawByteArray(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof Raw) return Arrays.equals(bytes, ((Raw) o).getBytes());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user