// @generated by protoc-gen-roto — do not edit #![allow(unused_imports)] use roto_runtime::{ ProtoAccessor, ProtoBuilder, RepeatedFieldIterator, Result, RotoError, read_varint, }; use std::str; pub struct Tool<'a> { accessor: roto_runtime::ProtoAccessor<'a>, name_offset: Option, version_offset: Option, payload_offset: Option, is_active_offset: Option, exploit_count_offset: Option, } impl<'a> Tool<'a> { pub fn new(data: &'a [u8]) -> roto_runtime::Result { let accessor = roto_runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut version_offset = None; let mut payload_offset = None; let mut is_active_offset = None; let mut exploit_count_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { name_offset = Some(offset); } if tag.field_number == 2 { version_offset = Some(offset); } if tag.field_number == 3 { payload_offset = Some(offset); } if tag.field_number == 4 { is_active_offset = Some(offset); } if tag.field_number == 5 { exploit_count_offset = Some(offset); } } Ok(Self { accessor, name_offset, version_offset, payload_offset, is_active_offset, exploit_count_offset, }) } pub fn name(&self) -> roto_runtime::Result<&'a str> { let offset = self .name_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| RotoError::WireFormatViolation) } pub fn version(&self) -> roto_runtime::Result<&'a str> { let offset = self .version_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| RotoError::WireFormatViolation) } pub fn payload(&self) -> roto_runtime::Result<&'a [u8]> { let offset = self .payload_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } pub fn is_active(&self) -> roto_runtime::Result { let offset = self .is_active_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v != 0) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn exploit_count(&self) -> roto_runtime::Result { let offset = self .exploit_count_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct ToolBuilder<'b> { builder: roto_runtime::ProtoBuilder<'b>, name_written: bool, version_written: bool, payload_written: bool, is_active_written: bool, exploit_count_written: bool, } impl<'b> ToolBuilder<'b> { pub fn builder(buf: &mut [u8]) -> ToolBuilder<'_> { ToolBuilder { builder: roto_runtime::ProtoBuilder::new(buf), name_written: false, version_written: false, payload_written: false, is_active_written: false, exploit_count_written: false, } } pub fn name(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } pub fn version(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(2, value)?; self.version_written = true; Ok(self) } pub fn payload(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(3, value)?; self.payload_written = true; Ok(self) } pub fn is_active(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(4, value)?; self.is_active_written = true; Ok(self) } pub fn exploit_count(mut self, value: i32) -> roto_runtime::Result { self.builder.write_int32(5, value)?; self.exploit_count_written = true; Ok(self) } pub fn with(mut self, msg: &Tool<'_>) -> roto_runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { 1 => self.name_written, 2 => self.version_written, 3 => self.payload_written, 4 => self.is_active_written, 5 => self.exploit_count_written, _ => false, }; if !is_written { self.builder.write_raw(raw_bytes)?; } } Ok(self) } pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { self.builder.finish() } } pub struct Connection<'a> { accessor: roto_runtime::ProtoAccessor<'a>, host_offset: Option, port_offset: Option, encrypted_offset: Option, bandwidth_bps_offset: Option, session_key_offset: Option, } impl<'a> Connection<'a> { pub fn new(data: &'a [u8]) -> roto_runtime::Result { let accessor = roto_runtime::ProtoAccessor::new(data)?; let mut host_offset = None; let mut port_offset = None; let mut encrypted_offset = None; let mut bandwidth_bps_offset = None; let mut session_key_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { host_offset = Some(offset); } if tag.field_number == 2 { port_offset = Some(offset); } if tag.field_number == 3 { encrypted_offset = Some(offset); } if tag.field_number == 4 { bandwidth_bps_offset = Some(offset); } if tag.field_number == 5 { session_key_offset = Some(offset); } } Ok(Self { accessor, host_offset, port_offset, encrypted_offset, bandwidth_bps_offset, session_key_offset, }) } pub fn host(&self) -> roto_runtime::Result<&'a str> { let offset = self .host_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| RotoError::WireFormatViolation) } pub fn port(&self) -> roto_runtime::Result { let offset = self .port_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn encrypted(&self) -> roto_runtime::Result { let offset = self .encrypted_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v != 0) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn bandwidth_bps(&self) -> roto_runtime::Result { let offset = self .bandwidth_bps_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn session_key(&self) -> roto_runtime::Result<&'a [u8]> { let offset = self .session_key_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct ConnectionBuilder<'b> { builder: roto_runtime::ProtoBuilder<'b>, host_written: bool, port_written: bool, encrypted_written: bool, bandwidth_bps_written: bool, session_key_written: bool, } impl<'b> ConnectionBuilder<'b> { pub fn builder(buf: &mut [u8]) -> ConnectionBuilder<'_> { ConnectionBuilder { builder: roto_runtime::ProtoBuilder::new(buf), host_written: false, port_written: false, encrypted_written: false, bandwidth_bps_written: false, session_key_written: false, } } pub fn host(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(1, value)?; self.host_written = true; Ok(self) } pub fn port(mut self, value: i32) -> roto_runtime::Result { self.builder.write_int32(2, value)?; self.port_written = true; Ok(self) } pub fn encrypted(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(3, value)?; self.encrypted_written = true; Ok(self) } pub fn bandwidth_bps(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(4, value)?; self.bandwidth_bps_written = true; Ok(self) } pub fn session_key(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(5, value)?; self.session_key_written = true; Ok(self) } pub fn with(mut self, msg: &Connection<'_>) -> roto_runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { 1 => self.host_written, 2 => self.port_written, 3 => self.encrypted_written, 4 => self.bandwidth_bps_written, 5 => self.session_key_written, _ => false, }; if !is_written { self.builder.write_raw(raw_bytes)?; } } Ok(self) } pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { self.builder.finish() } } pub struct Hacker<'a> { accessor: roto_runtime::ProtoAccessor<'a>, handle_offset: Option, real_name_offset: Option, age_offset: Option, skill_level_offset: Option, is_elite_offset: Option, crew_id_offset: Option, exploits_start: Option, exploits_end: Option, tools_start: Option, tools_end: Option, active_connection_offset: Option, } impl<'a> Hacker<'a> { pub fn new(data: &'a [u8]) -> roto_runtime::Result { let accessor = roto_runtime::ProtoAccessor::new(data)?; let mut handle_offset = None; let mut real_name_offset = None; let mut age_offset = None; let mut skill_level_offset = None; let mut is_elite_offset = None; let mut crew_id_offset = None; let mut exploits_start = None; let mut exploits_end = None; let mut tools_start = None; let mut tools_end = None; let mut active_connection_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { handle_offset = Some(offset); } if tag.field_number == 2 { real_name_offset = Some(offset); } if tag.field_number == 3 { age_offset = Some(offset); } if tag.field_number == 4 { skill_level_offset = Some(offset); } if tag.field_number == 5 { is_elite_offset = Some(offset); } if tag.field_number == 6 { crew_id_offset = Some(offset); } if tag.field_number == 7 { if exploits_start.is_none() { exploits_start = Some(offset); } exploits_end = Some(offset); } if tag.field_number == 8 { if tools_start.is_none() { tools_start = Some(offset); } tools_end = Some(offset); } if tag.field_number == 9 { active_connection_offset = Some(offset); } } Ok(Self { accessor, handle_offset, real_name_offset, age_offset, skill_level_offset, is_elite_offset, crew_id_offset, exploits_start, exploits_end, tools_start, tools_end, active_connection_offset, }) } pub fn handle(&self) -> roto_runtime::Result<&'a str> { let offset = self .handle_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| RotoError::WireFormatViolation) } pub fn real_name(&self) -> roto_runtime::Result<&'a str> { let offset = self .real_name_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| RotoError::WireFormatViolation) } pub fn age(&self) -> roto_runtime::Result { let offset = self .age_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn skill_level(&self) -> roto_runtime::Result { let offset = self .skill_level_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(f32::from_le_bytes( bytes .try_into() .map_err(|_| RotoError::WireFormatViolation)?, )) } pub fn is_elite(&self) -> roto_runtime::Result { let offset = self .is_elite_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v != 0) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn crew_id(&self) -> roto_runtime::Result { let offset = self .crew_id_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn exploits(&self) -> roto_runtime::RepeatedFieldIterator<'a> { match (self.exploits_start, self.exploits_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(7, start, end), _ => self.accessor.iter_repeated(7), } } pub fn tools(&self) -> roto_runtime::RepeatedFieldIterator<'a> { match (self.tools_start, self.tools_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(8, start, end), _ => self.accessor.iter_repeated(8), } } pub fn active_connection(&self) -> roto_runtime::Result<&'a [u8]> { let offset = self .active_connection_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct HackerBuilder<'b> { builder: roto_runtime::ProtoBuilder<'b>, handle_written: bool, real_name_written: bool, age_written: bool, skill_level_written: bool, is_elite_written: bool, crew_id_written: bool, exploits_written: bool, tools_written: bool, active_connection_written: bool, } impl<'b> HackerBuilder<'b> { pub fn builder(buf: &mut [u8]) -> HackerBuilder<'_> { HackerBuilder { builder: roto_runtime::ProtoBuilder::new(buf), handle_written: false, real_name_written: false, age_written: false, skill_level_written: false, is_elite_written: false, crew_id_written: false, exploits_written: false, tools_written: false, active_connection_written: false, } } pub fn handle(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(1, value)?; self.handle_written = true; Ok(self) } pub fn real_name(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(2, value)?; self.real_name_written = true; Ok(self) } pub fn age(mut self, value: i32) -> roto_runtime::Result { self.builder.write_int32(3, value)?; self.age_written = true; Ok(self) } pub fn skill_level(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(4, value)?; self.skill_level_written = true; Ok(self) } pub fn is_elite(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(5, value)?; self.is_elite_written = true; Ok(self) } pub fn crew_id(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(6, value)?; self.crew_id_written = true; Ok(self) } pub fn exploits(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(7, value)?; self.exploits_written = true; Ok(self) } pub fn tools(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(8, value)?; self.tools_written = true; Ok(self) } pub fn active_connection(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(9, value)?; self.active_connection_written = true; Ok(self) } pub fn with(mut self, msg: &Hacker<'_>) -> roto_runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { 1 => self.handle_written, 2 => self.real_name_written, 3 => self.age_written, 4 => self.skill_level_written, 5 => self.is_elite_written, 6 => self.crew_id_written, 7 => self.exploits_written, 8 => self.tools_written, 9 => self.active_connection_written, _ => false, }; if !is_written { self.builder.write_raw(raw_bytes)?; } } Ok(self) } pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { self.builder.finish() } } pub struct Worm<'a> { accessor: roto_runtime::ProtoAccessor<'a>, name_offset: Option, variant_offset: Option, size_bytes_offset: Option, payload_offset: Option, polymorphic_offset: Option, targets_start: Option, targets_end: Option, } impl<'a> Worm<'a> { pub fn new(data: &'a [u8]) -> roto_runtime::Result { let accessor = roto_runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut variant_offset = None; let mut size_bytes_offset = None; let mut payload_offset = None; let mut polymorphic_offset = None; let mut targets_start = None; let mut targets_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { name_offset = Some(offset); } if tag.field_number == 2 { variant_offset = Some(offset); } if tag.field_number == 3 { size_bytes_offset = Some(offset); } if tag.field_number == 4 { payload_offset = Some(offset); } if tag.field_number == 5 { polymorphic_offset = Some(offset); } if tag.field_number == 6 { if targets_start.is_none() { targets_start = Some(offset); } targets_end = Some(offset); } } Ok(Self { accessor, name_offset, variant_offset, size_bytes_offset, payload_offset, polymorphic_offset, targets_start, targets_end, }) } pub fn name(&self) -> roto_runtime::Result<&'a str> { let offset = self .name_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| RotoError::WireFormatViolation) } pub fn variant(&self) -> roto_runtime::Result { let offset = self .variant_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn size_bytes(&self) -> roto_runtime::Result { let offset = self .size_bytes_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn payload(&self) -> roto_runtime::Result<&'a [u8]> { let offset = self .payload_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } pub fn polymorphic(&self) -> roto_runtime::Result { let offset = self .polymorphic_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v != 0) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn targets(&self) -> roto_runtime::RepeatedFieldIterator<'a> { match (self.targets_start, self.targets_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(6, start, end), _ => self.accessor.iter_repeated(6), } } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct WormBuilder<'b> { builder: roto_runtime::ProtoBuilder<'b>, name_written: bool, variant_written: bool, size_bytes_written: bool, payload_written: bool, polymorphic_written: bool, targets_written: bool, } impl<'b> WormBuilder<'b> { pub fn builder(buf: &mut [u8]) -> WormBuilder<'_> { WormBuilder { builder: roto_runtime::ProtoBuilder::new(buf), name_written: false, variant_written: false, size_bytes_written: false, payload_written: false, polymorphic_written: false, targets_written: false, } } pub fn name(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } pub fn variant(mut self, value: i32) -> roto_runtime::Result { self.builder.write_int32(2, value)?; self.variant_written = true; Ok(self) } pub fn size_bytes(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(3, value)?; self.size_bytes_written = true; Ok(self) } pub fn payload(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(4, value)?; self.payload_written = true; Ok(self) } pub fn polymorphic(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(5, value)?; self.polymorphic_written = true; Ok(self) } pub fn targets(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(6, value)?; self.targets_written = true; Ok(self) } pub fn with(mut self, msg: &Worm<'_>) -> roto_runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { 1 => self.name_written, 2 => self.variant_written, 3 => self.size_bytes_written, 4 => self.payload_written, 5 => self.polymorphic_written, 6 => self.targets_written, _ => false, }; if !is_written { self.builder.write_raw(raw_bytes)?; } } Ok(self) } pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { self.builder.finish() } } pub struct Operation<'a> { accessor: roto_runtime::ProtoAccessor<'a>, codename_offset: Option, target_corp_offset: Option, timestamp_offset: Option, successful_offset: Option, stolen_data_offset: Option, crew_start: Option, crew_end: Option, worm_offset: Option, log_entries_start: Option, log_entries_end: Option, severity_offset: Option, } impl<'a> Operation<'a> { pub fn new(data: &'a [u8]) -> roto_runtime::Result { let accessor = roto_runtime::ProtoAccessor::new(data)?; let mut codename_offset = None; let mut target_corp_offset = None; let mut timestamp_offset = None; let mut successful_offset = None; let mut stolen_data_offset = None; let mut crew_start = None; let mut crew_end = None; let mut worm_offset = None; let mut log_entries_start = None; let mut log_entries_end = None; let mut severity_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { codename_offset = Some(offset); } if tag.field_number == 2 { target_corp_offset = Some(offset); } if tag.field_number == 3 { timestamp_offset = Some(offset); } if tag.field_number == 4 { successful_offset = Some(offset); } if tag.field_number == 5 { stolen_data_offset = Some(offset); } if tag.field_number == 6 { if crew_start.is_none() { crew_start = Some(offset); } crew_end = Some(offset); } if tag.field_number == 7 { worm_offset = Some(offset); } if tag.field_number == 8 { if log_entries_start.is_none() { log_entries_start = Some(offset); } log_entries_end = Some(offset); } if tag.field_number == 9 { severity_offset = Some(offset); } } Ok(Self { accessor, codename_offset, target_corp_offset, timestamp_offset, successful_offset, stolen_data_offset, crew_start, crew_end, worm_offset, log_entries_start, log_entries_end, severity_offset, }) } pub fn codename(&self) -> roto_runtime::Result<&'a str> { let offset = self .codename_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| RotoError::WireFormatViolation) } pub fn target_corp(&self) -> roto_runtime::Result<&'a str> { let offset = self .target_corp_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| RotoError::WireFormatViolation) } pub fn timestamp(&self) -> roto_runtime::Result { let offset = self .timestamp_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn successful(&self) -> roto_runtime::Result { let offset = self .successful_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v != 0) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn stolen_data(&self) -> roto_runtime::Result<&'a [u8]> { let offset = self .stolen_data_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } pub fn crew(&self) -> roto_runtime::RepeatedFieldIterator<'a> { match (self.crew_start, self.crew_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(6, start, end), _ => self.accessor.iter_repeated(6), } } pub fn worm(&self) -> roto_runtime::Result<&'a [u8]> { let offset = self .worm_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } pub fn log_entries(&self) -> roto_runtime::RepeatedFieldIterator<'a> { match (self.log_entries_start, self.log_entries_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(8, start, end), _ => self.accessor.iter_repeated(8), } } pub fn severity(&self) -> roto_runtime::Result { let offset = self .severity_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct OperationBuilder<'b> { builder: roto_runtime::ProtoBuilder<'b>, codename_written: bool, target_corp_written: bool, timestamp_written: bool, successful_written: bool, stolen_data_written: bool, crew_written: bool, worm_written: bool, log_entries_written: bool, severity_written: bool, } impl<'b> OperationBuilder<'b> { pub fn builder(buf: &mut [u8]) -> OperationBuilder<'_> { OperationBuilder { builder: roto_runtime::ProtoBuilder::new(buf), codename_written: false, target_corp_written: false, timestamp_written: false, successful_written: false, stolen_data_written: false, crew_written: false, worm_written: false, log_entries_written: false, severity_written: false, } } pub fn codename(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(1, value)?; self.codename_written = true; Ok(self) } pub fn target_corp(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(2, value)?; self.target_corp_written = true; Ok(self) } pub fn timestamp(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(3, value)?; self.timestamp_written = true; Ok(self) } pub fn successful(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(4, value)?; self.successful_written = true; Ok(self) } pub fn stolen_data(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(5, value)?; self.stolen_data_written = true; Ok(self) } pub fn crew(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(6, value)?; self.crew_written = true; Ok(self) } pub fn worm(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(7, value)?; self.worm_written = true; Ok(self) } pub fn log_entries(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(8, value)?; self.log_entries_written = true; Ok(self) } pub fn severity(mut self, value: i32) -> roto_runtime::Result { self.builder.write_int32(9, value)?; self.severity_written = true; Ok(self) } pub fn with(mut self, msg: &Operation<'_>) -> roto_runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { 1 => self.codename_written, 2 => self.target_corp_written, 3 => self.timestamp_written, 4 => self.successful_written, 5 => self.stolen_data_written, 6 => self.crew_written, 7 => self.worm_written, 8 => self.log_entries_written, 9 => self.severity_written, _ => false, }; if !is_written { self.builder.write_raw(raw_bytes)?; } } Ok(self) } pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { self.builder.finish() } } pub struct Campaign<'a> { accessor: roto_runtime::ProtoAccessor<'a>, name_offset: Option, operations_start: Option, operations_end: Option, total_bytes_stolen_offset: Option, } impl<'a> Campaign<'a> { pub fn new(data: &'a [u8]) -> roto_runtime::Result { let accessor = roto_runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut operations_start = None; let mut operations_end = None; let mut total_bytes_stolen_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { name_offset = Some(offset); } if tag.field_number == 2 { if operations_start.is_none() { operations_start = Some(offset); } operations_end = Some(offset); } if tag.field_number == 3 { total_bytes_stolen_offset = Some(offset); } } Ok(Self { accessor, name_offset, operations_start, operations_end, total_bytes_stolen_offset, }) } pub fn name(&self) -> roto_runtime::Result<&'a str> { let offset = self .name_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| RotoError::WireFormatViolation) } pub fn operations(&self) -> roto_runtime::RepeatedFieldIterator<'a> { match (self.operations_start, self.operations_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(2, start, end), _ => self.accessor.iter_repeated(2), } } pub fn total_bytes_stolen(&self) -> roto_runtime::Result { let offset = self .total_bytes_stolen_offset .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; roto_runtime::read_varint(bytes) .map(|(v, _)| v as i32) .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct CampaignBuilder<'b> { builder: roto_runtime::ProtoBuilder<'b>, name_written: bool, operations_written: bool, total_bytes_stolen_written: bool, } impl<'b> CampaignBuilder<'b> { pub fn builder(buf: &mut [u8]) -> CampaignBuilder<'_> { CampaignBuilder { builder: roto_runtime::ProtoBuilder::new(buf), name_written: false, operations_written: false, total_bytes_stolen_written: false, } } pub fn name(mut self, value: &str) -> roto_runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } pub fn operations(mut self, value: &[u8]) -> roto_runtime::Result { self.builder.write_bytes(2, value)?; self.operations_written = true; Ok(self) } pub fn total_bytes_stolen(mut self, value: u64) -> roto_runtime::Result { self.builder.write_varint(3, value)?; self.total_bytes_stolen_written = true; Ok(self) } pub fn with(mut self, msg: &Campaign<'_>) -> roto_runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { 1 => self.name_written, 2 => self.operations_written, 3 => self.total_bytes_stolen_written, _ => false, }; if !is_written { self.builder.write_raw(raw_bytes)?; } } Ok(self) } pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { self.builder.finish() } }