mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Read/Write ChronicleMap's boostrapping header with Wire
This commit is contained in:
@@ -20,6 +20,8 @@ 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.BytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
@@ -30,8 +32,8 @@ import java.util.zip.InflaterInputStream;
|
||||
/**
|
||||
* Created by peter on 24/10/14.
|
||||
*/
|
||||
public enum DeflatorStringMarshaller
|
||||
implements BytesReader<CharSequence>, BytesWriter<CharSequence> {
|
||||
public enum DeflatorStringMarshaller implements BytesReader<CharSequence>,
|
||||
BytesWriter<CharSequence>, EnumMarshallable<DeflatorStringMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
private static final StringFactory STRING_FACTORY = getStringFactory();
|
||||
@@ -54,7 +56,7 @@ public enum DeflatorStringMarshaller
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Bytes out, CharSequence s) {
|
||||
public void write(Bytes out, @NotNull CharSequence s) {
|
||||
if (s == null) {
|
||||
out.writeStopBit(NULL_LENGTH);
|
||||
return;
|
||||
@@ -114,6 +116,11 @@ public enum DeflatorStringMarshaller
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeflatorStringMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private static abstract class StringFactory {
|
||||
abstract String fromChars(char[] chars) throws Exception;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ package net.openhft.chronicle.map;
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.BytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable;
|
||||
import net.openhft.chronicle.set.Builder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Issue43Test {
|
||||
@@ -34,7 +36,7 @@ public class Issue43Test {
|
||||
ChronicleMap<Long, ValueWrapper> map = ChronicleMapBuilder
|
||||
.of(Long.class, ValueWrapper.class)
|
||||
.entries(512)
|
||||
.valueMarshaller(new ArrayMarshaller())
|
||||
.valueMarshaller(ArrayMarshaller.INSTANCE)
|
||||
.constantValueSizeBySample(new ValueWrapper(new double[128]))
|
||||
.createPersistedTo(Builder.getPersistenceFile());
|
||||
System.out.println("Created the monkey map ValueWrapper 128");
|
||||
@@ -52,11 +54,12 @@ public class Issue43Test {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ArrayMarshaller
|
||||
implements BytesReader<ValueWrapper>, BytesWriter<ValueWrapper> {
|
||||
private enum ArrayMarshaller implements BytesReader<ValueWrapper>, BytesWriter<ValueWrapper>,
|
||||
EnumMarshallable<ArrayMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public void write(Bytes bytes, ValueWrapper vw) {
|
||||
public void write(Bytes bytes, @NotNull ValueWrapper vw) {
|
||||
bytes.writeInt(vw.values.length);
|
||||
|
||||
for (int i = 0; i < vw.values.length; i ++) {
|
||||
@@ -68,5 +71,10 @@ public class Issue43Test {
|
||||
public ValueWrapper read(Bytes in, ValueWrapper using) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package net.openhft.chronicle.map;
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.BytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -128,7 +129,8 @@ public class Issue58 {
|
||||
}
|
||||
|
||||
|
||||
enum UuidMarshaller implements BytesReader<UUID>, BytesWriter<UUID> {
|
||||
enum UuidMarshaller
|
||||
implements BytesReader<UUID>, BytesWriter<UUID>, EnumMarshallable<UuidMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
@@ -137,9 +139,15 @@ public class Issue58 {
|
||||
bytes.writeLong(uuid.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public UUID read(Bytes bytes, @Nullable UUID using) {
|
||||
return new UUID(bytes.readLong(), bytes.readLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public UuidMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.BytesMarshallable;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.BytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.Issue43Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ComplexSerializationTest {
|
||||
List<B> list_;
|
||||
}
|
||||
|
||||
enum AMarshaller implements BytesReader<A>, BytesWriter<A> {
|
||||
enum AMarshaller implements BytesReader<A>, BytesWriter<A>, EnumMarshallable<AMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
@@ -79,6 +79,11 @@ public class ComplexSerializationTest {
|
||||
}
|
||||
return using;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
static class B implements BytesMarshallable {
|
||||
|
||||
@@ -18,11 +18,12 @@ package net.openhft.chronicle.map.fromdocs;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
enum LongPairArrayReader implements SizedReader<LongPair[]> {
|
||||
enum LongPairArrayReader implements SizedReader<LongPair[]>, EnumMarshallable<LongPairArrayReader> {
|
||||
INSTANCE;
|
||||
|
||||
@NotNull
|
||||
@@ -50,4 +51,9 @@ enum LongPairArrayReader implements SizedReader<LongPair[]> {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongPairArrayReader readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,10 @@ package net.openhft.chronicle.map.fromdocs;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.hash.serialization.SizedWriter;
|
||||
import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
enum LongPairArrayWriter implements SizedWriter<LongPair[]> {
|
||||
enum LongPairArrayWriter implements SizedWriter<LongPair[]>, EnumMarshallable<LongPairArrayWriter> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
@@ -35,4 +36,9 @@ enum LongPairArrayWriter implements SizedWriter<LongPair[]> {
|
||||
out.writeLong(pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongPairArrayWriter readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user