rusteron_code_genConstant CUSTOM_AERON_CODE
Source pub const CUSTOM_AERON_CODE: &str = "// code here is included in all modules and extends generated classes\n\npub const AERON_IPC_STREAM: &\'static str = \"aeron:ipc\";\n\nunsafe impl Send for AeronCountersReader {}\nunsafe impl Send for AeronSubscription {}\nunsafe impl Sync for AeronSubscription {}\nunsafe impl Send for AeronPublication {}\nunsafe impl Sync for AeronPublication {}\nunsafe impl Send for AeronExclusivePublication {}\nunsafe impl Sync for AeronExclusivePublication {}\nunsafe impl Send for AeronCounter {}\nunsafe impl Sync for AeronCounter {}\n\nimpl AeronCounter {\n #[inline]\n pub fn addr_atomic(&self) -> &std::sync::atomic::AtomicI64 {\n unsafe { std::sync::atomic::AtomicI64::from_ptr(self.addr()) }\n }\n}\n\nimpl AeronSubscription {\n pub fn async_add_destination(\n &mut self,\n client: &Aeron,\n destination: &str,\n ) -> Result<AeronAsyncDestination, AeronCError> {\n AeronAsyncDestination::aeron_subscription_async_add_destination(client, self, destination)\n }\n\n pub fn add_destination(\n &mut self,\n client: &Aeron,\n destination: &str,\n timeout: std::time::Duration,\n ) -> Result<(), AeronCError> {\n let result = self.async_add_destination(client, destination)?;\n if result\n .aeron_subscription_async_destination_poll()\n .unwrap_or_default()\n > 0\n {\n return Ok(());\n }\n let time = std::time::Instant::now();\n while time.elapsed() < timeout {\n if result\n .aeron_subscription_async_destination_poll()\n .unwrap_or_default()\n > 0\n {\n return Ok(());\n }\n #[cfg(debug_assertions)]\n std::thread::sleep(std::time::Duration::from_millis(10));\n }\n log::error!(\"failed async poll for {} {:?}\", destination, self);\n Err(AeronErrorType::TimedOut.into())\n }\n}\n\nimpl AeronExclusivePublication {\n pub fn async_add_destination(\n &mut self,\n client: &Aeron,\n destination: &str,\n ) -> Result<AeronAsyncDestination, AeronCError> {\n AeronAsyncDestination::aeron_exclusive_publication_async_add_destination(\n client,\n self,\n destination,\n )\n }\n\n pub fn add_destination(\n &mut self,\n client: &Aeron,\n destination: &str,\n timeout: std::time::Duration,\n ) -> Result<(), AeronCError> {\n let result = self.async_add_destination(client, destination)?;\n if result\n .aeron_subscription_async_destination_poll()\n .unwrap_or_default()\n > 0\n {\n return Ok(());\n }\n let time = std::time::Instant::now();\n while time.elapsed() < timeout {\n if result\n .aeron_subscription_async_destination_poll()\n .unwrap_or_default()\n > 0\n {\n return Ok(());\n }\n #[cfg(debug_assertions)]\n std::thread::sleep(std::time::Duration::from_millis(10));\n }\n log::error!(\"failed async poll for {} {:?}\", destination, self);\n Err(AeronErrorType::TimedOut.into())\n }\n}\n\nimpl AeronPublication {\n pub fn async_add_destination(\n &mut self,\n client: &Aeron,\n destination: &str,\n ) -> Result<AeronAsyncDestination, AeronCError> {\n AeronAsyncDestination::aeron_publication_async_add_destination(client, self, destination)\n }\n\n pub fn add_destination(\n &mut self,\n client: &Aeron,\n destination: &str,\n timeout: std::time::Duration,\n ) -> Result<(), AeronCError> {\n let result = self.async_add_destination(client, destination)?;\n if result\n .aeron_subscription_async_destination_poll()\n .unwrap_or_default()\n > 0\n {\n return Ok(());\n }\n let time = std::time::Instant::now();\n while time.elapsed() < timeout {\n if result\n .aeron_subscription_async_destination_poll()\n .unwrap_or_default()\n > 0\n {\n return Ok(());\n }\n #[cfg(debug_assertions)]\n std::thread::sleep(std::time::Duration::from_millis(10));\n }\n log::error!(\"failed async poll for {} {:?}\", destination, self);\n Err(AeronErrorType::TimedOut.into())\n }\n}\n\nimpl std::str::FromStr for AeronUriStringBuilder {\n type Err = AeronCError;\n\n fn from_str(s: &str) -> Result<Self, Self::Err> {\n let builder = AeronUriStringBuilder::default();\n builder.init_on_string(s)?;\n Ok(builder)\n }\n}\n\nimpl AeronUriStringBuilder {\n #[inline]\n pub fn build(&self, max_str_length: usize) -> Result<String, AeronCError> {\n let mut result = String::with_capacity(max_str_length);\n self.build_into(&mut result)?;\n Ok(result)\n }\n\n pub fn media(&self, value: Media) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_STRING_BUILDER_MEDIA_KEY);\n self.put(key, value.as_str())?;\n Ok(self)\n }\n\n pub fn control_mode(&self, value: ControlMode) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_UDP_CHANNEL_CONTROL_MODE_KEY);\n self.put(key, value.as_str())?;\n Ok(self)\n }\n\n pub fn prefix(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_STRING_BUILDER_PREFIX_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n\n fn strip_null_terminator(bytes: &[u8]) -> &str {\n let len = bytes.len() - 1;\n unsafe { std::str::from_utf8_unchecked(&bytes[..len]) }\n }\n\n pub fn initial_term_id(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_INITIAL_TERM_ID_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn term_id(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_TERM_ID_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn term_offset(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_TERM_OFFSET_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn alias(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_ALIAS_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn term_length(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_TERM_LENGTH_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn linger_timeout(&self, value: i64) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_LINGER_TIMEOUT_KEY);\n self.put_int64(key, value)?;\n Ok(self)\n }\n pub fn mtu_length(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_MTU_LENGTH_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn ttl(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_UDP_CHANNEL_TTL_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn sparse_term(&self, value: bool) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_SPARSE_TERM_KEY);\n self.put(key, if value { \"true\" } else { \"false\" })?;\n Ok(self)\n }\n pub fn reliable(&self, value: bool) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_UDP_CHANNEL_RELIABLE_KEY);\n self.put(key, if value { \"true\" } else { \"false\" })?;\n Ok(self)\n }\n pub fn eos(&self, value: bool) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_EOS_KEY);\n self.put(key, if value { \"true\" } else { \"false\" })?;\n Ok(self)\n }\n pub fn tether(&self, value: bool) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_TETHER_KEY);\n self.put(key, if value { \"true\" } else { \"false\" })?;\n Ok(self)\n }\n pub fn tags(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_TAGS_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn endpoint(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_UDP_CHANNEL_ENDPOINT_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn interface(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_UDP_CHANNEL_INTERFACE_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn control(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_UDP_CHANNEL_CONTROL_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn session_id(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_SESSION_ID_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn group(&self, value: bool) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_GROUP_KEY);\n self.put(key, if value { \"true\" } else { \"false\" })?;\n Ok(self)\n }\n pub fn rejoin(&self, value: bool) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_REJOIN_KEY);\n self.put(key, if value { \"true\" } else { \"false\" })?;\n Ok(self)\n }\n pub fn fc(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_FC_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn gtag(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_GTAG_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn cc(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_CC_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn spies_simulate_connection(&self, value: bool) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_SPIES_SIMULATE_CONNECTION_KEY);\n self.put(key, if value { \"true\" } else { \"false\" })?;\n Ok(self)\n }\n pub fn ats(&self, value: bool) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_ATS_KEY);\n self.put(key, if value { \"true\" } else { \"false\" })?;\n Ok(self)\n }\n pub fn socket_sndbuf(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_SOCKET_SNDBUF_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn socket_rcvbuf(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_SOCKET_RCVBUF_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn receiver_window(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_RECEIVER_WINDOW_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn media_rcv_timestamp_offset(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_MEDIA_RCV_TIMESTAMP_OFFSET_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn channel_rcv_timestamp_offset(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_CHANNEL_RCV_TIMESTAMP_OFFSET_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn channel_snd_timestamp_offset(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_CHANNEL_SND_TIMESTAMP_OFFSET_KEY);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn timestamp_offset_reserved(&self, value: &str) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_TIMESTAMP_OFFSET_RESERVED);\n self.put(key, value)?;\n Ok(self)\n }\n pub fn response_correlation_id(&self, value: i64) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_RESPONSE_CORRELATION_ID_KEY);\n self.put_int64(key, value)?;\n Ok(self)\n }\n pub fn nak_delay(&self, value: i64) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_NAK_DELAY_KEY);\n self.put_int64(key, value)?;\n Ok(self)\n }\n pub fn untethered_window_limit_timeout(&self, value: i64) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_UNTETHERED_WINDOW_LIMIT_TIMEOUT_KEY);\n self.put_int64(key, value)?;\n Ok(self)\n }\n pub fn untethered_resting_timeout(&self, value: i64) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_UNTETHERED_RESTING_TIMEOUT_KEY);\n self.put_int64(key, value)?;\n Ok(self)\n }\n pub fn max_resend(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_MAX_RESEND_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn stream_id(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_STREAM_ID_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n pub fn publication_window(&self, value: i32) -> Result<&Self, AeronCError> {\n let key: &str = Self::strip_null_terminator(AERON_URI_PUBLICATION_WINDOW_KEY);\n self.put_int32(key, value)?;\n Ok(self)\n }\n\n #[inline]\n pub fn build_into(&self, dst: &mut String) -> Result<(), AeronCError> {\n self.sprint_into(dst)?;\n Ok(())\n }\n}\n\nimpl AeronCountersReader {\n #[inline]\n #[doc = \"Get the label for a counter.\"]\n #[doc = \"\"]\n #[doc = \" \\n**param** counters_reader that contains the counter\"]\n #[doc = \" \\n**param** counter_id to find\"]\n #[doc = \" \\n**param** buffer to store the counter in.\"]\n #[doc = \" \\n**param** buffer_length length of the output buffer\"]\n #[doc = \" \\n**return** -1 on failure, number of characters copied to buffer on success.\"]\n pub fn get_counter_label(\n &self,\n counter_id: i32,\n max_length: usize,\n ) -> Result<String, AeronCError> {\n let mut result = String::with_capacity(max_length);\n self.get_counter_label_into(counter_id, &mut result)?;\n Ok(result)\n }\n\n #[inline]\n #[doc = \"Get the label for a counter.\"]\n pub fn get_counter_label_into(\n &self,\n counter_id: i32,\n dst: &mut String,\n ) -> Result<(), AeronCError> {\n unsafe {\n let capacity = dst.capacity();\n let vec = dst.as_mut_vec();\n vec.set_len(capacity);\n self.counter_label(counter_id, vec.as_mut_ptr() as *mut _, capacity)?;\n let mut len = 0;\n loop {\n if len == capacity {\n break;\n }\n let val = vec[len];\n if val == 0 {\n break;\n }\n len += 1;\n }\n vec.set_len(len);\n }\n Ok(())\n }\n\n #[inline]\n #[doc = \"Get the key for a counter.\"]\n pub fn get_counter_key(&self, counter_id: i32) -> Result<Vec<u8>, AeronCError> {\n let mut dst = Vec::new();\n self.get_counter_key_into(counter_id, &mut dst)?;\n Ok(dst)\n }\n\n #[inline]\n #[doc = \"Get the key for a counter.\"]\n pub fn get_counter_key_into(\n &self,\n counter_id: i32,\n dst: &mut Vec<u8>,\n ) -> Result<(), AeronCError> {\n let mut key_ptr: *mut u8 = std::ptr::null_mut();\n unsafe {\n let result = bindings::aeron_counters_reader_metadata_key(\n self.get_inner(),\n counter_id,\n &mut key_ptr,\n );\n if result < 0 || key_ptr.is_null() {\n return Err(AeronCError::from_code(result));\n }\n\n loop {\n let val = *key_ptr.add(dst.len());\n if val == 0 {\n break;\n } else {\n dst.push(val);\n }\n }\n Ok(())\n }\n }\n\n #[inline]\n pub fn get_counter_value(&self, counter_id: i32) -> i64 {\n unsafe { *self.addr(counter_id) }\n }\n}\n\nimpl Aeron {\n pub fn new_blocking(\n context: &AeronContext,\n timeout: std::time::Duration,\n ) -> Result<Self, AeronCError> {\n if let Ok(aeron) = Aeron::new(&context) {\n return Ok(aeron);\n }\n let time = std::time::Instant::now();\n while time.elapsed() < timeout {\n if let Ok(aeron) = Aeron::new(&context) {\n return Ok(aeron);\n }\n #[cfg(debug_assertions)]\n std::thread::sleep(std::time::Duration::from_millis(10));\n }\n log::error!(\"failed to create aeron client for {:?}\", context);\n Err(AeronErrorType::TimedOut.into())\n }\n}\n\nimpl AeronFragmentHandlerCallback for AeronFragmentAssembler {\n fn handle_aeron_fragment_handler(&mut self, buffer: &[u8], header: AeronHeader) -> () {\n unsafe {\n aeron_fragment_assembler_handler(\n self.get_inner() as *mut _,\n buffer.as_ptr(),\n buffer.len(),\n header.get_inner(),\n )\n }\n }\n}\n\nimpl AeronControlledFragmentHandlerCallback for AeronControlledFragmentAssembler {\n fn handle_aeron_controlled_fragment_handler(\n &mut self,\n buffer: &[u8],\n header: AeronHeader,\n ) -> aeron_controlled_fragment_handler_action_t {\n unsafe {\n aeron_controlled_fragment_assembler_handler(\n self.get_inner() as *mut _,\n buffer.as_ptr(),\n buffer.len(),\n header.get_inner(),\n )\n }\n }\n}\n\nimpl<T: AeronFragmentHandlerCallback> Handler<T> {\n pub fn leak_with_fragment_assembler(\n handler: T,\n ) -> Result<(Handler<AeronFragmentAssembler>, Handler<T>), AeronCError> {\n let handler = Handler::leak(handler);\n Ok((\n Handler::leak(AeronFragmentAssembler::new(Some(&handler))?),\n handler,\n ))\n }\n}\nimpl<T: AeronControlledFragmentHandlerCallback> Handler<T> {\n pub fn leak_with_controlled_fragment_assembler(\n handler: T,\n ) -> Result<(Handler<AeronControlledFragmentAssembler>, Handler<T>), AeronCError> {\n let handler = Handler::leak(handler);\n Ok((\n Handler::leak(AeronControlledFragmentAssembler::new(Some(&handler))?),\n handler,\n ))\n }\n}\n\nimpl AeronBufferClaim {\n #[inline]\n pub fn data_mut(&self) -> &mut [u8] {\n debug_assert!(!self.data.is_null());\n unsafe { std::slice::from_raw_parts_mut(self.data, self.length) }\n }\n\n #[inline]\n pub fn frame_header_mut(&self) -> &mut aeron_header_values_frame_t {\n unsafe { &mut *self.frame_header.cast::<aeron_header_values_frame_t>() }\n }\n}\n\npub struct AeronErrorLogger;\nimpl AeronErrorHandlerCallback for AeronErrorLogger {\n fn handle_aeron_error_handler(&mut self, error_code: std::ffi::c_int, msg: &\'static str) -> () {\n log::error!(\"aeron error {}: {}\", error_code, msg);\n }\n}\nunsafe impl Send for AeronErrorLogger {}\nunsafe impl Sync for AeronErrorLogger {}\n";