code: def _copy_normal_buffer_if_needed(
      buf: "pyarrow.Buffer",
      byte_width: int,
      offset: int,
      length: int,
  ) -> "pyarrow.Buffer":
      """Copy buffer, if needed."""
      byte_offset = offset * byte_width
      byte_length = length * byte_width
      if offset > 0 or byte_length < buf.size:
          # Array is a zero-copy slice, so we need to copy to a new buffer before
          # serializing; this slice of the underlying buffer (not the array) will ensure
          # that the buffer is properly copied at pickle-time.
          buf = buf.slice(byte_offset, byte_length)
      return buf
  
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 25 for calling a global function with example usage: _copy_normal_buffer_if_needed(buf, byte_width, offset, length) and returns: buf