code: def encode(data: Any) -> bytes:
      """Сonverts data to the socket server input formatted bytes array.
  
      Serializes ``data`` to the JSON formatted bytes array and adds 4 bytes to the beginning of the array - packed
      to bytes length of the JSON formatted bytes array. Header format is "<I"
      (see https://docs.python.org/3/library/struct.html#struct-format-strings)
  
      Args:
          data: Object to pact to the bytes array.
  
      Raises:
          TypeError: If data is not JSON-serializable object.
  
      Examples:
          >>> from deeppavlov.utils.socket import encode
          >>> encode({'a':1})
          b'\x08\x00\x00\x00{"a": 1}
          >>> encode([42])
          b'\x04\x00\x00\x00[42]'
  
      """
      json_data = jsonify_data(data)
      bytes_data = json.dumps(json_data).encode()
      response = pack(HEADER_FORMAT, len(bytes_data)) + bytes_data
      return response
  
file_path: DeepPavlov/deeppavlov/utils/socket/socket.py
imports: import asyncio
  import json
  from logging import getLogger
  from pathlib import Path
  from struct import pack, unpack
  from typing import Any, List, Optional, Tuple, Union
  from deeppavlov.core.commands.infer import build_model
  from deeppavlov.core.common.chainer import Chainer
  from deeppavlov.core.data.utils import jsonify_data
  from deeppavlov.utils.connector import DialogLogger
  from deeppavlov.utils.server import get_server_params
label_desc: Use image node_id 1 for calling a global function with example usage: encode(data) and returns: response