package it.cavallium.dbengine.database.remote; import it.cavallium.data.generator.DataSerializer; import it.cavallium.dbengine.lucene.analyzer.TextFieldsAnalyzer; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import org.jetbrains.annotations.NotNull; public class StringMapSerializer implements DataSerializer> { @Override public void serialize(DataOutput dataOutput, @NotNull Map stringTextFieldsAnalyzerMap) throws IOException { dataOutput.writeInt(stringTextFieldsAnalyzerMap.size()); for (Entry entry : stringTextFieldsAnalyzerMap.entrySet()) { dataOutput.writeUTF(entry.getKey()); dataOutput.writeUTF(entry.getValue()); } } @Override public @NotNull Map deserialize(DataInput dataInput) throws IOException { var size = dataInput.readInt(); var result = new HashMap(size); for (int i = 0; i < size; i++) { result.put(dataInput.readUTF(), dataInput.readUTF()); } return Collections.unmodifiableMap(result); } }