private static void serializeStruct(RandomAccessOutput byteStream, Object obj,
      StructObjectInspector soi, BooleanRef warnedOnceNullMapKey) throws SerDeException {
    // do nothing for null struct
    if (null == obj) {
      return;
    }

    List<? extends StructField> fields = soi.getAllStructFieldRefs();
    int size = fields.size();
    Object[] fieldData = new Object[size];
    List<ObjectInspector> fieldOis = new ArrayList<ObjectInspector>(size);
    for (int i = 0; i < size; ++i) {
      StructField field = fields.get(i);
      fieldData[i] = soi.getStructFieldData(obj, field);
      fieldOis.add(field.getFieldObjectInspector());
    }

    serializeStruct(byteStream, fieldData, fieldOis, warnedOnceNullMapKey);
  }
Serialize an object to a byte buffer in a binary compact way.
serde/src/java/org/apache/hadoop/hive/serde2/lazybinary/LazyBinarySerDe.java