code: def merge_memoryviews(mvs: Sequence[memoryview]) -> memoryview:
      """
      Zero-copy "concatenate" a sequence of contiguous memoryviews.
  
      Returns a new memoryview which slices into the underlying buffer
      to extract out the portion equivalent to all of ``mvs`` being concatenated.
  
      All the memoryviews must:
      * Share the same underlying buffer (``.obj``)
      * When merged, cover a continuous portion of that buffer with no gaps
      * Have the same strides
      * Be 1-dimensional
      * Have the same format
      * Be contiguous
  
      Raises ValueError if these conditions are not met.
      """
      if not mvs:
          return memoryview(bytearray())
      if len(mvs) == 1:
          return mvs[0]
  
      first = mvs[0]
      if not isinstance(first, memoryview):
          raise TypeError(f"Expected memoryview; got {type(first)}")
      obj = first.obj
      format = first.format
  
      first_start_addr = 0
      nbytes = 0
      for i, mv in enumerate(mvs):
          if not isinstance(mv, memoryview):
              raise TypeError(
                  f"{i}: expected memoryview; got {type(mv)}"
              )
  
          if mv.nbytes == 0:
              continue
  
          if mv.obj is not obj:
              raise ValueError(
                  f"{i}: memoryview has different buffer: {mv.obj!r} vs {obj!r}"
              )
          if not mv.contiguous:
              raise ValueError(f"{i}: memoryview non-contiguous")
          if mv.ndim != 1:
              raise ValueError(
                  f"{i}: memoryview has {mv.ndim} dimensions, not 1"
              )
          if mv.format != format:
              raise ValueError(
                  f"{i}: inconsistent format: {mv.format} vs {format}"
              )
  
          start_addr = address_of_memoryview(mv)
          if first_start_addr == 0:
              first_start_addr = start_addr
          else:
              expected_addr = first_start_addr + nbytes
              if start_addr != expected_addr:
                  raise ValueError(
                      f"memoryview {i} does not start where the previous ends. "
                      f"Expected {expected_addr:x}, starts {start_addr - expected_addr} byte(s) away."
                  )
          nbytes += mv.nbytes
  
      if nbytes == 0:
          # all memoryviews were zero-length
          assert len(first) == 0
          return first
  
      assert (
          first_start_addr != 0
      ), "Underlying buffer is null pointer?!"
  
      base_mv = memoryview(obj).cast("B")
      base_start_addr = address_of_memoryview(base_mv)
      start_index = first_start_addr - base_start_addr
  
      return base_mv[start_index : start_index + nbytes].cast(format)
  
file_path: distributed/distributed/protocol/utils.py
imports: from __future__ import annotations
  import ctypes
  import struct
  from collections.abc import Collection, Iterable, Sequence
  from typing import Literal, overload
  import dask
  from distributed.utils import nbytes
label_desc: Use image node_id 8 for calling a global function with example usage: merge_memoryviews(mvs) and returns: base_mv, memoryview, mvs, first