cst_encode_blue_event method

  1. @protected
JSAny cst_encode_blue_event(
  1. BlueEvent raw
)

Implementation

@protected
JSAny cst_encode_blue_event(BlueEvent raw) {
  // Codec=Cst (C-struct based), see doc to use other codecs
  if (raw is BlueEvent_DeviceDiscovered) {
    return [0, cst_encode_box_autoadd_device_peripheral_id(raw.field0)]
        .jsify()!;
  }
  if (raw is BlueEvent_DeviceUpdated) {
    return [1, cst_encode_box_autoadd_device_peripheral_id(raw.field0)]
        .jsify()!;
  }
  if (raw is BlueEvent_DeviceConnected) {
    return [2, cst_encode_box_autoadd_device_peripheral_id(raw.field0)]
        .jsify()!;
  }
  if (raw is BlueEvent_DeviceDisconnected) {
    return [3, cst_encode_box_autoadd_device_peripheral_id(raw.field0)]
        .jsify()!;
  }
  if (raw is BlueEvent_ManufacturerDataAdvertisement) {
    return [
      4,
      cst_encode_box_autoadd_device_peripheral_id(raw.field0),
      cst_encode_Map_u_16_list_prim_u_8_strict_None(raw.field1)
    ].jsify()!;
  }
  if (raw is BlueEvent_ServiceDataAdvertisement) {
    return [
      5,
      cst_encode_box_autoadd_device_peripheral_id(raw.field0),
      cst_encode_Map_Uuid_list_prim_u_8_strict_None(raw.field1)
    ].jsify()!;
  }
  if (raw is BlueEvent_ServicesAdvertisement) {
    return [
      6,
      cst_encode_box_autoadd_device_peripheral_id(raw.field0),
      cst_encode_list_Uuid(raw.field1)
    ].jsify()!;
  }
  if (raw is BlueEvent_StateUpdate) {
    return [7, cst_encode_b_central_state(raw.field0)].jsify()!;
  }
  if (raw is BlueEvent_ERROR) {
    return [8, cst_encode_String(raw.field0)].jsify()!;
  }

  throw Exception('unreachable');
}