@Override
    void serialize(RandomAccessOutput byteStream, Object obj, ObjectInspector objInspector,
        boolean skipLengthPrefix, BooleanRef warnedOnceNullMapKey) {
      BinaryObjectInspector baoi = (BinaryObjectInspector) objInspector;
      BytesWritable bw = baoi.getPrimitiveWritableObject(obj);
      int length = bw.getLength();
      if(!skipLengthPrefix){
        LazyBinaryUtils.writeVInt(byteStream, length);
      } else {
        if (length == 0){
          throw new RuntimeException("LazyBinaryColumnarSerde cannot serialize a non-null zero "
              + "length binary field. Consider using either LazyBinarySerde or ColumnarSerde.");
        }
      }
      byteStream.write(bw.getBytes(),0,length);
    }
Abstract serializer class for serializing to LazyBinary format.
serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe2.java