code: def _map_array_to_array_payload(
      a: "pyarrow.MapArray",
  ) -> "PicklableArrayPayload":
      """Serialize map arrays to PicklableArrayPayload."""
      import pyarrow as pa
  
      # Dedicated path for MapArrays.
      # Buffer scheme: [bitmap, offsets, child_struct_array_buffers, ...]
      buffers = a.buffers()
      assert len(buffers) > 0, len(buffers)
  
      # Copy bitmap buffer, if needed.
      if a.null_count > 0:
          bitmap_buf = _copy_bitpacked_buffer_if_needed(
              buffers[0], a.offset, len(a)
          )
      else:
          bitmap_buf = None
  
      new_buffers = [bitmap_buf]
  
      # Copy offsets buffer, if needed.
      offset_buf = buffers[1]
      (
          offset_buf,
          data_offset,
          data_length,
      ) = _copy_offsets_buffer_if_needed(
          offset_buf, a.type, a.offset, len(a)
      )
  
      if isinstance(a, pa.lib.ListArray):
          # Map arrays directly expose the one child struct array in pyarrow>=7.0.0, which
          # is easier to work with than the raw buffers.
          new_buffers.append(offset_buf)
          children = [
              _array_to_array_payload(
                  a.values.slice(data_offset, data_length)
              )
          ]
      else:
          # In pyarrow<7.0.0, the child struct array is not exposed, so we work with the
          # key and item arrays.
          buffers = a.buffers()
          assert len(buffers) > 2, len(buffers)
          # Reconstruct offsets array.
          offsets = pa.Array.from_buffers(
              pa.int32(), len(a) + 1, [bitmap_buf, offset_buf]
          )
          # Propagate slice to keys.
          keys = a.keys.slice(data_offset, data_length)
          # Propagate slice to items.
          items = a.items.slice(data_offset, data_length)
          children = [
              _array_to_array_payload(offsets),
              _array_to_array_payload(keys),
              _array_to_array_payload(items),
          ]
      return PicklableArrayPayload(
          type=a.type,
          length=len(a),
          buffers=new_buffers,
          null_count=a.null_count,
          offset=0,
          children=children,
      )
  
imports: from dataclasses import dataclass
  import logging
  import os
  import sys
  from typing import List, Tuple, Optional, TYPE_CHECKING
label_desc: Use image node_id 22 for calling a global function with example usage: _map_array_to_array_payload(a) and returns: PicklableArrayPayload