@Override
    void serialize(RandomAccessOutput byteStream, Object obj,
        ObjectInspector objInspector, boolean skipLengthPrefix,
        BooleanRef warnedOnceNullMapKey) {
      int byteSizeStart = 0;
      int typeStart = 0;
      if (!skipLengthPrefix) {
        // 1/ reserve spaces for the byte size of the struct
        // which is a integer and takes four bytes
        byteSizeStart = byteStream.getLength();
        byteStream.reserve(4);
        typeStart = byteStream.getLength();
      }

      // 2/ serialize the union - tag/value
      UnionObjectInspector uoi = (UnionObjectInspector) objInspector;
      byte tag = uoi.getTag(obj);
      byteStream.write(tag);
      unionFieldSerializers[tag].serializeValue(
          byteStream, uoi.getField(obj), uoi.getObjectInspectors().get(tag),
          false, warnedOnceNullMapKey);

      if (!skipLengthPrefix) {
        // 3/ update the byte size of the struct
        int typeEnd = byteStream.getLength();
        int typeSize = typeEnd - typeStart;
        writeSizeAtOffset(byteStream, byteSizeStart, typeSize);
      }
    }
Abstract serializer class for serializing to LazyBinary format.
serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe2.java