Skip to content

Commit

Permalink
JavaFormatter: added serialization methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykang920 committed Apr 11, 2016
1 parent 355acbf commit bb9e6c8
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 64 deletions.
14 changes: 14 additions & 0 deletions x2/src/main/java/x2/Deserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ public Calendar readCallendar() throws IOException {

// Read methods for composite types

public byte[] readBytes() throws IOException {
byte[] value = null;
int length = readNonnegativeInt();
if (length == 0) { return value; }

buffer.checkLengthToRead(length);

value = new byte[length];
for (int i = 0; i < length; ++i) {
value[i] = buffer.get();
}
return value;
}

/** Decodes a cell-derived object out of the underlying buffer. */
public <T extends Cell> T readCell(Class<T> cls) throws IOException {
T value = null;
Expand Down
20 changes: 20 additions & 0 deletions x2/src/main/java/x2/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package x2;

import java.io.IOException;

import x2.util.*;

/** Common base class for all events. */
Expand Down Expand Up @@ -92,6 +94,24 @@ protected boolean isEquivalent(Cell other, Fingerprint fingerprint) {

// Serialization

@Override
public void deserialize(Deserializer deserializer) throws IOException {
super.deserialize(deserializer);
}

@Override
public int length() {
int length = Serializer.lengthInt(_getTypeId());
length += super.length();
return length;
}

@Override
public void serialize(Serializer serializer) {
serializer.writeInt(_getTypeId());
super.serialize(serializer);
}

// Built-in accessors and mutators

/** Gets the link session handle associated with this event. */
Expand Down
Loading

0 comments on commit bb9e6c8

Please sign in to comment.