public static byte[] serialize(Set<ByteArrayWrapper> set) {
    if (CollectionUtils.isEmpty(set)) {
      return null;
    }

    // Calculate the total size of the resulting byte array
    // The first 4 bytes represent the size of the set
    int totalSize = 4;
    for (ByteArrayWrapper record : set) {
      // Each element consists of 4 bytes representing the size of the element
      totalSize += 4;
      totalSize += record.size;
    }

    // Create a new byte array with the total size
    ByteBuffer buffer = ByteBuffer.allocate(totalSize);
    buffer.putInt(set.size()); // Write the size of the set

    for (ByteArrayWrapper record : set) {
      buffer.putInt(record.size); // Write the size of the element
      buffer.put(record.bytes); // Write the element bytes
    }

    return buffer.array();
  }
Serializes a set of ByteArrayWrapper objects into a byte array.

@param set the set of ByteArrayWrapper objects to serialize
@return the serialized byte array
amoro-format-mixed/amoro-mixed-flink/amoro-mixed-flink-common/src/main/java/org/apache/amoro/flink/lookup/ByteArraySetSerializer.java