@Override
  public Block readBlock(SliceInput sliceInput) {
    int positionCount = sliceInput.readInt();

    boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount);

    long[] values = new long[positionCount];
    for (int position = 0; position < positionCount; position++) {
      if (!valueIsNull[position]) {
        values[position] = sliceInput.readLong();
      }
    }

    return new LongArrayBlock(positionCount, valueIsNull, values);
  }
  private static Block toBlock(Type type, SliceInput input, int length) {
    BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), 1, length);
    if (type.getJavaType() == long.class) {
      type.writeLong(builder, input.readLong());
    } else if (type.getJavaType() == double.class) {
      type.writeDouble(builder, input.readDouble());
    } else if (type.getJavaType() == Slice.class) {
      type.writeSlice(builder, input.readSlice(length));
    } else if (type.getJavaType() == boolean.class) {
      type.writeBoolean(builder, input.readByte() != 0);
    } else {
      throw new IllegalArgumentException("Unsupported type: " + type.getJavaType().getSimpleName());
    }

    return builder.build();
  }