/*
 * Copyright DataStax, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.datastax.oss.driver.core.type.codec;

import com.datastax.oss.driver.api.core.ProtocolVersion;
import com.datastax.oss.driver.api.core.type.DataType;
import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
import com.datastax.oss.driver.api.core.type.codec.TypeCodecs;
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.nio.ByteBuffer;

/**
 * A sample user codec implementation that we use in our tests.
 *
 * <p>It maps a CQL string to a Java string containing its textual representation.
 */
public class CqlIntToStringCodec implements TypeCodec<String> {

  @NonNull
  @Override
  public GenericType<String> getJavaType() {
    return GenericType.STRING;
  }

  @NonNull
  @Override
  public DataType getCqlType() {
    return DataTypes.INT;
  }

  @Override
  public ByteBuffer encode(String value, @NonNull ProtocolVersion protocolVersion) {
    if (value == null) {
      return null;
    } else {
      return TypeCodecs.INT.encode(Integer.parseInt(value), protocolVersion);
    }
  }

  @Override
  public String decode(ByteBuffer bytes, @NonNull ProtocolVersion protocolVersion) {
    return TypeCodecs.INT.decode(bytes, protocolVersion).toString();
  }

  @NonNull
  @Override
  public String format(String value) {
    throw new UnsupportedOperationException("Not implemented for this test");
  }

  @Override
  public String parse(String value) {
    throw new UnsupportedOperationException("Not implemented for this test");
  }
}

@@ -676,191 +676,26 @@
 ore.
-ProtocolVersion;%0Aimport com.datastax.oss.driver.api.core.type.DataType;%0Aimport com.datastax.oss.driver.api.core.type.DataTypes;%0Aimport com.datastax.oss.driver.api.core.type.codec.Type
+type.codec.Mapping
 Code
@@ -870,42 +870,15 @@
 ns.N
-onNull;%0Aimport java.nio.ByteBuffer
+ullable
 ;%0A%0A/
@@ -1071,118 +1071,107 @@
 dec 
-implements TypeCodec%3CString%3E %7B%0A%0A  @NonNull%0A  @Override%0A  public GenericType%3CString%3E getJavaType() %7B%0A    return
+extends MappingCodec%3CInteger, String%3E %7B%0A%0A  public CqlIntToStringCodec() %7B%0A    super(TypeCodecs.INT,
  Gen
@@ -1185,16 +1185,17 @@
 e.STRING
+)
 ;%0A  %7D%0A%0A 
@@ -1189,38 +1189,39 @@
 RING);%0A  %7D%0A%0A  @N
-onN
 ull
+able
 %0A  @Override%0A  p
@@ -1224,170 +1224,68 @@
 %0A  p
-ublic DataType getCqlType() %7B%0A    return DataTypes.INT;%0A  %7D%0A%0A  @Override%0A  public ByteBuffer encode(String value, @NonNull ProtocolVersion protocolVersion
+rotected String innerToOuter(@Nullable Integer value
 ) %7B%0A    
 if (
@@ -1284,12 +1284,15 @@
     
-if (
+return 
 valu
@@ -1304,132 +1304,52 @@
 null
-) %7B%0A      return null;%0A    %7D else %7B%0A      return TypeCodecs.INT.encode(Integer.parseInt(value), protocolVersion
+ ? null : value.toString(
 );%0A  
-  
 %7D
+%0A
 %0A  
-%7D%0A
+@Nullable
 %0A  @
@@ -1364,434 +1364,120 @@
 %0A  p
-ublic String decode(ByteBuffer bytes, @NonNull ProtocolVersion protocolVersion) %7B%0A    return TypeCodecs.INT.decode(bytes, protocolVersion).toString();%0A  %7D%0A%0A  @NonNull%0A  @Override%0A  public String format(String value) %7B%0A    throw new UnsupportedOperationException(%22Not implemented for this test%22);%0A  %7D%0A%0A  @Override%0A  public String parse(String value) %7B%0A    throw new UnsupportedOperationException(%22Not implemented for this test%22
+rotected Integer outerToInner(@Nullable String value) %7B%0A    return value == null ? null : Integer.parseInt(value
 );%0A 

Make CqlIntToStringCodec extend MappingCodec