This commit is contained in:
Rob Austin
2014-11-04 14:44:59 +00:00
parent a0c89935f5
commit 9dec1ed4db
64 changed files with 700 additions and 865 deletions
@@ -59,10 +59,10 @@ public enum ByteArrayMarshaller implements BytesInterop<byte[]>, BytesReader<byt
}
@Override
public byte[] read(Bytes bytes, long size, byte[] toReuse) {
if (toReuse == null || size != toReuse.length)
toReuse = new byte[(int) size];
bytes.read(toReuse);
return toReuse;
public byte[] read(Bytes bytes, long size, byte[] ba) {
if (ba == null || size != ba.length)
ba = new byte[(int) size];
bytes.read(ba);
return ba;
}
}
@@ -18,10 +18,8 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.hash.serialization.BytesInterop;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.chronicle.hash.serialization.Hasher;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.MultiStoreBytes;
import net.openhft.lang.io.NativeBytes;
@@ -30,8 +28,7 @@ import net.openhft.lang.io.serialization.impl.AllocateInstanceObjectFactory;
import net.openhft.lang.model.Byteable;
import org.jetbrains.annotations.NotNull;
public class ByteableMarshaller<E extends Byteable>
implements BytesInterop<E>, BytesReader<E>, SizeMarshaller {
public class ByteableMarshaller<E extends Byteable> implements AgileBytesMarshaller<E> {
private static final long serialVersionUID = 0L;
public static <E extends Byteable> ByteableMarshaller<E> of(@NotNull Class<E> eClass) {
@@ -117,13 +114,13 @@ public class ByteableMarshaller<E extends Byteable>
}
@Override
public E read(Bytes bytes, long size, E toReuse) {
public E read(Bytes bytes, long size, E e) {
try {
if (toReuse == null)
toReuse = getInstance();
setBytesAndOffset(toReuse, bytes);
if (e == null)
e = getInstance();
setBytesAndOffset(e, bytes);
bytes.skip(size);
return toReuse;
return e;
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
@@ -49,11 +49,11 @@ public enum CharArrayMarshaller implements BytesInterop<char[]>, BytesReader<cha
}
@Override
public char[] read(Bytes bytes, long size, char[] toReuse) {
if (toReuse == null || toReuse.length != size)
toReuse = new char[(int) size];
bytes.readFully(toReuse);
return toReuse;
public char[] read(Bytes bytes, long size, char[] chars) {
if (chars == null || chars.length != size)
chars = new char[(int) size];
bytes.readFully(chars);
return chars;
}
@Override
@@ -78,14 +78,14 @@ public final class CharSequenceReader<S extends CharSequence>
}
@Override
public S read(Bytes bytes, long size, S toReuse) {
public S read(Bytes bytes, long size, S s) {
Appendable appendable;
if (toReuse instanceof Appendable) {
appendable = (Appendable) toReuse;
if (toReuse instanceof StringBuilder) {
((StringBuilder) toReuse).setLength(0);
} else if (toReuse instanceof StringBuffer) {
((StringBuffer) toReuse).setLength(0);
if (s instanceof Appendable) {
appendable = (Appendable) s;
if (s instanceof StringBuilder) {
((StringBuilder) s).setLength(0);
} else if (s instanceof StringBuffer) {
((StringBuffer) s).setLength(0);
}
} else {
sb.setLength(0);
@@ -96,8 +96,8 @@ public final class CharSequenceReader<S extends CharSequence>
} catch (IOException e) {
throw new IllegalStateException(e);
}
if (appendable == toReuse)
return toReuse;
if (appendable == s)
return s;
return interner.intern(sb);
}
@@ -18,15 +18,13 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.hash.serialization.BytesInterop;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.chronicle.hash.serialization.Hasher;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import net.openhft.lang.io.Bytes;
import static java.lang.Double.doubleToLongBits;
public enum DoubleMarshaller implements BytesInterop<Double>, BytesReader<Double>, SizeMarshaller {
public enum DoubleMarshaller implements AgileBytesMarshaller<Double> {
INSTANCE;
@Override
@@ -70,7 +68,7 @@ public enum DoubleMarshaller implements BytesInterop<Double>, BytesReader<Double
}
@Override
public Double read(Bytes bytes, long size, Double toReuse) {
public Double read(Bytes bytes, long size, Double e) {
return read(bytes, size);
}
}
@@ -18,11 +18,11 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.hash.serialization.*;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.chronicle.hash.serialization.Hasher;
import net.openhft.lang.io.Bytes;
public enum IntegerMarshaller
implements BytesInterop<Integer>, BytesReader<Integer>, SizeMarshaller {
public enum IntegerMarshaller implements AgileBytesMarshaller<Integer> {
INSTANCE;
@Override
@@ -66,7 +66,7 @@ public enum IntegerMarshaller
}
@Override
public Integer read(Bytes bytes, long size, Integer toReuse) {
public Integer read(Bytes bytes, long size, Integer e) {
return bytes.readInt();
}
}
@@ -18,14 +18,11 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.hash.serialization.BytesInterop;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.chronicle.hash.serialization.Hasher;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import net.openhft.lang.io.Bytes;
public enum LongMarshaller
implements BytesInterop<Long>, BytesReader<Long>, SizeMarshaller {
public enum LongMarshaller implements AgileBytesMarshaller<Long> {
INSTANCE;
@Override
@@ -69,7 +66,7 @@ public enum LongMarshaller
}
@Override
public Long read(Bytes bytes, long size, Long toReuse) {
public Long read(Bytes bytes, long size, Long e) {
return bytes.readLong();
}
}
@@ -18,13 +18,10 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.hash.serialization.BytesInterop;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.lang.io.Bytes;
public enum VoidMarshaller
implements BytesInterop<Void>, BytesReader<Void>, SizeMarshaller {
public enum VoidMarshaller implements AgileBytesMarshaller<Void> {
INSTANCE;
@Override
@@ -69,7 +66,7 @@ public enum VoidMarshaller
}
@Override
public Void read(Bytes bytes, long size, Void toReuse) {
public Void read(Bytes bytes, long size, Void aVoid) {
return null;
}