// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.mvstore.index;

import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.EnumeratorStringDescriptor;
import com.intellij.util.io.IntInlineKeyDescriptor;
import com.intellij.util.io.KeyDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.mvstore.type.DataType;
import org.jetbrains.mvstore.type.IntDataType;
import org.jetbrains.mvstore.type.KeyableDataType;
import org.jetbrains.mvstore.type.StringDataType;

class DataExternalizerDataTypeConverter {
  @SuppressWarnings("unchecked")
  @NotNull
  static <T> DataType<T> convert(@NotNull DataExternalizer<T> externalizer) {
    if (externalizer instanceof IntInlineKeyDescriptor) {
      return (DataType<T>)IntDataType.INSTANCE;
    }
    if (externalizer instanceof EnumeratorStringDescriptor) {
      return (DataType<T>)StringDataType.INSTANCE;
    }
    throw new IllegalArgumentException("unsupported externalizer");
  }

  @NotNull
  static <T> KeyableDataType<T> convert(@NotNull KeyDescriptor<T> descriptor) {
    DataType<T> dataType = convert((DataExternalizer<T>)descriptor);
    return (KeyableDataType<T>)dataType;
  }
}

@@ -196,367 +196,185 @@
 lij.
-util.io.DataExternalizer;%0Aimport com.intellij.util.io.EnumeratorStringDescriptor;%0Aimport com.intellij.util.io.IntInlineKeyDescriptor;%0Aimport com.intellij.util.io.KeyDescriptor;%0Aimport org.jetbrains.annotations.NotNull;%0Aimport org.jetbrains.mvstore.type.DataType;%0Aimport org.jetbrains.mvstore.type.IntDataType;%0Aimport org.jetbrains.mvstore.type.KeyableDataType
+openapi.util.io.ByteArraySequence;%0Aimport com.intellij.util.io.*;%0Aimport io.netty.buffer.ByteBuf;%0Aimport org.jetbrains.annotations.NotNull;%0Aimport org.jetbrains.mvstore.DataUtil
 ;%0Aim
@@ -405,30 +405,17 @@
 re.type.
-StringDataType
+*
 ;%0A%0Aclass
@@ -800,24 +800,151 @@
 ANCE;%0A    %7D%0A
+    if (externalizer instanceof ByteSequenceDataExternalizer) %7B%0A      return (DataType%3CT%3E)ByteSequenceDataType.INSTANCE;%0A    %7D%0A
     throw ne
@@ -1208,11 +1208,798 @@
 ype;%0A  %7D
+%0A%0A  private static final class ByteSequenceDataType implements DataType%3CByteArraySequence%3E %7B%0A    public static final ByteSequenceDataType INSTANCE = new ByteSequenceDataType();%0A    @Override%0A    public int getMemory(ByteArraySequence obj) %7B%0A      return DataUtil.VAR_INT_MAX_SIZE + obj.getLength();%0A    %7D%0A%0A    @Override%0A    public int getFixedMemory() %7B%0A      return -1;%0A    %7D%0A%0A    @Override%0A    public void write(ByteBuf buf, ByteArraySequence obj) %7B%0A      ByteArrayDataType.INSTANCE.write(buf, obj.toBytes());%0A    %7D%0A%0A    @Override%0A    public ByteArraySequence read(ByteBuf buff) %7B%0A      return new ByteArraySequence(ByteArrayDataType.INSTANCE.read(buff));%0A    %7D%0A%0A    @Override%0A    public ByteArraySequence%5B%5D createStorage(int size) %7B%0A      return new ByteArraySequence%5Bsize%5D;%0A    %7D%0A  %7D
 %0A%7D%0A

add ByteSequenceDataType to convert ByteSequenceDataExternalizer to mvstore data-type