mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Simplified the serialisation format. Other task #39.
The new format is simpler but less efficient for small integers, short strings and short byte arrays.
This commit is contained in:
@@ -94,7 +94,7 @@ class MessageFactoryImpl implements MessageFactory {
|
||||
if(author == null) w.writeNull();
|
||||
else writeAuthor(w, author);
|
||||
w.writeString(contentType);
|
||||
w.writeIntAny(timestamp);
|
||||
w.writeInteger(timestamp);
|
||||
byte[] salt = new byte[MESSAGE_SALT_LENGTH];
|
||||
random.nextBytes(salt);
|
||||
w.writeBytes(salt);
|
||||
|
||||
@@ -56,7 +56,7 @@ class MessageReader implements StructReader<UnverifiedMessage> {
|
||||
// Read the content type
|
||||
String contentType = r.readString(MAX_CONTENT_TYPE_LENGTH);
|
||||
// Read the timestamp
|
||||
long timestamp = r.readIntAny();
|
||||
long timestamp = r.readInteger();
|
||||
if(timestamp < 0) throw new FormatException();
|
||||
// Read the salt
|
||||
byte[] salt = r.readBytes(MESSAGE_SALT_LENGTH);
|
||||
|
||||
@@ -165,7 +165,7 @@ class PacketReaderImpl implements PacketReader {
|
||||
|
||||
public RetentionAck readRetentionAck() throws IOException {
|
||||
r.readStructStart(RETENTION_ACK);
|
||||
long version = r.readIntAny();
|
||||
long version = r.readInteger();
|
||||
if(version < 0) throw new FormatException();
|
||||
r.readStructEnd();
|
||||
return new RetentionAck(version);
|
||||
@@ -177,9 +177,9 @@ class PacketReaderImpl implements PacketReader {
|
||||
|
||||
public RetentionUpdate readRetentionUpdate() throws IOException {
|
||||
r.readStructStart(RETENTION_UPDATE);
|
||||
long retention = r.readIntAny();
|
||||
long retention = r.readInteger();
|
||||
if(retention < 0) throw new FormatException();
|
||||
long version = r.readIntAny();
|
||||
long version = r.readInteger();
|
||||
if(version < 0) throw new FormatException();
|
||||
r.readStructEnd();
|
||||
return new RetentionUpdate(retention, version);
|
||||
@@ -191,7 +191,7 @@ class PacketReaderImpl implements PacketReader {
|
||||
|
||||
public SubscriptionAck readSubscriptionAck() throws IOException {
|
||||
r.readStructStart(SUBSCRIPTION_ACK);
|
||||
long version = r.readIntAny();
|
||||
long version = r.readInteger();
|
||||
if(version < 0) throw new FormatException();
|
||||
r.readStructEnd();
|
||||
return new SubscriptionAck(version);
|
||||
@@ -213,7 +213,7 @@ class PacketReaderImpl implements PacketReader {
|
||||
r.readStructStart(TRANSPORT_ACK);
|
||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
||||
if(b.length < UniqueId.LENGTH) throw new FormatException();
|
||||
long version = r.readIntAny();
|
||||
long version = r.readInteger();
|
||||
if(version < 0) throw new FormatException();
|
||||
r.readStructEnd();
|
||||
return new TransportAck(new TransportId(b), version);
|
||||
@@ -245,7 +245,7 @@ class PacketReaderImpl implements PacketReader {
|
||||
}
|
||||
r.readMapEnd();
|
||||
// Read the version number
|
||||
long version = r.readIntAny();
|
||||
long version = r.readInteger();
|
||||
if(version < 0) throw new FormatException();
|
||||
// Read the end of the struct
|
||||
r.readStructEnd();
|
||||
|
||||
@@ -101,22 +101,22 @@ class PacketWriterImpl implements PacketWriter {
|
||||
|
||||
public void writeRetentionAck(RetentionAck a) throws IOException {
|
||||
w.writeStructStart(RETENTION_ACK);
|
||||
w.writeIntAny(a.getVersion());
|
||||
w.writeInteger(a.getVersion());
|
||||
w.writeStructEnd();
|
||||
if(flush) out.flush();
|
||||
}
|
||||
|
||||
public void writeRetentionUpdate(RetentionUpdate u) throws IOException {
|
||||
w.writeStructStart(RETENTION_UPDATE);
|
||||
w.writeIntAny(u.getRetentionTime());
|
||||
w.writeIntAny(u.getVersion());
|
||||
w.writeInteger(u.getRetentionTime());
|
||||
w.writeInteger(u.getVersion());
|
||||
w.writeStructEnd();
|
||||
if(flush) out.flush();
|
||||
}
|
||||
|
||||
public void writeSubscriptionAck(SubscriptionAck a) throws IOException {
|
||||
w.writeStructStart(SUBSCRIPTION_ACK);
|
||||
w.writeIntAny(a.getVersion());
|
||||
w.writeInteger(a.getVersion());
|
||||
w.writeStructEnd();
|
||||
if(flush) out.flush();
|
||||
}
|
||||
@@ -132,7 +132,7 @@ class PacketWriterImpl implements PacketWriter {
|
||||
w.writeStructEnd();
|
||||
}
|
||||
w.writeListEnd();
|
||||
w.writeIntAny(u.getVersion());
|
||||
w.writeInteger(u.getVersion());
|
||||
w.writeStructEnd();
|
||||
if(flush) out.flush();
|
||||
}
|
||||
@@ -140,7 +140,7 @@ class PacketWriterImpl implements PacketWriter {
|
||||
public void writeTransportAck(TransportAck a) throws IOException {
|
||||
w.writeStructStart(TRANSPORT_ACK);
|
||||
w.writeBytes(a.getId().getBytes());
|
||||
w.writeIntAny(a.getVersion());
|
||||
w.writeInteger(a.getVersion());
|
||||
w.writeStructEnd();
|
||||
if(flush) out.flush();
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class PacketWriterImpl implements PacketWriter {
|
||||
w.writeStructStart(TRANSPORT_UPDATE);
|
||||
w.writeBytes(u.getId().getBytes());
|
||||
w.writeMap(u.getProperties());
|
||||
w.writeIntAny(u.getVersion());
|
||||
w.writeInteger(u.getVersion());
|
||||
w.writeStructEnd();
|
||||
if(flush) out.flush();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class SubscriptionUpdateReader implements StructReader<SubscriptionUpdate> {
|
||||
groups.add(groupReader.readStruct(r));
|
||||
r.readListEnd();
|
||||
// Read the version number
|
||||
long version = r.readIntAny();
|
||||
long version = r.readInteger();
|
||||
if(version < 0) throw new FormatException();
|
||||
// Read the end of the struct
|
||||
r.readStructEnd();
|
||||
|
||||
Reference in New Issue
Block a user