aedat 1.3.3

A fast AEDAT4 Rust implementation. Forked from https://github.com/neuromorphicsystems/aedat, a Rust AEDAT4 decoder for Python projects.
Documentation
// automatically generated by the FlatBuffers compiler, do not modify

use std::cmp::Ordering;
use std::mem;

extern crate flatbuffers;
use self::flatbuffers::{EndianScalar, Follow};

// struct Event, aligned to 8
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq)]
pub struct Event(pub [u8; 16]);
impl Default for Event {
    fn default() -> Self {
        Self([0; 16])
    }
}
impl std::fmt::Debug for Event {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.debug_struct("Event")
            .field("t", &self.t())
            .field("x", &self.x())
            .field("y", &self.y())
            .field("on", &self.on())
            .finish()
    }
}

impl flatbuffers::SimpleToVerifyInSlice for Event {}
impl flatbuffers::SafeSliceAccess for Event {}
impl<'a> flatbuffers::Follow<'a> for Event {
    type Inner = &'a Event;
    #[inline]
    fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
        <&'a Event>::follow(buf, loc)
    }
}
impl<'a> flatbuffers::Follow<'a> for &'a Event {
    type Inner = &'a Event;
    #[inline]
    fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
        flatbuffers::follow_cast_ref::<Event>(buf, loc)
    }
}
impl<'b> flatbuffers::Push for Event {
    type Output = Event;
    #[inline]
    fn push(&self, dst: &mut [u8], _rest: &[u8]) {
        let src = unsafe {
            ::std::slice::from_raw_parts(self as *const Event as *const u8, Self::size())
        };
        dst.copy_from_slice(src);
    }
}
impl<'b> flatbuffers::Push for &'b Event {
    type Output = Event;

    #[inline]
    fn push(&self, dst: &mut [u8], _rest: &[u8]) {
        let src = unsafe {
            ::std::slice::from_raw_parts(*self as *const Event as *const u8, Self::size())
        };
        dst.copy_from_slice(src);
    }
}

impl<'a> flatbuffers::Verifiable for Event {
    #[inline]
    fn run_verifier(
        v: &mut flatbuffers::Verifier,
        pos: usize,
    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
        use self::flatbuffers::Verifiable;
        v.in_buffer::<Self>(pos)
    }
}
impl<'a> Event {
    #[allow(clippy::too_many_arguments)]
    pub fn new(t: i64, x: i16, y: i16, on: bool) -> Self {
        let mut s = Self([0; 16]);
        s.set_t(t);
        s.set_x(x);
        s.set_y(y);
        s.set_on(on);
        s
    }

    pub fn t(&self) -> i64 {
        let mut mem = core::mem::MaybeUninit::<i64>::uninit();
        unsafe {
            core::ptr::copy_nonoverlapping(
                self.0[0..].as_ptr(),
                mem.as_mut_ptr() as *mut u8,
                core::mem::size_of::<i64>(),
            );
            mem.assume_init()
        }
        .from_little_endian()
    }

    pub fn set_t(&mut self, x: i64) {
        let x_le = x.to_little_endian();
        unsafe {
            core::ptr::copy_nonoverlapping(
                &x_le as *const i64 as *const u8,
                self.0[0..].as_mut_ptr(),
                core::mem::size_of::<i64>(),
            );
        }
    }

    pub fn x(&self) -> i16 {
        let mut mem = core::mem::MaybeUninit::<i16>::uninit();
        unsafe {
            core::ptr::copy_nonoverlapping(
                self.0[8..].as_ptr(),
                mem.as_mut_ptr() as *mut u8,
                core::mem::size_of::<i16>(),
            );
            mem.assume_init()
        }
        .from_little_endian()
    }

    pub fn set_x(&mut self, x: i16) {
        let x_le = x.to_little_endian();
        unsafe {
            core::ptr::copy_nonoverlapping(
                &x_le as *const i16 as *const u8,
                self.0[8..].as_mut_ptr(),
                core::mem::size_of::<i16>(),
            );
        }
    }

    pub fn y(&self) -> i16 {
        let mut mem = core::mem::MaybeUninit::<i16>::uninit();
        unsafe {
            core::ptr::copy_nonoverlapping(
                self.0[10..].as_ptr(),
                mem.as_mut_ptr() as *mut u8,
                core::mem::size_of::<i16>(),
            );
            mem.assume_init()
        }
        .from_little_endian()
    }

    pub fn set_y(&mut self, x: i16) {
        let x_le = x.to_little_endian();
        unsafe {
            core::ptr::copy_nonoverlapping(
                &x_le as *const i16 as *const u8,
                self.0[10..].as_mut_ptr(),
                core::mem::size_of::<i16>(),
            );
        }
    }

    pub fn on(&self) -> bool {
        let mut mem = core::mem::MaybeUninit::<bool>::uninit();
        unsafe {
            core::ptr::copy_nonoverlapping(
                self.0[12..].as_ptr(),
                mem.as_mut_ptr() as *mut u8,
                core::mem::size_of::<bool>(),
            );
            mem.assume_init()
        }
        .from_little_endian()
    }

    pub fn set_on(&mut self, x: bool) {
        let x_le = x.to_little_endian();
        unsafe {
            core::ptr::copy_nonoverlapping(
                &x_le as *const bool as *const u8,
                self.0[12..].as_mut_ptr(),
                core::mem::size_of::<bool>(),
            );
        }
    }
}

pub enum EventPacketOffset {}
#[derive(Copy, Clone, PartialEq)]

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

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

impl<'a> EventPacket<'a> {
    #[inline]
    pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
        EventPacket { _tab: table }
    }
    #[allow(unused_mut)]
    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
        args: &'args EventPacketArgs<'args>,
    ) -> flatbuffers::WIPOffset<EventPacket<'bldr>> {
        let mut builder = EventPacketBuilder::new(_fbb);
        if let Some(x) = args.elements {
            builder.add_elements(x);
        }
        builder.finish()
    }

    pub const VT_ELEMENTS: flatbuffers::VOffsetT = 4;

    #[inline]
    pub fn elements(&self) -> Option<&'a [Event]> {
        self._tab
            .get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Event>>>(
                EventPacket::VT_ELEMENTS,
                None,
            )
            .map(|v| v.safe_slice())
    }
}

impl flatbuffers::Verifiable for EventPacket<'_> {
    #[inline]
    fn run_verifier(
        v: &mut flatbuffers::Verifier,
        pos: usize,
    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
        use self::flatbuffers::Verifiable;
        v.visit_table(pos)?
            .visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, Event>>>(
                &"elements",
                Self::VT_ELEMENTS,
                false,
            )?
            .finish();
        Ok(())
    }
}
pub struct EventPacketArgs<'a> {
    pub elements: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, Event>>>,
}
impl<'a> Default for EventPacketArgs<'a> {
    #[inline]
    fn default() -> Self {
        EventPacketArgs { elements: None }
    }
}
pub struct EventPacketBuilder<'a: 'b, 'b> {
    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
}
impl<'a: 'b, 'b> EventPacketBuilder<'a, 'b> {
    #[inline]
    pub fn add_elements(
        &mut self,
        elements: flatbuffers::WIPOffset<flatbuffers::Vector<'b, Event>>,
    ) {
        self.fbb_
            .push_slot_always::<flatbuffers::WIPOffset<_>>(EventPacket::VT_ELEMENTS, elements);
    }
    #[inline]
    pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> EventPacketBuilder<'a, 'b> {
        let start = _fbb.start_table();
        EventPacketBuilder {
            fbb_: _fbb,
            start_: start,
        }
    }
    #[inline]
    pub fn finish(self) -> flatbuffers::WIPOffset<EventPacket<'a>> {
        let o = self.fbb_.end_table(self.start_);
        flatbuffers::WIPOffset::new(o.value())
    }
}

impl std::fmt::Debug for EventPacket<'_> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let mut ds = f.debug_struct("EventPacket");
        ds.field("elements", &self.elements());
        ds.finish()
    }
}
#[inline]
#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")]
pub fn get_root_as_event_packet<'a>(buf: &'a [u8]) -> EventPacket<'a> {
    unsafe { flatbuffers::root_unchecked::<EventPacket<'a>>(buf) }
}

#[inline]
#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")]
pub fn get_size_prefixed_root_as_event_packet<'a>(buf: &'a [u8]) -> EventPacket<'a> {
    unsafe { flatbuffers::size_prefixed_root_unchecked::<EventPacket<'a>>(buf) }
}

#[inline]
/// Verifies that a buffer of bytes contains a `EventPacket`
/// 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_event_packet_unchecked`.
pub fn root_as_event_packet(buf: &[u8]) -> Result<EventPacket, flatbuffers::InvalidFlatbuffer> {
    flatbuffers::root::<EventPacket>(buf)
}
#[inline]
/// Verifies that a buffer of bytes contains a size prefixed
/// `EventPacket` 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_event_packet_unchecked`.
pub fn size_prefixed_root_as_event_packet(
    buf: &[u8],
) -> Result<EventPacket, flatbuffers::InvalidFlatbuffer> {
    flatbuffers::size_prefixed_root::<EventPacket>(buf)
}
#[inline]
/// Verifies, with the given options, that a buffer of bytes
/// contains a `EventPacket` 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_event_packet_unchecked`.
pub fn root_as_event_packet_with_opts<'b, 'o>(
    opts: &'o flatbuffers::VerifierOptions,
    buf: &'b [u8],
) -> Result<EventPacket<'b>, flatbuffers::InvalidFlatbuffer> {
    flatbuffers::root_with_opts::<EventPacket<'b>>(opts, buf)
}
#[inline]
/// Verifies, with the given verifier options, that a buffer of
/// bytes contains a size prefixed `EventPacket` 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_event_packet_unchecked`.
pub fn size_prefixed_root_as_event_packet_with_opts<'b, 'o>(
    opts: &'o flatbuffers::VerifierOptions,
    buf: &'b [u8],
) -> Result<EventPacket<'b>, flatbuffers::InvalidFlatbuffer> {
    flatbuffers::size_prefixed_root_with_opts::<EventPacket<'b>>(opts, buf)
}
#[inline]
/// Assumes, without verification, that a buffer of bytes contains a EventPacket and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid `EventPacket`.
pub unsafe fn root_as_event_packet_unchecked(buf: &[u8]) -> EventPacket {
    flatbuffers::root_unchecked::<EventPacket>(buf)
}
#[inline]
/// Assumes, without verification, that a buffer of bytes contains a size prefixed EventPacket and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid size prefixed `EventPacket`.
pub unsafe fn size_prefixed_root_as_event_packet_unchecked(buf: &[u8]) -> EventPacket {
    flatbuffers::size_prefixed_root_unchecked::<EventPacket>(buf)
}
pub const EVENT_PACKET_IDENTIFIER: &str = "EVTS";

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

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

#[inline]
pub fn finish_event_packet_buffer<'a, 'b>(
    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
    root: flatbuffers::WIPOffset<EventPacket<'a>>,
) {
    fbb.finish(root, Some(EVENT_PACKET_IDENTIFIER));
}

#[inline]
pub fn finish_size_prefixed_event_packet_buffer<'a, 'b>(
    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
    root: flatbuffers::WIPOffset<EventPacket<'a>>,
) {
    fbb.finish_size_prefixed(root, Some(EVENT_PACKET_IDENTIFIER));
}