/**
 * @license
 * Copyright 2025-2026 Open Home Foundation
 * SPDX-License-Identifier: Apache-2.0
 */
const BLE_PROXY_PROTOCOL_VERSION = 1;
const BleProxyCommand = {
  StartScan: "start_scan",
  StopScan: "stop_scan",
  Connect: "connect",
  Disconnect: "disconnect",
  DiscoverServices: "discover_services",
  DiscoverCharacteristics: "discover_characteristics",
  ReadCharacteristic: "read_characteristic",
  WriteCharacteristic: "write_characteristic",
  SubscribeCharacteristic: "subscribe_characteristic",
  WriteAndSubscribe: "write_and_subscribe",
  UnsubscribeCharacteristic: "unsubscribe_characteristic",
  RequestMtu: "request_mtu"
};
const BleProxyEvent = {
  DeviceDiscovered: "device_discovered",
  Disconnected: "disconnected",
  ScanStopped: "scan_stopped",
  CharacteristicNotification: "characteristic_notification"
};
const BleProxyErrorCode = {
  BluetoothUnavailable: "bluetooth_unavailable",
  AlreadyScanning: "already_scanning",
  NotScanning: "not_scanning",
  DeviceNotFound: "device_not_found",
  ConnectionFailed: "connection_failed",
  AlreadyConnected: "already_connected",
  NotConnected: "not_connected",
  Timeout: "timeout",
  ServiceNotFound: "service_not_found",
  CharacteristicNotFound: "characteristic_not_found",
  ReadFailed: "read_failed",
  WriteFailed: "write_failed",
  SubscribeFailed: "subscribe_failed",
  NotSubscribed: "not_subscribed",
  NotifyNotSupported: "notify_not_supported",
  MtuRequestFailed: "mtu_request_failed",
  DiscoveryFailed: "discovery_failed",
  InternalError: "internal_error"
};
const BinaryFrameOpcode = {
  /** Server -> Client: write payload to the active write characteristic */
  WriteData: 1,
  /** Client -> Server: notification data from a subscribed characteristic */
  Notification: 2,
  /** Client -> Server: response data for a read_characteristic command */
  ReadResponse: 3
};
const BINARY_FRAME_HEADER_SIZE = 3;
function encodeBinaryFrame(opcode, connectionHandle, payload) {
  const frame = new Uint8Array(BINARY_FRAME_HEADER_SIZE + payload.length);
  frame[0] = opcode & 255;
  frame[1] = connectionHandle >> 8 & 255;
  frame[2] = connectionHandle & 255;
  frame.set(payload, BINARY_FRAME_HEADER_SIZE);
  return frame;
}
function decodeBinaryFrame(data) {
  if (data.length < BINARY_FRAME_HEADER_SIZE) {
    throw new Error(`Binary frame too short: ${data.length} bytes, minimum ${BINARY_FRAME_HEADER_SIZE}`);
  }
  return {
    opcode: data[0],
    connectionHandle: data[1] << 8 | data[2],
    payload: data.subarray(BINARY_FRAME_HEADER_SIZE)
  };
}
export {
  BLE_PROXY_PROTOCOL_VERSION,
  BinaryFrameOpcode,
  BleProxyCommand,
  BleProxyErrorCode,
  BleProxyEvent,
  decodeBinaryFrame,
  encodeBinaryFrame
};
//# sourceMappingURL=BleProxyProtocol.js.map
