From da0ba7d6bb5370d24ec5f028292e13a71682a26c Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 31 Jan 2021 12:07:07 +0100 Subject: [PATCH] Update DatabaseMapDictionary.java --- .../collections/DatabaseMapDictionary.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java index a77ab74..6839d76 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java @@ -1,5 +1,6 @@ package it.cavallium.dbengine.database.collections; +import io.netty.buffer.Unpooled; import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.LLRange; @@ -18,7 +19,7 @@ public class DatabaseMapDictionary> implements public static final byte[] EMPTY_BYTES = new byte[0]; private final LLDictionary dictionary; private final SubStageGetter subStageGetter; - private final FixedLengthSerializer suffixKeySerializer; + private final FixedLengthSerializer keySuffixSerializer; private final byte[] keyPrefix; private final int keySuffixLength; private final int keyExtLength; @@ -70,10 +71,10 @@ public class DatabaseMapDictionary> implements this(dictionary, subStageGetter, keySerializer, EMPTY_BYTES, keyLength, keyExtLength); } - public DatabaseMapDictionary(LLDictionary dictionary, SubStageGetter subStageGetter, FixedLengthSerializer suffixKeySerializer, byte[] prefixKey, int keySuffixLength, int keyExtLength) { + public DatabaseMapDictionary(LLDictionary dictionary, SubStageGetter subStageGetter, FixedLengthSerializer keySuffixSerializer, byte[] prefixKey, int keySuffixLength, int keyExtLength) { this.dictionary = dictionary; this.subStageGetter = subStageGetter; - this.suffixKeySerializer = suffixKeySerializer; + this.keySuffixSerializer = keySuffixSerializer; this.keyPrefix = prefixKey; this.keySuffixLength = keySuffixLength; this.keyExtLength = keyExtLength; @@ -175,11 +176,18 @@ public class DatabaseMapDictionary> implements ); } - private T deserializeSuffix(byte[] suffix) { - return (T) new Object(); + //todo: temporary wrapper. convert the whole class to buffers + private T deserializeSuffix(byte[] keySuffix) { + var serialized = Unpooled.wrappedBuffer(keySuffix); + return keySuffixSerializer.deserialize(serialized, keySuffixLength); } + //todo: temporary wrapper. convert the whole class to buffers private byte[] serializeSuffix(T keySuffix) { - return new byte[0]; + var output = Unpooled.buffer(keySuffixLength, keySuffixLength); + var outputBytes = new byte[keySuffixLength]; + keySuffixSerializer.serialize(keySuffix, output, keySuffixLength); + output.getBytes(0, outputBytes, 0, keySuffixLength); + return outputBytes; } }