Read/Write ChronicleMap's boostrapping header with Wire

This commit is contained in:
leventov
2015-11-25 20:37:19 +03:00
parent d32f7e9e62
commit fe77012381
57 changed files with 816 additions and 197 deletions
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
public enum BooleanMarshaller
implements SizedReader<Boolean>, BytesReader<Boolean>,
SizedWriter<Boolean>, BytesWriter<Boolean> {
SizedWriter<Boolean>, BytesWriter<Boolean>, EnumMarshallable<BooleanMarshaller> {
INSTANCE;
@Override
@@ -55,4 +55,9 @@ public enum BooleanMarshaller
public void write(Bytes out, @NotNull Boolean toWrite) {
out.writeByte((byte) (toWrite ? 'Y' : 0));
}
@Override
public BooleanMarshaller readResolve() {
return INSTANCE;
}
}
@@ -17,10 +17,13 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.HeapBytesStore;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.AbstractData;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -93,4 +96,15 @@ public class ByteArrayDataAccess extends AbstractData<byte[]> implements DataAcc
public DataAccess<byte[]> copy() {
return new ByteArrayDataAccess();
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
// no fields to read
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
// no fields to write
}
}
@@ -21,7 +21,8 @@ import net.openhft.chronicle.hash.serialization.SizedReader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public enum ByteArraySizedReader implements SizedReader<byte[]> {
public enum ByteArraySizedReader
implements SizedReader<byte[]>, EnumMarshallable<ByteArraySizedReader> {
INSTANCE;
@NotNull
@@ -40,4 +41,9 @@ public enum ByteArraySizedReader implements SizedReader<byte[]> {
size + " given. Memory corruption?");
return (int) size;
}
@Override
public ByteArraySizedReader readResolve() {
return INSTANCE;
}
}
@@ -20,6 +20,8 @@ import net.openhft.chronicle.bytes.*;
import net.openhft.chronicle.hash.AbstractData;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import sun.nio.ch.DirectBuffer;
@@ -116,4 +118,15 @@ public class ByteBufferDataAccess extends AbstractData<ByteBuffer>
public DataAccess<ByteBuffer> copy() {
return new ByteBufferDataAccess();
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
// no fields to read
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
// no fields to write
}
}
@@ -23,7 +23,8 @@ import org.jetbrains.annotations.Nullable;
import java.nio.ByteBuffer;
public enum ByteBufferSizedReader implements SizedReader<ByteBuffer> {
public enum ByteBufferSizedReader
implements SizedReader<ByteBuffer>, EnumMarshallable<ByteBufferSizedReader> {
INSTANCE;
@NotNull
@@ -43,4 +44,9 @@ public enum ByteBufferSizedReader implements SizedReader<ByteBuffer> {
using.flip();
return using;
}
@Override
public ByteBufferSizedReader readResolve() {
return INSTANCE;
}
}
@@ -17,9 +17,12 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Byteable;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -89,6 +92,6 @@ public class ByteableDataAccess<T extends Byteable> extends InstanceCreatingMars
@Override
public DataAccess<T> copy() {
return new ByteableDataAccess<>(tClass);
return new ByteableDataAccess<>(tClass());
}
}
@@ -17,9 +17,12 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.SizedReader;
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -27,7 +30,7 @@ public class BytesAsSizedReader<T>
implements SizedReader<T>, StatefulCopyable<BytesAsSizedReader<T>> {
/** Config field */
private final BytesReader<T> reader;
private BytesReader<T> reader;
public BytesAsSizedReader(BytesReader<T> reader) {
this.reader = reader;
@@ -47,4 +50,14 @@ public class BytesAsSizedReader<T>
return this;
}
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
reader = wireIn.read(() -> "reader").typedMarshallable();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
wireOut.write(() -> "reader").typedMarshallable(reader);
}
}
@@ -18,9 +18,11 @@ package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.BytesMarshallable;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.wire.WireIn;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -41,6 +43,12 @@ public class BytesMarshallableDataAccess<T extends BytesMarshallable>
initTransients();
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
super.readMarshallable(wireIn);
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
@@ -109,6 +117,6 @@ public class BytesMarshallableDataAccess<T extends BytesMarshallable>
@Override
public DataAccess<T> copy() {
return new BytesMarshallableDataAccess<>(tClass);
return new BytesMarshallableDataAccess<>(tClass());
}
}
@@ -30,11 +30,17 @@ import org.jetbrains.annotations.NotNull;
*
* @see CharSequenceBytesWriter
*/
public enum CharSequenceBytesWriter implements BytesWriter<CharSequence> {
public enum CharSequenceBytesWriter
implements BytesWriter<CharSequence>, EnumMarshallable<CharSequenceBytesWriter> {
INSTANCE;
@Override
public void write(Bytes out, @NotNull CharSequence toWrite) {
out.writeUtf8(toWrite);
}
@Override
public CharSequenceBytesWriter readResolve() {
return INSTANCE;
}
}
@@ -18,8 +18,11 @@ package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.BytesUtil;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.hash.serialization.SizedReader;
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -70,4 +73,15 @@ public class CharSequenceSizedReader
public CharSequenceSizedReader copy() {
return new CharSequenceSizedReader();
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
// no fields to read
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
// no fields to write
}
}
@@ -21,7 +21,8 @@ import net.openhft.chronicle.bytes.BytesUtil;
import net.openhft.chronicle.hash.serialization.SizedWriter;
import org.jetbrains.annotations.NotNull;
public enum CharSequenceSizedWriter implements SizedWriter<CharSequence> {
public enum CharSequenceSizedWriter
implements SizedWriter<CharSequence>, EnumMarshallable<CharSequenceSizedWriter> {
INSTANCE;
@Override
@@ -33,4 +34,9 @@ public enum CharSequenceSizedWriter implements SizedWriter<CharSequence> {
public void write(@NotNull Bytes out, long size, @NotNull CharSequence toWrite) {
BytesUtil.appendUtf8(out, toWrite);
}
@Override
public CharSequenceSizedWriter readResolve() {
return INSTANCE;
}
}
@@ -17,12 +17,16 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
public final class ConstantSizeMarshaller implements SizeMarshaller {
/** Config field */
private final long constantSize;
private long constantSize;
public ConstantSizeMarshaller(long constantSize) {
this.constantSize = constantSize;
@@ -62,4 +66,14 @@ public final class ConstantSizeMarshaller implements SizeMarshaller {
public long readSize(Bytes in) {
return constantSize;
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
constantSize = wireIn.read(() -> "constantSize").int64();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
wireOut.write(() -> "constantSize").int64(constantSize);
}
}
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
public enum DoubleMarshaller
implements SizedReader<Double>, BytesReader<Double>,
SizedWriter<Double>, BytesWriter<Double> {
SizedWriter<Double>, BytesWriter<Double>, EnumMarshallable<DoubleMarshaller> {
INSTANCE;
@NotNull
@@ -55,4 +55,9 @@ public enum DoubleMarshaller
public void write(Bytes out, @NotNull Double toWrite) {
out.writeDouble(toWrite);
}
@Override
public DoubleMarshaller readResolve() {
return INSTANCE;
}
}
@@ -17,11 +17,14 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.BytesWriter;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.hash.serialization.SizedReader;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -34,8 +37,8 @@ public class ExternalBytesMarshallableDataAccess<T> extends InstanceCreatingMars
implements DataAccess<T>, Data<T> {
// Config fields
private final SizedReader<T> reader;
private final BytesWriter<? super T> writer;
private SizedReader<T> reader;
private BytesWriter<? super T> writer;
/** Cache field */
private transient Bytes bytes;
@@ -120,6 +123,21 @@ public class ExternalBytesMarshallableDataAccess<T> extends InstanceCreatingMars
@Override
public DataAccess<T> copy() {
return new ExternalBytesMarshallableDataAccess<>(
tClass, copyIfNeeded(reader), copyIfNeeded(writer));
tClass(), copyIfNeeded(reader), copyIfNeeded(writer));
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
super.readMarshallable(wireIn);
reader = wireIn.read(() -> "reader").typedMarshallable();
writer = wireIn.read(() -> "writer").typedMarshallable();
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
super.writeMarshallable(wireOut);
wireOut.write(() -> "reader").typedMarshallable(reader);
wireOut.write(() -> "writer").typedMarshallable(writer);
}
}
@@ -16,8 +16,11 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -29,12 +32,16 @@ import java.io.ObjectOutputStream;
public class ExternalizableDataAccess<T extends Externalizable> extends SerializableDataAccess<T> {
/** Config field */
protected final Class<T> tClass;
private Class<T> tClass;
public ExternalizableDataAccess(Class<T> tClass) {
this.tClass = tClass;
}
protected Class<T> tClass() {
return tClass;
}
protected T createInstance() {
try {
return tClass.newInstance();
@@ -74,4 +81,15 @@ public class ExternalizableDataAccess<T extends Externalizable> extends Serializ
public DataAccess<T> copy() {
return new ExternalizableDataAccess<>(tClass);
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
tClass = wireIn.read(() -> "tClass").typeLiteral();
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
wireOut.write(() -> "tClass").typeLiteral(tClass);
}
}
@@ -16,13 +16,17 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.hash.serialization.SizedReader;
import net.openhft.chronicle.map.ChronicleMapBuilder;
import net.openhft.chronicle.wire.Marshallable;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
import java.lang.reflect.Constructor;
/**
* Holds new instance creation logic, common for many {@link DataAccess} and {@link SizedReader}
@@ -30,12 +34,9 @@ import java.lang.reflect.Constructor;
*
* @param <T> the type of objects deserialized
*/
public abstract class InstanceCreatingMarshaller<T> implements Serializable {
public abstract class InstanceCreatingMarshaller<T> implements Serializable, Marshallable {
/**
* The class of objects deserialized.
*/
protected final Class<T> tClass;
private Class<T> tClass;
/**
* Constructor for use in subclasses.
@@ -46,6 +47,13 @@ public abstract class InstanceCreatingMarshaller<T> implements Serializable {
this.tClass = tClass;
}
/**
* Returns the class of objects deserialized.
*/
protected Class<T> tClass() {
return tClass;
}
/**
* Creates a new {@code T} instance by calling {@link Class#newInstance()}. If you need
* different logic, i. e. calling a constructor with parameter, override this method in a
@@ -70,4 +78,15 @@ public abstract class InstanceCreatingMarshaller<T> implements Serializable {
"Chronicle Map via keyMarshaller[s]() or valueMarshaller[s]() methods", e);
}
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
//noinspection unchecked
tClass = wireIn.read(() -> "tClass").typeLiteral();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
wireOut.write(() -> "tClass").typeLiteral(tClass);
}
}
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
public enum IntegerMarshaller
implements SizedReader<Integer>, BytesReader<Integer>,
SizedWriter<Integer>, BytesWriter<Integer> {
SizedWriter<Integer>, BytesWriter<Integer>, EnumMarshallable<IntegerMarshaller> {
INSTANCE;
@NotNull
@@ -55,4 +55,9 @@ public enum IntegerMarshaller
public void write(Bytes out, @NotNull Integer toWrite) {
out.writeInt(toWrite);
}
@Override
public IntegerMarshaller readResolve() {
return INSTANCE;
}
}
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
public enum LongMarshaller
implements SizedReader<Long>, BytesReader<Long>,
SizedWriter<Long>, BytesWriter<Long> {
SizedWriter<Long>, BytesWriter<Long>, EnumMarshallable<LongMarshaller> {
INSTANCE;
@Override
@@ -55,4 +55,9 @@ public enum LongMarshaller
public void write(Bytes out, @NotNull Long toWrite) {
out.writeLong(toWrite);
}
@Override
public LongMarshaller readResolve() {
return INSTANCE;
}
}
@@ -37,6 +37,6 @@ public class NotReusingSizedMarshallableDataAccess<T> extends SizedMarshallableD
@Override
public DataAccess<T> copy() {
return new NotReusingSizedMarshallableDataAccess<>(
tClass, copyIfNeeded(sizedReader), copyIfNeeded(sizedWriter));
tClass(), copyIfNeeded(sizedReader()), copyIfNeeded(sizedWriter()));
}
}
@@ -17,10 +17,13 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.AbstractData;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -46,7 +49,7 @@ public class SerializableDataAccess<T extends Serializable> extends AbstractData
initTransients();
}
private void initTransients() {
void initTransients() {
bytes = Bytes.allocateElasticDirect(1);
out = bytes.outputStream();
in = bytes.inputStream();
@@ -107,4 +110,15 @@ public class SerializableDataAccess<T extends Serializable> extends AbstractData
public DataAccess<T> copy() {
return new SerializableDataAccess<>();
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
// no fields to read
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
// no fields to write
}
}
@@ -17,8 +17,11 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.SizedReader;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -44,4 +47,14 @@ public class SerializableReader<T extends Serializable>
throw new RuntimeException(e);
}
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
// no fields to read
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
// no fields to write
}
}
@@ -17,11 +17,14 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.hash.serialization.SizedReader;
import net.openhft.chronicle.hash.serialization.SizedWriter;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -34,8 +37,8 @@ public class SizedMarshallableDataAccess<T> extends InstanceCreatingMarshaller<T
implements DataAccess<T>, Data<T> {
// Config fields
final SizedReader<T> sizedReader;
final SizedWriter<? super T> sizedWriter;
private SizedReader<T> sizedReader;
private SizedWriter<? super T> sizedWriter;
/** Cache field */
private transient Bytes bytes;
@@ -51,6 +54,14 @@ public class SizedMarshallableDataAccess<T> extends InstanceCreatingMarshaller<T
initTransients();
}
SizedReader<T> sizedReader() {
return sizedReader;
}
SizedWriter<? super T> sizedWriter() {
return sizedWriter;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
@@ -120,6 +131,21 @@ public class SizedMarshallableDataAccess<T> extends InstanceCreatingMarshaller<T
@Override
public DataAccess<T> copy() {
return new SizedMarshallableDataAccess<>(
tClass, copyIfNeeded(sizedReader), copyIfNeeded(sizedWriter));
tClass(), copyIfNeeded(sizedReader), copyIfNeeded(sizedWriter));
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
super.readMarshallable(wireIn);
sizedReader = wireIn.read(() -> "sizedReader").typedMarshallable();
sizedWriter = wireIn.read(() -> "sizedWriter").typedMarshallable();
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
super.writeMarshallable(wireOut);
wireOut.write(() -> "sizedReader").typedMarshallable(sizedReader);
wireOut.write(() -> "sizedWriter").typedMarshallable(sizedWriter);
}
}
@@ -23,7 +23,8 @@ import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import static java.lang.Math.max;
import static java.lang.Math.min;
public enum StopBitSizeMarshaller implements SizeMarshaller {
public enum StopBitSizeMarshaller
implements SizeMarshaller, EnumMarshallable<StopBitSizeMarshaller> {
INSTANCE;
private static final long MIN_ENCODABLE_SIZE = Long.MIN_VALUE;
@@ -75,4 +76,9 @@ public enum StopBitSizeMarshaller implements SizeMarshaller {
public long readSize(Bytes in) {
return BytesUtil.readStopBit(in);
}
@Override
public StopBitSizeMarshaller readResolve() {
return INSTANCE;
}
}
@@ -22,7 +22,8 @@ import net.openhft.chronicle.hash.serialization.SizedReader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public enum StringBuilderSizedReader implements SizedReader<StringBuilder> {
public enum StringBuilderSizedReader
implements SizedReader<StringBuilder>, EnumMarshallable<StringBuilderSizedReader> {
INSTANCE;
@NotNull
@@ -40,4 +41,9 @@ public enum StringBuilderSizedReader implements SizedReader<StringBuilder> {
BytesUtil.parseUtf8(in, using, csLen);
return using;
}
@Override
public StringBuilderSizedReader readResolve() {
return INSTANCE;
}
}
@@ -17,10 +17,13 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.ListMarshaller;
import net.openhft.chronicle.hash.serialization.SetMarshaller;
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -66,4 +69,15 @@ public class StringBytesReader
public StringBytesReader copy() {
return new StringBytesReader();
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
// no fields to read
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
// no fields to write
}
}
@@ -18,8 +18,11 @@ package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.BytesUtil;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.hash.serialization.SizedReader;
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -58,4 +61,15 @@ public class StringSizedReader implements SizedReader<String>, StatefulCopyable<
public StringSizedReader copy() {
return new StringSizedReader();
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
// no fields to read
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
// no fields to write
}
}
@@ -17,12 +17,15 @@
package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Byteable;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.AbstractData;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.values.Copyable;
import net.openhft.chronicle.values.Values;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -33,12 +36,12 @@ import static net.openhft.chronicle.bytes.NativeBytesStore.nativeStoreWithFixedC
public class ValueDataAccess<T> extends AbstractData<T> implements DataAccess<T> {
/** The interface of values serialized. */
protected final Class<T> valueType;
/** Config field */
private Class<T> valueType;
// Cache fields
protected transient Class<? extends T> nativeClass;
protected transient Class<? extends T> heapClass;
private transient Class<? extends T> nativeClass;
private transient Class<? extends T> heapClass;
private transient Byteable nativeInstance;
private transient Copyable nativeInstanceAsCopyable;
@@ -50,6 +53,19 @@ public class ValueDataAccess<T> extends AbstractData<T> implements DataAccess<T>
initTransients();
}
/** Returns the interface of values serialized. */
protected Class<T> valueType() {
return valueType;
}
protected Class<? extends T> nativeClass() {
return nativeClass;
}
protected Class<? extends T> heapClass() {
return heapClass;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
@@ -120,4 +136,15 @@ public class ValueDataAccess<T> extends AbstractData<T> implements DataAccess<T>
public DataAccess<T> copy() {
return new ValueDataAccess<>(valueType);
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
valueType = wireIn.read(() -> "valueType").typeLiteral();
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
wireOut.write(() -> "valueType").typeLiteral(valueType);
}
}
@@ -18,11 +18,14 @@ package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Byteable;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.IORuntimeException;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.SizedReader;
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
import net.openhft.chronicle.values.Copyable;
import net.openhft.chronicle.values.Values;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -32,12 +35,12 @@ import java.io.ObjectInputStream;
public class ValueReader<T>
implements SizedReader<T>, BytesReader<T>, StatefulCopyable<ValueReader<T>> {
/** The interface of values deserialized. */
protected final Class<T> valueType;
/** Config field */
private Class<T> valueType;
// Cache fields
protected transient Class<? extends T> heapClass;
protected transient Class<? extends T> nativeClass;
private transient Class<? extends T> nativeClass;
private transient Class<? extends T> heapClass;
private transient Byteable nativeReference;
public ValueReader(Class<T> valueType) {
@@ -45,14 +48,27 @@ public class ValueReader<T>
initTransients();
}
/** Returns the interface of values deserialized. */
protected Class<T> valueType() {
return valueType;
}
protected Class<? extends T> nativeClass() {
return nativeClass;
}
protected Class<? extends T> heapClass() {
return heapClass;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
heapClass = Values.heapClassFor(valueType);
nativeClass = Values.nativeClassFor(valueType);
heapClass = Values.heapClassFor(valueType);
nativeReference = (Byteable) Values.newNativeReference(valueType);
}
@@ -92,4 +108,15 @@ public class ValueReader<T>
public ValueReader<T> copy() {
return new ValueReader<>(valueType);
}
@Override
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
valueType = wireIn.read(() -> "valueType").typeLiteral();
initTransients();
}
@Override
public void writeMarshallable(@NotNull WireOut wireOut) {
wireOut.write(() -> "valueType").typeLiteral(valueType);
}
}