selium-switchboard-protocol 0.4.3

Selium module for abstracting channel management and messaging patterns
Documentation
// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
use super::*;
pub enum SwitchboardMessageOffset {}
#[derive(Copy, Clone, PartialEq)]

pub struct SwitchboardMessage<'a> {
  pub _tab: ::flatbuffers::Table<'a>,
}

impl<'a> ::flatbuffers::Follow<'a> for SwitchboardMessage<'a> {
  type Inner = SwitchboardMessage<'a>;
  #[inline]
  unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
    Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } }
  }
}

impl<'a> SwitchboardMessage<'a> {
  pub const VT_REQUEST_ID: ::flatbuffers::VOffsetT = 4;
  pub const VT_PAYLOAD_TYPE: ::flatbuffers::VOffsetT = 6;
  pub const VT_PAYLOAD: ::flatbuffers::VOffsetT = 8;

  #[inline]
  pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
    SwitchboardMessage { _tab: table }
  }
  #[allow(unused_mut)]
  pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>(
    _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>,
    args: &'args SwitchboardMessageArgs
  ) -> ::flatbuffers::WIPOffset<SwitchboardMessage<'bldr>> {
    let mut builder = SwitchboardMessageBuilder::new(_fbb);
    builder.add_request_id(args.request_id);
    if let Some(x) = args.payload { builder.add_payload(x); }
    builder.add_payload_type(args.payload_type);
    builder.finish()
  }


  #[inline]
  pub fn request_id(&self) -> u64 {
    // Safety:
    // Created from valid Table for this object
    // which contains a valid value in this slot
    unsafe { self._tab.get::<u64>(SwitchboardMessage::VT_REQUEST_ID, Some(0)).unwrap()}
  }
  #[inline]
  pub fn payload_type(&self) -> SwitchboardPayload {
    // Safety:
    // Created from valid Table for this object
    // which contains a valid value in this slot
    unsafe { self._tab.get::<SwitchboardPayload>(SwitchboardMessage::VT_PAYLOAD_TYPE, Some(SwitchboardPayload::NONE)).unwrap()}
  }
  #[inline]
  pub fn payload(&self) -> Option<::flatbuffers::Table<'a>> {
    // Safety:
    // Created from valid Table for this object
    // which contains a valid value in this slot
    unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(SwitchboardMessage::VT_PAYLOAD, None)}
  }
  #[inline]
  #[allow(non_snake_case)]
  pub fn payload_as_register_request(&self) -> Option<RegisterRequest<'a>> {
    if self.payload_type() == SwitchboardPayload::RegisterRequest {
      self.payload().map(|t| {
       // Safety:
       // Created from a valid Table for this object
       // Which contains a valid union in this slot
       unsafe { RegisterRequest::init_from_table(t) }
     })
    } else {
      None
    }
  }

  #[inline]
  #[allow(non_snake_case)]
  pub fn payload_as_adopt_request(&self) -> Option<AdoptRequest<'a>> {
    if self.payload_type() == SwitchboardPayload::AdoptRequest {
      self.payload().map(|t| {
       // Safety:
       // Created from a valid Table for this object
       // Which contains a valid union in this slot
       unsafe { AdoptRequest::init_from_table(t) }
     })
    } else {
      None
    }
  }

  #[inline]
  #[allow(non_snake_case)]
  pub fn payload_as_connect_request(&self) -> Option<ConnectRequest<'a>> {
    if self.payload_type() == SwitchboardPayload::ConnectRequest {
      self.payload().map(|t| {
       // Safety:
       // Created from a valid Table for this object
       // Which contains a valid union in this slot
       unsafe { ConnectRequest::init_from_table(t) }
     })
    } else {
      None
    }
  }

  #[inline]
  #[allow(non_snake_case)]
  pub fn payload_as_register_response(&self) -> Option<RegisterResponse<'a>> {
    if self.payload_type() == SwitchboardPayload::RegisterResponse {
      self.payload().map(|t| {
       // Safety:
       // Created from a valid Table for this object
       // Which contains a valid union in this slot
       unsafe { RegisterResponse::init_from_table(t) }
     })
    } else {
      None
    }
  }

  #[inline]
  #[allow(non_snake_case)]
  pub fn payload_as_ok_response(&self) -> Option<OkResponse<'a>> {
    if self.payload_type() == SwitchboardPayload::OkResponse {
      self.payload().map(|t| {
       // Safety:
       // Created from a valid Table for this object
       // Which contains a valid union in this slot
       unsafe { OkResponse::init_from_table(t) }
     })
    } else {
      None
    }
  }

  #[inline]
  #[allow(non_snake_case)]
  pub fn payload_as_error_response(&self) -> Option<ErrorResponse<'a>> {
    if self.payload_type() == SwitchboardPayload::ErrorResponse {
      self.payload().map(|t| {
       // Safety:
       // Created from a valid Table for this object
       // Which contains a valid union in this slot
       unsafe { ErrorResponse::init_from_table(t) }
     })
    } else {
      None
    }
  }

  #[inline]
  #[allow(non_snake_case)]
  pub fn payload_as_wiring_update(&self) -> Option<WiringUpdate<'a>> {
    if self.payload_type() == SwitchboardPayload::WiringUpdate {
      self.payload().map(|t| {
       // Safety:
       // Created from a valid Table for this object
       // Which contains a valid union in this slot
       unsafe { WiringUpdate::init_from_table(t) }
     })
    } else {
      None
    }
  }

}

impl ::flatbuffers::Verifiable for SwitchboardMessage<'_> {
  #[inline]
  fn run_verifier(
    v: &mut ::flatbuffers::Verifier, pos: usize
  ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
    v.visit_table(pos)?
     .visit_field::<u64>("request_id", Self::VT_REQUEST_ID, false)?
     .visit_union::<SwitchboardPayload, _>("payload_type", Self::VT_PAYLOAD_TYPE, "payload", Self::VT_PAYLOAD, false, |key, v, pos| {
        match key {
          SwitchboardPayload::RegisterRequest => v.verify_union_variant::<::flatbuffers::ForwardsUOffset<RegisterRequest>>("SwitchboardPayload::RegisterRequest", pos),
          SwitchboardPayload::AdoptRequest => v.verify_union_variant::<::flatbuffers::ForwardsUOffset<AdoptRequest>>("SwitchboardPayload::AdoptRequest", pos),
          SwitchboardPayload::ConnectRequest => v.verify_union_variant::<::flatbuffers::ForwardsUOffset<ConnectRequest>>("SwitchboardPayload::ConnectRequest", pos),
          SwitchboardPayload::RegisterResponse => v.verify_union_variant::<::flatbuffers::ForwardsUOffset<RegisterResponse>>("SwitchboardPayload::RegisterResponse", pos),
          SwitchboardPayload::OkResponse => v.verify_union_variant::<::flatbuffers::ForwardsUOffset<OkResponse>>("SwitchboardPayload::OkResponse", pos),
          SwitchboardPayload::ErrorResponse => v.verify_union_variant::<::flatbuffers::ForwardsUOffset<ErrorResponse>>("SwitchboardPayload::ErrorResponse", pos),
          SwitchboardPayload::WiringUpdate => v.verify_union_variant::<::flatbuffers::ForwardsUOffset<WiringUpdate>>("SwitchboardPayload::WiringUpdate", pos),
          _ => Ok(()),
        }
     })?
     .finish();
    Ok(())
  }
}
pub struct SwitchboardMessageArgs {
    pub request_id: u64,
    pub payload_type: SwitchboardPayload,
    pub payload: Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>>,
}
impl<'a> Default for SwitchboardMessageArgs {
  #[inline]
  fn default() -> Self {
    SwitchboardMessageArgs {
      request_id: 0,
      payload_type: SwitchboardPayload::NONE,
      payload: None,
    }
  }
}

pub struct SwitchboardMessageBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> {
  fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
  start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>,
}
impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> SwitchboardMessageBuilder<'a, 'b, A> {
  #[inline]
  pub fn add_request_id(&mut self, request_id: u64) {
    self.fbb_.push_slot::<u64>(SwitchboardMessage::VT_REQUEST_ID, request_id, 0);
  }
  #[inline]
  pub fn add_payload_type(&mut self, payload_type: SwitchboardPayload) {
    self.fbb_.push_slot::<SwitchboardPayload>(SwitchboardMessage::VT_PAYLOAD_TYPE, payload_type, SwitchboardPayload::NONE);
  }
  #[inline]
  pub fn add_payload(&mut self, payload: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) {
    self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(SwitchboardMessage::VT_PAYLOAD, payload);
  }
  #[inline]
  pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> SwitchboardMessageBuilder<'a, 'b, A> {
    let start = _fbb.start_table();
    SwitchboardMessageBuilder {
      fbb_: _fbb,
      start_: start,
    }
  }
  #[inline]
  pub fn finish(self) -> ::flatbuffers::WIPOffset<SwitchboardMessage<'a>> {
    let o = self.fbb_.end_table(self.start_);
    ::flatbuffers::WIPOffset::new(o.value())
  }
}

impl ::core::fmt::Debug for SwitchboardMessage<'_> {
  fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
    let mut ds = f.debug_struct("SwitchboardMessage");
      ds.field("request_id", &self.request_id());
      ds.field("payload_type", &self.payload_type());
      match self.payload_type() {
        SwitchboardPayload::RegisterRequest => {
          if let Some(x) = self.payload_as_register_request() {
            ds.field("payload", &x)
          } else {
            ds.field("payload", &"InvalidFlatbuffer: Union discriminant does not match value.")
          }
        },
        SwitchboardPayload::AdoptRequest => {
          if let Some(x) = self.payload_as_adopt_request() {
            ds.field("payload", &x)
          } else {
            ds.field("payload", &"InvalidFlatbuffer: Union discriminant does not match value.")
          }
        },
        SwitchboardPayload::ConnectRequest => {
          if let Some(x) = self.payload_as_connect_request() {
            ds.field("payload", &x)
          } else {
            ds.field("payload", &"InvalidFlatbuffer: Union discriminant does not match value.")
          }
        },
        SwitchboardPayload::RegisterResponse => {
          if let Some(x) = self.payload_as_register_response() {
            ds.field("payload", &x)
          } else {
            ds.field("payload", &"InvalidFlatbuffer: Union discriminant does not match value.")
          }
        },
        SwitchboardPayload::OkResponse => {
          if let Some(x) = self.payload_as_ok_response() {
            ds.field("payload", &x)
          } else {
            ds.field("payload", &"InvalidFlatbuffer: Union discriminant does not match value.")
          }
        },
        SwitchboardPayload::ErrorResponse => {
          if let Some(x) = self.payload_as_error_response() {
            ds.field("payload", &x)
          } else {
            ds.field("payload", &"InvalidFlatbuffer: Union discriminant does not match value.")
          }
        },
        SwitchboardPayload::WiringUpdate => {
          if let Some(x) = self.payload_as_wiring_update() {
            ds.field("payload", &x)
          } else {
            ds.field("payload", &"InvalidFlatbuffer: Union discriminant does not match value.")
          }
        },
        _ => {
          let x: Option<()> = None;
          ds.field("payload", &x)
        },
      };
      ds.finish()
  }
}
#[inline]
/// Verifies that a buffer of bytes contains a `SwitchboardMessage`
/// and returns it.
/// Note that verification is still experimental and may not
/// catch every error, or be maximally performant. For the
/// previous, unchecked, behavior use
/// `root_as_switchboard_message_unchecked`.
pub fn root_as_switchboard_message(buf: &[u8]) -> Result<SwitchboardMessage<'_>, ::flatbuffers::InvalidFlatbuffer> {
  ::flatbuffers::root::<SwitchboardMessage>(buf)
}
#[inline]
/// Verifies that a buffer of bytes contains a size prefixed
/// `SwitchboardMessage` and returns it.
/// Note that verification is still experimental and may not
/// catch every error, or be maximally performant. For the
/// previous, unchecked, behavior use
/// `size_prefixed_root_as_switchboard_message_unchecked`.
pub fn size_prefixed_root_as_switchboard_message(buf: &[u8]) -> Result<SwitchboardMessage<'_>, ::flatbuffers::InvalidFlatbuffer> {
  ::flatbuffers::size_prefixed_root::<SwitchboardMessage>(buf)
}
#[inline]
/// Verifies, with the given options, that a buffer of bytes
/// contains a `SwitchboardMessage` and returns it.
/// Note that verification is still experimental and may not
/// catch every error, or be maximally performant. For the
/// previous, unchecked, behavior use
/// `root_as_switchboard_message_unchecked`.
pub fn root_as_switchboard_message_with_opts<'b, 'o>(
  opts: &'o ::flatbuffers::VerifierOptions,
  buf: &'b [u8],
) -> Result<SwitchboardMessage<'b>, ::flatbuffers::InvalidFlatbuffer> {
  ::flatbuffers::root_with_opts::<SwitchboardMessage<'b>>(opts, buf)
}
#[inline]
/// Verifies, with the given verifier options, that a buffer of
/// bytes contains a size prefixed `SwitchboardMessage` and returns
/// it. Note that verification is still experimental and may not
/// catch every error, or be maximally performant. For the
/// previous, unchecked, behavior use
/// `root_as_switchboard_message_unchecked`.
pub fn size_prefixed_root_as_switchboard_message_with_opts<'b, 'o>(
  opts: &'o ::flatbuffers::VerifierOptions,
  buf: &'b [u8],
) -> Result<SwitchboardMessage<'b>, ::flatbuffers::InvalidFlatbuffer> {
  ::flatbuffers::size_prefixed_root_with_opts::<SwitchboardMessage<'b>>(opts, buf)
}
#[inline]
/// Assumes, without verification, that a buffer of bytes contains a SwitchboardMessage and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid `SwitchboardMessage`.
pub unsafe fn root_as_switchboard_message_unchecked(buf: &[u8]) -> SwitchboardMessage<'_> {
  unsafe { ::flatbuffers::root_unchecked::<SwitchboardMessage>(buf) }
}
#[inline]
/// Assumes, without verification, that a buffer of bytes contains a size prefixed SwitchboardMessage and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid size prefixed `SwitchboardMessage`.
pub unsafe fn size_prefixed_root_as_switchboard_message_unchecked(buf: &[u8]) -> SwitchboardMessage<'_> {
  unsafe { ::flatbuffers::size_prefixed_root_unchecked::<SwitchboardMessage>(buf) }
}
pub const SWITCHBOARD_MESSAGE_IDENTIFIER: &str = "SBSW";

#[inline]
pub fn switchboard_message_buffer_has_identifier(buf: &[u8]) -> bool {
  ::flatbuffers::buffer_has_identifier(buf, SWITCHBOARD_MESSAGE_IDENTIFIER, false)
}

#[inline]
pub fn switchboard_message_size_prefixed_buffer_has_identifier(buf: &[u8]) -> bool {
  ::flatbuffers::buffer_has_identifier(buf, SWITCHBOARD_MESSAGE_IDENTIFIER, true)
}

#[inline]
pub fn finish_switchboard_message_buffer<'a, 'b, A: ::flatbuffers::Allocator + 'a>(
    fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
    root: ::flatbuffers::WIPOffset<SwitchboardMessage<'a>>) {
  fbb.finish(root, Some(SWITCHBOARD_MESSAGE_IDENTIFIER));
}

#[inline]
pub fn finish_size_prefixed_switchboard_message_buffer<'a, 'b, A: ::flatbuffers::Allocator + 'a>(fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, root: ::flatbuffers::WIPOffset<SwitchboardMessage<'a>>) {
  fbb.finish_size_prefixed(root, Some(SWITCHBOARD_MESSAGE_IDENTIFIER));
}