| 1 | // Copyright (c) 2015 Robert Clipsham <[email protected]> |
| 2 | // Copyright (c) 2021 Pierre Chifflier <[email protected]> |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 5 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 6 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 7 | // option. This file may not be copied, modified, or distributed |
| 8 | // except according to those terms. |
| 9 | |
| 10 | //! Implements the #\[packet\] decorator. |
| 11 | |
| 12 | use craterust-analyzer cargo pnet_macros 0.35.0 crate/::utilrust-analyzer cargo pnet_macros 0.35.0 util/::{ |
| 13 | operationsrust-analyzer cargo pnet_macros 0.35.0 util/operations()., to_little_endianrust-analyzer cargo pnet_macros 0.35.0 util/to_little_endian()., to_mutatorrust-analyzer cargo pnet_macros 0.35.0 util/to_mutator()., Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#, GetOperationrust-analyzer cargo pnet_macros 0.35.0 util/GetOperation#, SetOperationrust-analyzer cargo pnet_macros 0.35.0 util/SetOperation#, |
| 14 | }; |
| 15 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#; |
| 16 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::{Grouprust-analyzer cargo proc-macro2 1.0.107 Group#, Spanrust-analyzer cargo proc-macro2 1.0.107 Span#}; |
| 17 | use quoterust-analyzer cargo quote 1.0.47 crate/::{quoterust-analyzer cargo quote 1.0.47 quote!, ToTokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#}; |
| 18 | use regexrust-analyzer cargo regex 1.13.1 crate/::Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#; |
| 19 | use synrust-analyzer cargo syn 2.0.119 crate/::{spannedrust-analyzer cargo syn 2.0.119 spanned/::Spannedrust-analyzer cargo syn 2.0.119 spanned/Spanned#, Errorrust-analyzer cargo syn 2.0.119 error/Error#}; |
| 20 | |
| 21 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 22 | enum EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified# { |
| 23 | Norust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#No#, |
| 24 | Yesrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#Yes#, |
| 25 | } |
| 26 | |
| 27 | /// Lower and upper bounds of a payload. |
| 28 | /// Represented as strings since they may involve functions. |
| 29 | struct PayloadBoundsrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds# { |
| 30 | lowerrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#lower.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 31 | upperrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#upper.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 32 | } |
| 33 | |
| 34 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 35 | enum Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type# { |
| 36 | /// Any of the `u*` types from `pnet_macros::types::*`. |
| 37 | Primitiverust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Primitive#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, usize, Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#), |
| 38 | /// Any type of the form `Vec<T>`. |
| 39 | Vectorrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Vector#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#>), |
| 40 | /// Any type which isn't a primitive or a vector. |
| 41 | Miscrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Misc#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 42 | } |
| 43 | |
| 44 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 45 | struct Fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/Field# { |
| 46 | namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 47 | spanrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#span.: Spanrust-analyzer cargo proc-macro2 1.0.107 Span#, |
| 48 | tyrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#ty.: Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#, |
| 49 | packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 50 | struct_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#struct_length.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 51 | is_payloadrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#is_payload.: bool, |
| 52 | construct_withrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#construct_with.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#>>, |
| 53 | } |
| 54 | |
| 55 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 56 | pub struct Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet# { |
| 57 | base_namerust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#base_name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 58 | fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#fields.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#>, |
| 59 | } |
| 60 | |
| 61 | impl Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet# { |
| 62 | fn packet_name_mutrust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name_mut().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 63 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Mutable{}Packet", self.base_namerust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#base_name.) |
| 64 | } |
| 65 | fn packet_namerust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 66 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}Packet", self.base_namerust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#base_name.) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | #[inline] |
| 71 | pub fn generate_packetrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet().( |
| 72 | s: &synrust-analyzer cargo syn 2.0.119 crate/::DataStructrust-analyzer cargo syn 2.0.119 derive/DataStruct#, |
| 73 | name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 74 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 75 | let packet = make_packetrust-analyzer cargo pnet_macros 0.35.0 decorator/make_packet().(s, name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 76 | let structs = generate_packet_structrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_struct().(&packet); |
| 77 | let (ts_packet_impls, payload_bounds, packet_size) = generate_packet_implsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_impls().(&packet)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 78 | let ts_size_impls = generate_packet_size_implsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_size_impls().(&packet, &packet_size)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 79 | let ts_trait_impls = generate_packet_trait_implsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_trait_impls().(&packet, &payload_bounds)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 80 | let ts_iterables = generate_iterablesrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_iterables().(&packet)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 81 | let ts_converters = generate_convertersrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_converters().(&packet)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 82 | let ts_debug_impls = generate_debug_implsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_debug_impls().(&packet)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 83 | let tts = quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 84 | #structs |
| 85 | #ts_packet_impls |
| 86 | #ts_size_impls |
| 87 | #ts_trait_impls |
| 88 | #ts_iterables |
| 89 | #ts_converters |
| 90 | #ts_debug_impls |
| 91 | }; |
| 92 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tts) |
| 93 | } |
| 94 | |
| 95 | #[inline] |
| 96 | fn generate_packet_structrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_struct().(packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#) -> proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream# { |
| 97 | let items = &[ |
| 98 | (packet.packet_namerust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name().(), "PacketData"), |
| 99 | (packet.packet_name_mutrust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name_mut().(), "MutPacketData"), |
| 100 | ]; |
| 101 | let tts: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = items |
| 102 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 103 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(name, packet_data)| { |
| 104 | let name = synrust-analyzer cargo syn 2.0.119 crate/::Identrust-analyzer cargo proc-macro2 1.0.107 Ident#::newrust-analyzer cargo proc-macro2 1.0.107 impl#[Ident]new().(&name, Spanrust-analyzer cargo proc-macro2 1.0.107 Span#::call_siterust-analyzer cargo proc-macro2 1.0.107 impl#[Span]call_site().()); |
| 105 | let packet_data = synrust-analyzer cargo syn 2.0.119 crate/::Identrust-analyzer cargo proc-macro2 1.0.107 Ident#::newrust-analyzer cargo proc-macro2 1.0.107 impl#[Ident]new().(packet_data, Spanrust-analyzer cargo proc-macro2 1.0.107 Span#::call_siterust-analyzer cargo proc-macro2 1.0.107 impl#[Span]call_site().()); |
| 106 | quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 107 | #[derive(PartialEq)] |
| 108 | /// A structure enabling manipulation of on the wire packets |
| 109 | pub struct #name<'p> { |
| 110 | packet: ::pnet_macros_support::packet::#packet_data<'p>, |
| 111 | } |
| 112 | } |
| 113 | }) |
| 114 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 115 | quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 116 | #(#tts)* |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | #[inline] |
| 121 | fn make_typerust-analyzer cargo pnet_macros 0.35.0 decorator/make_type().(ty_str: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, endianness_important: bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 122 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((size, endianness, spec)) = parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().(&ty_str[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().) { |
| 123 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().endianness_important || size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().8 || spec rust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[EndiannessSpecified][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[EndiannessSpecified][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[EndiannessSpecified][`PartialEq<Self>`]eq().EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Yesrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#Yes# { |
| 124 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Primitiverust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Primitive#(ty_str, size, endianness)) |
| 125 | } else { |
| 126 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("endianness must be specified for types of size >= 8".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()) |
| 127 | } |
| 128 | } else if ty_str.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("Vec<") { |
| 129 | let ty = make_typerust-analyzer cargo pnet_macros 0.35.0 decorator/make_type().( |
| 130 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(&ty_str[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().4..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#ty_str.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().), |
| 131 | endianness_important, |
| 132 | ); |
| 133 | match ty { |
| 134 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ty) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Vectorrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Vector#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(ty))), |
| 135 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), |
| 136 | } |
| 137 | } else if ty_str.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("&") { |
| 138 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("invalid type: {}", ty_str)) |
| 139 | } else { |
| 140 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Miscrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Misc#(ty_str)) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | #[inline] |
| 145 | fn make_packetrust-analyzer cargo pnet_macros 0.35.0 decorator/make_packet().(s: &synrust-analyzer cargo syn 2.0.119 crate/::DataStructrust-analyzer cargo syn 2.0.119 derive/DataStruct#, name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#, Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 146 | let mut fields = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 147 | let mut payload_span = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 148 | let sfields = &s.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields.; |
| 149 | for field in sfields { |
| 150 | let field_name = match &field.identrust-analyzer cargo syn 2.0.119 data/Field#ident. { |
| 151 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) => name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 152 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 153 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 154 | field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty..spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 155 | "all fields in a packet must be named", |
| 156 | )); |
| 157 | } |
| 158 | }; |
| 159 | let mut construct_with = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 160 | let mut is_payload = false; |
| 161 | let mut packet_length = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 162 | let mut struct_length = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 163 | for attr in &field.attrsrust-analyzer cargo syn 2.0.119 data/Field#attrs. { |
| 164 | match attr.metarust-analyzer cargo syn 2.0.119 attr/Attribute#meta. { |
| 165 | synrust-analyzer cargo syn 2.0.119 crate/::Metarust-analyzer cargo syn 2.0.119 attr/Meta#::Pathrust-analyzer cargo syn 2.0.119 attr/Meta#Path#(ref p) => { |
| 166 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = p.get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().() { |
| 167 | if ident rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."payload" { |
| 168 | if payload_span.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 169 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 170 | p.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 171 | "packet may not have multiple payloads", |
| 172 | )); |
| 173 | } |
| 174 | is_payload = true; |
| 175 | payload_span = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(field.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().()); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | synrust-analyzer cargo syn 2.0.119 crate/::Metarust-analyzer cargo syn 2.0.119 attr/Meta#::NameValuerust-analyzer cargo syn 2.0.119 attr/Meta#NameValue#(ref name_value) => { |
| 180 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = name_value.pathrust-analyzer cargo syn 2.0.119 attr/MetaNameValue#path..get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().() { |
| 181 | if ident rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."length_fn" { |
| 182 | if let synrust-analyzer cargo syn 2.0.119 crate/::Exprrust-analyzer cargo syn 2.0.119 expr/Expr#::Litrust-analyzer cargo syn 2.0.119 expr/Expr#Lit#(synrust-analyzer cargo syn 2.0.119 crate/::ExprLitrust-analyzer cargo syn 2.0.119 expr/ExprLit# { |
| 183 | litrust-analyzer cargo syn 2.0.119 expr/ExprLit#lit.: synrust-analyzer cargo syn 2.0.119 crate/::Litrust-analyzer cargo syn 2.0.119 lit/Lit#::Strrust-analyzer cargo syn 2.0.119 lit/Lit#Str#(ref s), |
| 184 | .. |
| 185 | }) = name_value.valuerust-analyzer cargo syn 2.0.119 attr/MetaNameValue#value. |
| 186 | { |
| 187 | packet_length = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s.valuerust-analyzer cargo syn 2.0.119 lit/impl#[LitStr]value().() rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add()."(&_self.to_immutable())"); |
| 188 | } else { |
| 189 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 190 | name_value.pathrust-analyzer cargo syn 2.0.119 attr/MetaNameValue#path..spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 191 | "#[length_fn] should be used as #[length_fn = \ |
| 192 | \"name_of_function\"]", |
| 193 | )); |
| 194 | } |
| 195 | } else if ident rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."length" { |
| 196 | // get literal |
| 197 | if let synrust-analyzer cargo syn 2.0.119 crate/::Exprrust-analyzer cargo syn 2.0.119 expr/Expr#::Litrust-analyzer cargo syn 2.0.119 expr/Expr#Lit#(synrust-analyzer cargo syn 2.0.119 crate/::ExprLitrust-analyzer cargo syn 2.0.119 expr/ExprLit# { |
| 198 | litrust-analyzer cargo syn 2.0.119 expr/ExprLit#lit.: synrust-analyzer cargo syn 2.0.119 crate/::Litrust-analyzer cargo syn 2.0.119 lit/Lit#::Strrust-analyzer cargo syn 2.0.119 lit/Lit#Str#(ref s), |
| 199 | .. |
| 200 | }) = name_value.valuerust-analyzer cargo syn 2.0.119 attr/MetaNameValue#value. |
| 201 | { |
| 202 | let field_names: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = sfields |
| 203 | .iterrust-analyzer cargo syn 2.0.119 data/impl#[Fields]iter().() |
| 204 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|field| { |
| 205 | field.identrust-analyzer cargo syn 2.0.119 data/Field#ident..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|name| name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().( |
| 206 | |name| { |
| 207 | if name rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<Self>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<Self>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<Self>`]eq().field_name { |
| 208 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 209 | } else { |
| 210 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) |
| 211 | } |
| 212 | }, |
| 213 | ) |
| 214 | }) |
| 215 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 216 | // Convert to tokens |
| 217 | let expr = s.parserust-analyzer cargo syn 2.0.119 lit/impl#[LitStr]parse().::<synrust-analyzer cargo syn 2.0.119 crate/::Exprrust-analyzer cargo syn 2.0.119 expr/Expr#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 218 | let tts = expr.to_token_streamrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#to_token_stream().(); |
| 219 | let tt_tokens: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = tts.into_iterrust-analyzer cargo proc-macro2 1.0.107 token_stream/impl#[TokenStream][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 220 | // Parse and replace fields |
| 221 | let tokens_packet = parse_length_exprrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_length_expr().(&tt_tokens, &field_names)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 222 | let parsed = quoterust-analyzer cargo quote 1.0.47 quote!! { #(#tokens_packet)* }; |
| 223 | packet_length = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parsed.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 224 | } else { |
| 225 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 226 | name_value.valuerust-analyzer cargo syn 2.0.119 attr/MetaNameValue#value..spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 227 | "#[length] should be used as #[length = \ |
| 228 | \"field_name and/or arithmetic expression\"]", |
| 229 | )); |
| 230 | } |
| 231 | } else { |
| 232 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 233 | ident.spanrust-analyzer cargo proc-macro2 1.0.107 impl#[Ident]span().(), |
| 234 | &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Unknown meta/namevalue option '{}'", ident), |
| 235 | )); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | synrust-analyzer cargo syn 2.0.119 crate/::Metarust-analyzer cargo syn 2.0.119 attr/Meta#::Listrust-analyzer cargo syn 2.0.119 attr/Meta#List#(ref l) => { |
| 240 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = l.pathrust-analyzer cargo syn 2.0.119 attr/MetaList#path..get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().() { |
| 241 | if ident rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."construct_with" { |
| 242 | let mut some_construct_with = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 243 | |
| 244 | l.parse_nested_metarust-analyzer cargo syn 2.0.119 attr/impl#[MetaList]parse_nested_meta().(|meta| { |
| 245 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = meta.pathrust-analyzer cargo syn 2.0.119 meta/ParseNestedMeta#path..get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().() { |
| 246 | // #[construct_with(<type>,...)] |
| 247 | let ty_str = ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 248 | match make_typerust-analyzer cargo pnet_macros 0.35.0 decorator/make_type().(ty_str, false) { |
| 249 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ty) => { |
| 250 | some_construct_with.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ty); |
| 251 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 252 | } |
| 253 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(meta.errorrust-analyzer cargo syn 2.0.119 meta/impl#[`ParseNestedMeta<'a>`]error().(e)), |
| 254 | } |
| 255 | } else { |
| 256 | // Not an ident. Something else, likely a path. |
| 257 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(meta.errorrust-analyzer cargo syn 2.0.119 meta/impl#[`ParseNestedMeta<'a>`]error().("expected ident")) |
| 258 | } |
| 259 | }) |
| 260 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|mut err| { |
| 261 | err.combinerust-analyzer cargo syn 2.0.119 error/impl#[Error]combine().(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 262 | l.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 263 | "#[construct_with] should be of the form \ |
| 264 | #[construct_with(<primitive types>)]", |
| 265 | )); |
| 266 | err |
| 267 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 268 | |
| 269 | if some_construct_with.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 270 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 271 | l.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 272 | "#[construct_with] must have at least one argument", |
| 273 | )); |
| 274 | } |
| 275 | construct_with = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(some_construct_with); |
| 276 | } else { |
| 277 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 278 | ident.spanrust-analyzer cargo proc-macro2 1.0.107 impl#[Ident]span().(), |
| 279 | &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unknown attribute: {}", ident), |
| 280 | )); |
| 281 | } |
| 282 | } else { |
| 283 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 284 | l.pathrust-analyzer cargo syn 2.0.119 attr/MetaList#path..spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 285 | "meta-list attribute has unexpected type (not an ident)", |
| 286 | )); |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | let ty = match make_typerust-analyzer cargo pnet_macros 0.35.0 decorator/make_type().(ty_to_stringrust-analyzer cargo pnet_macros 0.35.0 decorator/ty_to_string().(&field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty.), true) { |
| 293 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ty) => ty, |
| 294 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 295 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().(field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty..spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", e))); |
| 296 | } |
| 297 | }; |
| 298 | |
| 299 | match ty { |
| 300 | Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Vectorrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Vector#(_) => { |
| 301 | struct_length = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(construct_with) = construct_with.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 302 | let mut inner_size = 0; |
| 303 | for arg in construct_with.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 304 | if let Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Primitiverust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Primitive#(ref _ty_str, size, _endianness) = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().arg { |
| 305 | inner_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().size; |
| 306 | } else { |
| 307 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 308 | field.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 309 | "arguments to #[construct_with] must be primitives", |
| 310 | )); |
| 311 | } |
| 312 | } |
| 313 | if inner_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 { |
| 314 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 315 | field.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 316 | "types in #[construct_with] for vec must be add up to a multiple of 8 bits", |
| 317 | )); |
| 318 | } |
| 319 | inner_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`DivAssign<Self>`]div_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`DivAssign<Self>`]div_assign().8; // bytes not bits |
| 320 | |
| 321 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("_packet.{}.len() * {}", field_name, inner_size).to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().()) |
| 322 | } else { |
| 323 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("_packet.{}.len()", field_name).to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().()) |
| 324 | }; |
| 325 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_payload && packet_length.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 326 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 327 | field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty..spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 328 | "variable length field must have #[length = \"\"] or \ |
| 329 | #[length_fn = \"\"] attribute", |
| 330 | )); |
| 331 | } |
| 332 | } |
| 333 | Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Miscrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Misc#(_) => { |
| 334 | if construct_with.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 335 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 336 | field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty..spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 337 | "non-primitive field types must specify #[construct_with]", |
| 338 | )); |
| 339 | } |
| 340 | } |
| 341 | _ => {} |
| 342 | } |
| 343 | |
| 344 | fields.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/Field# { |
| 345 | namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name.: field_name, |
| 346 | spanrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#span.: field.spanrust-analyzer cargo syn 2.0.119 spanned/impl#[T][Spanned]span().(), |
| 347 | tyrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#ty., |
| 348 | packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length., |
| 349 | struct_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#struct_length., |
| 350 | is_payloadrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#is_payload., |
| 351 | construct_withrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#construct_with., |
| 352 | }); |
| 353 | } |
| 354 | |
| 355 | if payload_span.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 356 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 357 | Spanrust-analyzer cargo proc-macro2 1.0.107 Span#::call_siterust-analyzer cargo proc-macro2 1.0.107 impl#[Span]call_site().(), |
| 358 | "#[packet]'s must contain a payload", |
| 359 | )); |
| 360 | } |
| 361 | |
| 362 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet# { |
| 363 | base_namerust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#base_name.: name, |
| 364 | fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#fields., |
| 365 | }) |
| 366 | } |
| 367 | |
| 368 | /// Return the processed length expression for a packet. |
| 369 | #[inline] |
| 370 | fn parse_length_exprrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_length_expr().( |
| 371 | tts: &[proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenTreerust-analyzer cargo proc-macro2 1.0.107 TokenTree#], |
| 372 | field_names: &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#], |
| 373 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenTreerust-analyzer cargo proc-macro2 1.0.107 TokenTree#>, Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 374 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenTreerust-analyzer cargo proc-macro2 1.0.107 TokenTree#; |
| 375 | let error_msg = "Only field names, constants, integers, basic arithmetic expressions \ |
| 376 | (+ - * / %) and parentheses are allowed in the \"length\" attribute"; |
| 377 | let mut needs_constant: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Spanrust-analyzer cargo proc-macro2 1.0.107 Span#> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 378 | let mut has_constant = false; |
| 379 | let mut tokens_packet = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 380 | for tt_token in tts { |
| 381 | match tt_token { |
| 382 | TokenTreerust-analyzer cargo proc-macro2 1.0.107 TokenTree#::Identrust-analyzer cargo proc-macro2 1.0.107 TokenTree#Ident#(name) => { |
| 383 | if name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|c| c.is_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_lowercase().()) { |
| 384 | if field_names.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) { |
| 385 | let tts: synrust-analyzer cargo syn 2.0.119 crate/::Exprrust-analyzer cargo syn 2.0.119 expr/Expr# = |
| 386 | synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("_self.get_{}() as usize", name))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 387 | let mut modified_packet_tokens: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = |
| 388 | tts.to_token_streamrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#to_token_stream().().into_iterrust-analyzer cargo proc-macro2 1.0.107 token_stream/impl#[TokenStream][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 389 | tokens_packet.appendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]append().(&mut modified_packet_tokens); |
| 390 | } else { |
| 391 | if let Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# = needs_constant { |
| 392 | needs_constant = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tt_token.spanrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenTree]span().()); |
| 393 | } |
| 394 | tokens_packet.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(tt_token.clonerust-analyzer cargo proc-macro2 1.0.107 impl#[TokenTree][Clone]clone().()); |
| 395 | } |
| 396 | } |
| 397 | // Constants are only recognized if they are all uppercase |
| 398 | else { |
| 399 | let tts: synrust-analyzer cargo syn 2.0.119 crate/::Exprrust-analyzer cargo syn 2.0.119 expr/Expr# = synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{} as usize", name))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 400 | let mut modified_packet_tokens: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = |
| 401 | tts.to_token_streamrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#to_token_stream().().into_iterrust-analyzer cargo proc-macro2 1.0.107 token_stream/impl#[TokenStream][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 402 | tokens_packet.appendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]append().(&mut modified_packet_tokens); |
| 403 | has_constant = true; |
| 404 | } |
| 405 | } |
| 406 | TokenTreerust-analyzer cargo proc-macro2 1.0.107 TokenTree#::Punctrust-analyzer cargo proc-macro2 1.0.107 TokenTree#Punct#(_) => { |
| 407 | tokens_packet.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(tt_token.clonerust-analyzer cargo proc-macro2 1.0.107 impl#[TokenTree][Clone]clone().()); |
| 408 | } |
| 409 | TokenTreerust-analyzer cargo proc-macro2 1.0.107 TokenTree#::Literalrust-analyzer cargo proc-macro2 1.0.107 TokenTree#Literal#(lit) => { |
| 410 | // must be an integer |
| 411 | if synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().::<synrust-analyzer cargo syn 2.0.119 crate/::LitIntrust-analyzer cargo syn 2.0.119 lit/LitInt#>(&lit.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() { |
| 412 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().(lit.spanrust-analyzer cargo proc-macro2 1.0.107 impl#[Literal]span().(), error_msg)); |
| 413 | } |
| 414 | tokens_packet.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(tt_token.clonerust-analyzer cargo proc-macro2 1.0.107 impl#[TokenTree][Clone]clone().()); |
| 415 | } |
| 416 | TokenTreerust-analyzer cargo proc-macro2 1.0.107 TokenTree#::Grouprust-analyzer cargo proc-macro2 1.0.107 TokenTree#Group#(ref group) => { |
| 417 | let ts: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = group.streamrust-analyzer cargo proc-macro2 1.0.107 impl#[Group]stream().().into_iterrust-analyzer cargo proc-macro2 1.0.107 token_stream/impl#[TokenStream][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 418 | let tts = parse_length_exprrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_length_expr().(&ts, field_names)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 419 | let mut new_group = Grouprust-analyzer cargo proc-macro2 1.0.107 Group#::newrust-analyzer cargo proc-macro2 1.0.107 impl#[Group]new().( |
| 420 | group.delimiterrust-analyzer cargo proc-macro2 1.0.107 impl#[Group]delimiter().(), |
| 421 | proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#::from_iterrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`FromIterator<TokenTree>`]from_iter().(tts.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()), |
| 422 | ); |
| 423 | new_group.set_spanrust-analyzer cargo proc-macro2 1.0.107 impl#[Group]set_span().(group.spanrust-analyzer cargo proc-macro2 1.0.107 impl#[Group]span().()); |
| 424 | let tt = TokenTreerust-analyzer cargo proc-macro2 1.0.107 TokenTree#::Grouprust-analyzer cargo proc-macro2 1.0.107 TokenTree#Group#(new_group); |
| 425 | tokens_packet.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(tt); |
| 426 | } |
| 427 | }; |
| 428 | } |
| 429 | |
| 430 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(span) = needs_constant { |
| 431 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_constant { |
| 432 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 433 | span, |
| 434 | "Field name must be a member of the struct and not the field itself", |
| 435 | )); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tokens_packet) |
| 440 | } |
| 441 | |
| 442 | #[inline] |
| 443 | fn generate_packet_implrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_impl().( |
| 444 | packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#, |
| 445 | mutable: bool, |
| 446 | name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 447 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, PayloadBoundsrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 448 | let mut bit_offset = 0; |
| 449 | let mut offset_fns_packet = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 450 | let mut offset_fns_struct = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 451 | let mut accessors = "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 452 | let mut mutators = "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 453 | let mut payload_bounds = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 454 | for (idx, field) in packet.fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#fields..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 455 | let mut co = current_offsetrust-analyzer cargo pnet_macros 0.35.0 decorator/current_offset().(bit_offset, &offset_fns_packet[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().); |
| 456 | |
| 457 | if field.is_payloadrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#is_payload. { |
| 458 | let mut upper_bound_str = "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 459 | if field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 460 | upper_bound_str = |
| 461 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{} + {}", co.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 462 | } else { |
| 463 | if idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().packet.fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#fields..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1 { |
| 464 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 465 | field.spanrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#span., |
| 466 | "#[payload] must specify a #[length_fn], unless it is the \ |
| 467 | last field of a packet", |
| 468 | )); |
| 469 | } |
| 470 | } |
| 471 | payload_bounds = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PayloadBoundsrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds# { |
| 472 | lowerrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#lower.: co.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), |
| 473 | upperrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#upper.: upper_bound_str, |
| 474 | }); |
| 475 | } |
| 476 | match field.tyrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#ty. { |
| 477 | Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Primitiverust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Primitive#(ref ty_str, size, endianness) => { |
| 478 | let mut ops = operationsrust-analyzer cargo pnet_macros 0.35.0 util/operations().(bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().8, size).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 479 | let target_endianness = if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_endian = "little") { |
| 480 | Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# |
| 481 | } else { |
| 482 | Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big# |
| 483 | }; |
| 484 | |
| 485 | if endianness rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# |
| 486 | || (target_endianness rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# && endianness rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Hostrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Host#) |
| 487 | { |
| 488 | ops = to_little_endianrust-analyzer cargo pnet_macros 0.35.0 util/to_little_endian().(ops); |
| 489 | } |
| 490 | |
| 491 | mutators = mutators |
| 492 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&generate_mutator_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_mutator_str().( |
| 493 | &field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 494 | &ty_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 495 | &co[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 496 | &to_mutatorrust-analyzer cargo pnet_macros 0.35.0 util/to_mutator().(&ops[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., |
| 497 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 498 | )[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 499 | accessors = accessors |
| 500 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&generate_accessor_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_str().(&field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., &ty_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &co[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., &ops[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 501 | [rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 502 | bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().size; |
| 503 | } |
| 504 | Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Vectorrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Vector#(ref inner_ty) => handle_vector_fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/handle_vector_field().( |
| 505 | &field, |
| 506 | &mut bit_offset, |
| 507 | &offset_fns_packet[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., |
| 508 | &mut co, |
| 509 | &name, |
| 510 | &mut mutators, |
| 511 | &mut accessors, |
| 512 | inner_ty, |
| 513 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 514 | Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Miscrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Misc#(ref ty_str) => handle_misc_fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/handle_misc_field().( |
| 515 | &field, |
| 516 | &mut bit_offset, |
| 517 | &offset_fns_packet[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., |
| 518 | &mut co, |
| 519 | &name, |
| 520 | &mut mutators, |
| 521 | &mut accessors, |
| 522 | &ty_str, |
| 523 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 524 | } |
| 525 | if field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 526 | offset_fns_packet.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()); |
| 527 | } |
| 528 | if field.struct_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#struct_length..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 529 | offset_fns_struct.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(field.struct_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#struct_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | fn generate_set_fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_set_fields().(packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 534 | let mut set_fields = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 535 | for field in &packet.fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#fields. { |
| 536 | match field.tyrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#ty. { |
| 537 | Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Vectorrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Vector#(_) => { |
| 538 | set_fields = set_fields |
| 539 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("_self.set_{field}(&packet.{field});\n", field = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name.)[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 540 | } |
| 541 | _ => { |
| 542 | set_fields = set_fields |
| 543 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("_self.set_{field}(packet.{field});\n", field = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name.)[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | set_fields |
| 549 | } |
| 550 | |
| 551 | let populate = if mutable { |
| 552 | let set_fields = generate_set_fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_set_fields().(&packet); |
| 553 | let imm_name = packet.packet_namerust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name().(); |
| 554 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 555 | "/// Populates a {name}Packet using a {name} structure |
| 556 | #[inline] |
| 557 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 558 | pub fn populate(&mut self, packet: &{name}) {{ |
| 559 | let _self = self; |
| 560 | {set_fields} |
| 561 | }}", |
| 562 | name = &imm_name[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...imm_name.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 6]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 563 | set_fields = set_fields |
| 564 | ) |
| 565 | } else { |
| 566 | "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().() |
| 567 | }; |
| 568 | |
| 569 | // If there are no variable length fields defined, then `_packet` is not used, hence |
| 570 | // the leading underscore |
| 571 | let packet_size_struct = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 572 | "/// The size (in bytes) of a {base_name} instance when converted into |
| 573 | /// a byte-array |
| 574 | #[inline] |
| 575 | pub fn packet_size(_packet: \ |
| 576 | &{base_name}) -> usize {{ |
| 577 | {struct_size} |
| 578 | }}", |
| 579 | base_name = packet.base_namerust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#base_name., |
| 580 | struct_size = current_offsetrust-analyzer cargo pnet_macros 0.35.0 decorator/current_offset().(bit_offset, &offset_fns_struct[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().) |
| 581 | ); |
| 582 | |
| 583 | let byte_size = if bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 584 | bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().8 |
| 585 | } else { |
| 586 | (bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().8) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 |
| 587 | }; |
| 588 | |
| 589 | let s = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("impl<'a> {name}<'a> {{ |
| 590 | /// Constructs a new {name}. If the provided buffer is less than the minimum required |
| 591 | /// packet size, this will return None. |
| 592 | #[inline] |
| 593 | pub fn new<'p>(packet: &'p {mut} [u8]) -> Option<{name}<'p>> {{ |
| 594 | if packet.len() >= {name}::minimum_packet_size() {{ |
| 595 | use ::pnet_macros_support::packet::{cap_mut}PacketData; |
| 596 | Some({name} {{ packet: {cap_mut}PacketData::Borrowed(packet) }}) |
| 597 | }} else {{ |
| 598 | None |
| 599 | }} |
| 600 | }} |
| 601 | |
| 602 | /// Constructs a new {name}. If the provided buffer is less than the minimum required |
| 603 | /// packet size, this will return None. With this constructor the {name} will |
| 604 | /// own its own data and the underlying buffer will be dropped when the {name} is. |
| 605 | pub fn owned(packet: Vec<u8>) -> Option<{name}<'static>> {{ |
| 606 | if packet.len() >= {name}::minimum_packet_size() {{ |
| 607 | use ::pnet_macros_support::packet::{cap_mut}PacketData; |
| 608 | Some({name} {{ packet: {cap_mut}PacketData::Owned(packet) }}) |
| 609 | }} else {{ |
| 610 | None |
| 611 | }} |
| 612 | }} |
| 613 | |
| 614 | /// Maps from a {name} to a {imm_name} |
| 615 | #[inline] |
| 616 | pub fn to_immutable<'p>(&'p self) -> {imm_name}<'p> {{ |
| 617 | use ::pnet_macros_support::packet::PacketData; |
| 618 | {imm_name} {{ packet: PacketData::Borrowed(self.packet.as_slice()) }} |
| 619 | }} |
| 620 | |
| 621 | /// Maps from a {name} to a {imm_name} while consuming the source |
| 622 | #[inline] |
| 623 | pub fn consume_to_immutable(self) -> {imm_name}<'a> {{ |
| 624 | {imm_name} {{ packet: self.packet.to_immutable() }} |
| 625 | }} |
| 626 | |
| 627 | /// The minimum size (in bytes) a packet of this type can be. It's based on the total size |
| 628 | /// of the fixed-size fields. |
| 629 | #[inline] |
| 630 | pub const fn minimum_packet_size() -> usize {{ |
| 631 | {byte_size} |
| 632 | }} |
| 633 | |
| 634 | {packet_size_struct} |
| 635 | |
| 636 | {populate} |
| 637 | |
| 638 | {accessors} |
| 639 | |
| 640 | {mutators} |
| 641 | }}", name = name, |
| 642 | imm_name = packet.packet_namerust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name().(), |
| 643 | mut = if mutable { "mut" } else { "" }, |
| 644 | cap_mut = if mutable { "Mut" } else { "" }, |
| 645 | byte_size = byte_size, |
| 646 | accessors = accessors, |
| 647 | mutators = if mutable { &mutators[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index(). } else { "" }, |
| 648 | populate = populate, |
| 649 | packet_size_struct = packet_size_struct |
| 650 | ); |
| 651 | |
| 652 | let stmt: synrust-analyzer cargo syn 2.0.119 crate/::Stmtrust-analyzer cargo syn 2.0.119 stmt/Stmt# = synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().(&s).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("parse fn generate_packet_impl failed"); |
| 653 | let ts = quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 654 | #stmt |
| 655 | }; |
| 656 | |
| 657 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(( |
| 658 | ts, |
| 659 | payload_bounds.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 660 | current_offsetrust-analyzer cargo pnet_macros 0.35.0 decorator/current_offset().(bit_offset, &offset_fns_packet[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().), |
| 661 | )) |
| 662 | } |
| 663 | |
| 664 | #[inline] |
| 665 | fn generate_packet_implsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_impls().( |
| 666 | packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#, |
| 667 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, PayloadBoundsrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 668 | let mut ret = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 669 | let mut tts = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 670 | for (mutable, name) in vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 671 | (false, packet.packet_namerust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name().()), |
| 672 | (true, packet.packet_name_mutrust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name_mut().()), |
| 673 | ] { |
| 674 | let (tokens, bounds, size) = generate_packet_implrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_impl().(packet, mutable, name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 675 | tts.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(tokens); |
| 676 | ret = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((bounds, size)); |
| 677 | } |
| 678 | let tokens = quoterust-analyzer cargo quote 1.0.47 quote!! { #(#tts)* }; |
| 679 | |
| 680 | ret.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(bounds, size)| (tokens, bounds, size)) |
| 681 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().(Spanrust-analyzer cargo proc-macro2 1.0.107 Span#::call_siterust-analyzer cargo proc-macro2 1.0.107 impl#[Span]call_site().(), "generate_packet_impls failed")) |
| 682 | } |
| 683 | |
| 684 | #[inline] |
| 685 | fn generate_packet_size_implsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_size_impls().( |
| 686 | packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#, |
| 687 | size: &str, |
| 688 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 689 | let tts: Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _> = [packet.packet_namerust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name().(), packet.packet_name_mutrust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name_mut().()] |
| 690 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 691 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|name| { |
| 692 | let s = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 693 | " |
| 694 | impl<'a> ::pnet_macros_support::packet::PacketSize for {name}<'a> {{ |
| 695 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 696 | fn packet_size(&self) -> usize {{ |
| 697 | let _self = self; |
| 698 | {size} |
| 699 | }} |
| 700 | }} |
| 701 | ", |
| 702 | name = name, |
| 703 | size = size |
| 704 | ); |
| 705 | synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().::<synrust-analyzer cargo syn 2.0.119 crate/::Stmtrust-analyzer cargo syn 2.0.119 stmt/Stmt#>(&s) |
| 706 | }) |
| 707 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 708 | let tts = tts?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 709 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(quoterust-analyzer cargo quote 1.0.47 quote!! { #(#tts)* }) |
| 710 | } |
| 711 | |
| 712 | #[inline] |
| 713 | fn generate_packet_trait_implsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_packet_trait_impls().( |
| 714 | packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#, |
| 715 | payload_bounds: &PayloadBoundsrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#, |
| 716 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 717 | let items = [ |
| 718 | (packet.packet_name_mutrust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name_mut().(), "Mutable", "_mut", "mut"), |
| 719 | (packet.packet_name_mutrust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name_mut().(), "", "", ""), |
| 720 | (packet.packet_namerust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name().(), "", "", ""), |
| 721 | ]; |
| 722 | let tts: Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _> = items |
| 723 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 724 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(name, mutable, u_mut, mut_)| { |
| 725 | let mut pre = "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 726 | let mut start = "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 727 | let mut end = "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 728 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().payload_bounds.lowerrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#lower..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() { |
| 729 | pre = pre rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("let start = {};", payload_bounds.lowerrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#lower.)[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 730 | start = "start".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 731 | } |
| 732 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().payload_bounds.upperrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#upper..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() { |
| 733 | pre = pre |
| 734 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 735 | "let end = ::core::cmp::min({}, _self.packet.len());", |
| 736 | payload_bounds.upperrust-analyzer cargo pnet_macros 0.35.0 decorator/PayloadBounds#upper. |
| 737 | )[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 738 | end = "end".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 739 | } |
| 740 | let s = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 741 | "impl<'a> ::pnet_macros_support::packet::{mutable}Packet for {name}<'a> {{ |
| 742 | #[inline] |
| 743 | fn packet{u_mut}<'p>(&'p {mut_} self) -> &'p {mut_} [u8] {{ &{mut_} self.packet[..] }} |
| 744 | |
| 745 | #[inline] |
| 746 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 747 | fn payload{u_mut}<'p>(&'p {mut_} self) -> &'p {mut_} [u8] {{ |
| 748 | let _self = self; |
| 749 | {pre} |
| 750 | if _self.packet.len() <= {start} {{ |
| 751 | return &{mut_} []; |
| 752 | }} |
| 753 | &{mut_} _self.packet[{start}..{end}] |
| 754 | }} |
| 755 | }}", |
| 756 | name = name, |
| 757 | start = start, |
| 758 | end = end, |
| 759 | pre = pre, |
| 760 | mutable = mutable, |
| 761 | u_mut = u_mut, |
| 762 | mut_ = mut_ |
| 763 | ); |
| 764 | synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().::<synrust-analyzer cargo syn 2.0.119 crate/::Stmtrust-analyzer cargo syn 2.0.119 stmt/Stmt#>(&s) |
| 765 | }) |
| 766 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 767 | let tts = tts?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 768 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(quoterust-analyzer cargo quote 1.0.47 quote!! { #(#tts)* }) |
| 769 | } |
| 770 | |
| 771 | #[inline] |
| 772 | fn generate_iterablesrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_iterables().(packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 773 | let name = &packet.base_namerust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#base_name.; |
| 774 | |
| 775 | let ts1 = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 776 | " |
| 777 | /// Used to iterate over a slice of `{name}Packet`s |
| 778 | pub struct {name}Iterable<'a> {{ |
| 779 | buf: &'a [u8], |
| 780 | }} |
| 781 | ", |
| 782 | name = name |
| 783 | ); |
| 784 | |
| 785 | let ts2 = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 786 | " |
| 787 | impl<'a> Iterator for {name}Iterable<'a> {{ |
| 788 | type Item = {name}Packet<'a>; |
| 789 | |
| 790 | fn next(&mut self) -> Option<{name}Packet<'a>> {{ |
| 791 | use pnet_macros_support::packet::PacketSize; |
| 792 | use core::cmp::min; |
| 793 | if self.buf.len() > 0 {{ |
| 794 | if let Some(ret) = {name}Packet::new(self.buf) {{ |
| 795 | let start = min(ret.packet_size(), self.buf.len()); |
| 796 | self.buf = &self.buf[start..]; |
| 797 | return Some(ret); |
| 798 | }} |
| 799 | }} |
| 800 | |
| 801 | None |
| 802 | }} |
| 803 | |
| 804 | fn size_hint(&self) -> (usize, Option<usize>) {{ |
| 805 | (0, None) |
| 806 | }} |
| 807 | }} |
| 808 | ", |
| 809 | name = name |
| 810 | ); |
| 811 | let ts1: synrust-analyzer cargo syn 2.0.119 crate/::Stmtrust-analyzer cargo syn 2.0.119 stmt/Stmt# = synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().(&ts1)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 812 | let ts2: synrust-analyzer cargo syn 2.0.119 crate/::Stmtrust-analyzer cargo syn 2.0.119 stmt/Stmt# = synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().(&ts2)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 813 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 814 | #ts1 |
| 815 | #ts2 |
| 816 | }) |
| 817 | } |
| 818 | |
| 819 | #[inline] |
| 820 | fn generate_convertersrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_converters().(packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 821 | let get_fields = generate_get_fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_get_fields().(packet); |
| 822 | |
| 823 | let tts: Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _> = [packet.packet_namerust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name().(), packet.packet_name_mutrust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name_mut().()] |
| 824 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 825 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|name| { |
| 826 | let s = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 827 | " |
| 828 | impl<'p> ::pnet_macros_support::packet::FromPacket for {packet}<'p> {{ |
| 829 | type T = {name}; |
| 830 | #[inline] |
| 831 | fn from_packet(&self) -> {name} {{ |
| 832 | use pnet_macros_support::packet::Packet; |
| 833 | let _self = self; |
| 834 | {name} {{ |
| 835 | {get_fields} |
| 836 | }} |
| 837 | }} |
| 838 | }}", |
| 839 | packet = name, |
| 840 | name = packet.base_namerust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#base_name., |
| 841 | get_fields = get_fields |
| 842 | ); |
| 843 | synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().::<synrust-analyzer cargo syn 2.0.119 crate/::Stmtrust-analyzer cargo syn 2.0.119 stmt/Stmt#>(&s) |
| 844 | }) |
| 845 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 846 | let tts = tts?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 847 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(quoterust-analyzer cargo quote 1.0.47 quote!! { #(#tts)* }) |
| 848 | } |
| 849 | |
| 850 | #[inline] |
| 851 | fn generate_debug_implsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_debug_impls().(packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 852 | let mut field_fmt_str = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 853 | let mut get_fields = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 854 | |
| 855 | for field in &packet.fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#fields. { |
| 856 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().field.is_payloadrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#is_payload. { |
| 857 | field_fmt_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{} : {{:?}}, ", field_fmt_str, field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name.); |
| 858 | get_fields = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}, _self.get_{}()", get_fields, field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name.); |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | let tts: Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, _> = [packet.packet_namerust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name().(), packet.packet_name_mutrust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[Packet]packet_name_mut().()] |
| 863 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 864 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|packet| { |
| 865 | let s = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 866 | " |
| 867 | impl<'p> ::core::fmt::Debug for {packet}<'p> {{ |
| 868 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 869 | fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {{ |
| 870 | let _self = self; |
| 871 | write!(fmt, |
| 872 | \"{packet} {{{{ {field_fmt_str} }}}}\" |
| 873 | {get_fields} |
| 874 | ) |
| 875 | }} |
| 876 | }}", |
| 877 | packet = packet, |
| 878 | field_fmt_str = field_fmt_str, |
| 879 | get_fields = get_fields |
| 880 | ); |
| 881 | synrust-analyzer cargo syn 2.0.119 crate/::parse_strrust-analyzer cargo syn 2.0.119 parse_str().::<synrust-analyzer cargo syn 2.0.119 crate/::Stmtrust-analyzer cargo syn 2.0.119 stmt/Stmt#>(&s) |
| 882 | }) |
| 883 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 884 | let tts = tts?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 885 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(quoterust-analyzer cargo quote 1.0.47 quote!! { #(#tts)* }) |
| 886 | } |
| 887 | |
| 888 | #[inline] |
| 889 | fn handle_misc_fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/handle_misc_field().( |
| 890 | field: &Fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#, |
| 891 | bit_offset: &mut usize, |
| 892 | offset_fns: &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#], |
| 893 | co: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 894 | name: &str, |
| 895 | mutators: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 896 | accessors: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 897 | ty_str: &str, |
| 898 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 899 | let mut inner_accessors = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 900 | let mut inner_mutators = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 901 | let mut get_args = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 902 | let mut set_args = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 903 | for (i, arg) in field |
| 904 | .construct_withrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#construct_with. |
| 905 | .as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() |
| 906 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("misc field as ref") |
| 907 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 908 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 909 | { |
| 910 | if let Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Primitiverust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Primitive#(ref ty_str, size, endianness) = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().arg { |
| 911 | let mut ops = operationsrust-analyzer cargo pnet_macros 0.35.0 util/operations().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().8, size).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 912 | let target_endianness = if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_endian = "little") { |
| 913 | Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# |
| 914 | } else { |
| 915 | Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big# |
| 916 | }; |
| 917 | |
| 918 | if endianness rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# |
| 919 | || (target_endianness rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# && endianness rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Hostrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Host#) |
| 920 | { |
| 921 | ops = to_little_endianrust-analyzer cargo pnet_macros 0.35.0 util/to_little_endian().(ops); |
| 922 | } |
| 923 | |
| 924 | let arg_name = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("arg{}", i); |
| 925 | inner_accessors = inner_accessors |
| 926 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&generate_accessor_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_str().( |
| 927 | &arg_name[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 928 | &ty_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 929 | &co[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 930 | &ops[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., |
| 931 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&name[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().), |
| 932 | )[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 933 | inner_mutators = inner_mutators |
| 934 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&generate_mutator_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_mutator_str().( |
| 935 | &arg_name[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 936 | &ty_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 937 | &co[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 938 | &to_mutatorrust-analyzer cargo pnet_macros 0.35.0 util/to_mutator().(&ops[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., |
| 939 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&name[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().), |
| 940 | )[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 941 | get_args = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}get_{}(&self), ", get_args, arg_name); |
| 942 | set_args = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}set_{}(_self, vals.{});\n", set_args, arg_name, i); |
| 943 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().size; |
| 944 | // Current offset needs to be recalculated for each arg |
| 945 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().co = current_offsetrust-analyzer cargo pnet_macros 0.35.0 decorator/current_offset().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().bit_offset, offset_fns); |
| 946 | } else { |
| 947 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 948 | field.spanrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#span., |
| 949 | "arguments to #[construct_with] must be primitives", |
| 950 | )); |
| 951 | } |
| 952 | } |
| 953 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().mutators = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 954 | "{mutators} |
| 955 | /// Set the value of the {name} field. |
| 956 | #[inline] |
| 957 | #[allow(trivial_numeric_casts)] |
| 958 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 959 | pub fn set_{name}(&mut self, val: {ty_str}) {{ |
| 960 | use pnet_macros_support::packet::PrimitiveValues; |
| 961 | let _self = self; |
| 962 | {inner_mutators} |
| 963 | |
| 964 | let vals = val.to_primitive_values(); |
| 965 | |
| 966 | {set_args} |
| 967 | }} |
| 968 | ", |
| 969 | mutators = &mutators[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 970 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 971 | ty_str = ty_str, |
| 972 | inner_mutators = inner_mutators, |
| 973 | set_args = set_args |
| 974 | ); |
| 975 | let ctor = if field.construct_withrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#construct_with..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 976 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 977 | "{} {}::new({})", |
| 978 | inner_accessors, |
| 979 | ty_str, |
| 980 | &get_args[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...get_args.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index(). |
| 981 | ) |
| 982 | } else { |
| 983 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 984 | "let current_offset = {}; |
| 985 | {}::new(&_self.packet[current_offset..])", |
| 986 | co, ty_str |
| 987 | ) |
| 988 | }; |
| 989 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().accessors = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 990 | "{accessors} |
| 991 | /// Get the value of the {name} field |
| 992 | #[inline] |
| 993 | #[allow(trivial_numeric_casts)] |
| 994 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 995 | pub fn get_{name}(&self) -> {ty_str} {{ |
| 996 | {ctor} |
| 997 | }} |
| 998 | ", |
| 999 | accessors = accessors, |
| 1000 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 1001 | ty_str = ty_str, |
| 1002 | ctor = ctor |
| 1003 | ); |
| 1004 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1005 | } |
| 1006 | |
| 1007 | #[inline] |
| 1008 | fn handle_vec_primitiverust-analyzer cargo pnet_macros 0.35.0 decorator/handle_vec_primitive().( |
| 1009 | inner_ty_str: &str, |
| 1010 | size: usize, |
| 1011 | field: &Fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#, |
| 1012 | accessors: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 1013 | mutators: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 1014 | co: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 1015 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 1016 | if inner_ty_str rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."u8" || (size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().8) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 1017 | let ops = operationsrust-analyzer cargo pnet_macros 0.35.0 util/operations().(0, size).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1018 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().field.is_payloadrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#is_payload. { |
| 1019 | let op_strings = generate_accessor_op_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_op_str().("packet", inner_ty_str, &ops); |
| 1020 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().accessors = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{accessors} |
| 1021 | /// Get the value of the {name} field (copies contents) |
| 1022 | #[inline] |
| 1023 | #[allow(trivial_numeric_casts, unused_parens, unused_braces)] |
| 1024 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1025 | pub fn get_{name}(&self) -> Vec<{inner_ty_str}> {{ |
| 1026 | use core::cmp::min; |
| 1027 | let _self = self; |
| 1028 | let current_offset = {co}; |
| 1029 | let pkt_len = self.packet.len(); |
| 1030 | let end = min(current_offset + {packet_length}, pkt_len); |
| 1031 | |
| 1032 | let packet = &_self.packet[current_offset..end]; |
| 1033 | let mut vec: Vec<{inner_ty_str}> = Vec::with_capacity(packet.len() / {size}); |
| 1034 | let mut co = 0; |
| 1035 | for _ in 0..vec.capacity() {{ |
| 1036 | vec.push({{ |
| 1037 | {ops} |
| 1038 | }}); |
| 1039 | co += {size}; |
| 1040 | }} |
| 1041 | vec |
| 1042 | }} |
| 1043 | ", |
| 1044 | accessors = accessors, |
| 1045 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 1046 | co = co, |
| 1047 | packet_length = field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 1048 | inner_ty_str = inner_ty_str, |
| 1049 | ops = op_strings, |
| 1050 | size = size /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). 8); |
| 1051 | } |
| 1052 | let check_len = if field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 1053 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1054 | "let len = {packet_length}; |
| 1055 | assert!(vals.len() <= len);", |
| 1056 | packet_length = field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 1057 | ) |
| 1058 | } else { |
| 1059 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().() |
| 1060 | }; |
| 1061 | |
| 1062 | let copy_vals = if inner_ty_str rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."u8" { |
| 1063 | // Efficient copy_from_slice (memcpy) |
| 1064 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1065 | " |
| 1066 | _self.packet[current_offset..current_offset + vals.len()] |
| 1067 | .copy_from_slice(vals); |
| 1068 | " |
| 1069 | ) |
| 1070 | } else { |
| 1071 | // e.g. Vec<u16> -> Vec<u8> |
| 1072 | let sop_strings = generate_sop_stringsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_sop_strings().(&to_mutatorrust-analyzer cargo pnet_macros 0.35.0 util/to_mutator().(&ops)); |
| 1073 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1074 | " |
| 1075 | let mut co = current_offset; |
| 1076 | for i in 0..vals.len() {{ |
| 1077 | let val = vals[i]; |
| 1078 | {sop} |
| 1079 | co += {size}; |
| 1080 | }}", |
| 1081 | sop = sop_strings, |
| 1082 | size = size /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). 8 |
| 1083 | ) |
| 1084 | }; |
| 1085 | |
| 1086 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().mutators = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1087 | "{mutators} |
| 1088 | /// Set the value of the {name} field (copies contents) |
| 1089 | #[inline] |
| 1090 | #[allow(trivial_numeric_casts)] |
| 1091 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1092 | pub fn set_{name}(&mut self, vals: &[{inner_ty_str}]) {{ |
| 1093 | let mut _self = self; |
| 1094 | let current_offset = {co}; |
| 1095 | |
| 1096 | {check_len} |
| 1097 | |
| 1098 | {copy_vals} |
| 1099 | }}", |
| 1100 | mutators = mutators, |
| 1101 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 1102 | co = co, |
| 1103 | check_len = check_len, |
| 1104 | inner_ty_str = inner_ty_str, |
| 1105 | copy_vals = copy_vals |
| 1106 | ); |
| 1107 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1108 | } else { |
| 1109 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 1110 | field.spanrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#span., |
| 1111 | "unimplemented variable length field", |
| 1112 | )) |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | #[inline] |
| 1117 | fn handle_vector_fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/handle_vector_field().( |
| 1118 | field: &Fieldrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#, |
| 1119 | bit_offset: &mut usize, |
| 1120 | offset_fns: &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#], |
| 1121 | co: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 1122 | name: &str, |
| 1123 | mutators: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 1124 | accessors: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 1125 | inner_ty: &Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#>, |
| 1126 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo syn 2.0.119 error/Error#> { |
| 1127 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().field.is_payloadrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#is_payload. && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 1128 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 1129 | field.spanrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#span., |
| 1130 | "variable length field must have #[length_fn = \"\"] attribute", |
| 1131 | )); |
| 1132 | } |
| 1133 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().field.is_payloadrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#is_payload. { |
| 1134 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().accessors = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{accessors} |
| 1135 | /// Get the raw &[u8] value of the {name} field, without copying |
| 1136 | #[inline] |
| 1137 | #[allow(trivial_numeric_casts)] |
| 1138 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1139 | pub fn get_{name}_raw(&self) -> &[u8] {{ |
| 1140 | use core::cmp::min; |
| 1141 | let _self = self; |
| 1142 | let current_offset = {co}; |
| 1143 | let end = min(current_offset + {packet_length}, _self.packet.len()); |
| 1144 | |
| 1145 | &_self.packet[current_offset..end] |
| 1146 | }} |
| 1147 | ", |
| 1148 | accessors = accessors, |
| 1149 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 1150 | co = co, |
| 1151 | packet_length = field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 1152 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().mutators = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{mutators} |
| 1153 | /// Get the raw &mut [u8] value of the {name} field, without copying |
| 1154 | #[inline] |
| 1155 | #[allow(trivial_numeric_casts)] |
| 1156 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1157 | pub fn get_{name}_raw_mut(&mut self) -> &mut [u8] {{ |
| 1158 | use core::cmp::min; |
| 1159 | let _self = self; |
| 1160 | let current_offset = {co}; |
| 1161 | let end = min(current_offset + {packet_length}, _self.packet.len()); |
| 1162 | |
| 1163 | &mut _self.packet[current_offset..end] |
| 1164 | }} |
| 1165 | ", |
| 1166 | mutators = mutators, |
| 1167 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 1168 | co = co, |
| 1169 | packet_length = field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 1170 | } |
| 1171 | match *rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().inner_ty { |
| 1172 | Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Primitiverust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Primitive#(ref inner_ty_str, _size, _endianness) => { |
| 1173 | handle_vec_primitiverust-analyzer cargo pnet_macros 0.35.0 decorator/handle_vec_primitive().(inner_ty_str, _size, field, accessors, mutators, co) |
| 1174 | } |
| 1175 | Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Vectorrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Vector#(_) => { |
| 1176 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 1177 | field.spanrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#span., |
| 1178 | "variable length fields may not contain vectors", |
| 1179 | )); |
| 1180 | } |
| 1181 | Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Miscrust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Misc#(ref inner_ty_str) => { |
| 1182 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(construct_with) = field.construct_withrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#construct_with..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 1183 | let mut inner_accessors = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 1184 | let mut inner_mutators = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 1185 | let mut get_args = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 1186 | let mut set_args = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 1187 | let mut inner_size = 0; |
| 1188 | for (i, arg) in construct_with.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 1189 | if let Typerust-analyzer cargo pnet_macros 0.35.0 decorator/Type#::Primitiverust-analyzer cargo pnet_macros 0.35.0 decorator/Type#Primitive#(ref ty_str, size, endianness) = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().arg { |
| 1190 | let mut ops = operationsrust-analyzer cargo pnet_macros 0.35.0 util/operations().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().8, size).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1191 | let target_endianness = if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_endian = "little") { |
| 1192 | Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# |
| 1193 | } else { |
| 1194 | Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big# |
| 1195 | }; |
| 1196 | |
| 1197 | if endianness rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# |
| 1198 | || (target_endianness rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# |
| 1199 | && endianness rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 util/impl#[Endianness][`PartialEq<Self>`]eq().Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Hostrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Host#) |
| 1200 | { |
| 1201 | ops = to_little_endianrust-analyzer cargo pnet_macros 0.35.0 util/to_little_endian().(ops); |
| 1202 | } |
| 1203 | |
| 1204 | inner_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().size; |
| 1205 | let arg_name = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("arg{}", i); |
| 1206 | inner_accessors = inner_accessors |
| 1207 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&generate_accessor_with_offset_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_with_offset_str().( |
| 1208 | &arg_name[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 1209 | &ty_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 1210 | &co[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 1211 | &ops[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., |
| 1212 | &name[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 1213 | )[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 1214 | inner_mutators = inner_mutators |
| 1215 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&generate_mutator_with_offset_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_mutator_with_offset_str().( |
| 1216 | &arg_name[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()., |
| 1217 | &ty_str[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 1218 | &co[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 1219 | &to_mutatorrust-analyzer cargo pnet_macros 0.35.0 util/to_mutator().(&ops[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., |
| 1220 | &name[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 1221 | )[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 1222 | get_args = |
| 1223 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}get_{}(&self, additional_offset), ", get_args, arg_name); |
| 1224 | set_args = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1225 | "{}set_{}(_self, vals.{}, additional_offset);\n", |
| 1226 | set_args, arg_name, i |
| 1227 | ); |
| 1228 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().size; |
| 1229 | // Current offset needs to be recalculated for each arg |
| 1230 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().co = current_offsetrust-analyzer cargo pnet_macros 0.35.0 decorator/current_offset().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().bit_offset, offset_fns); |
| 1231 | } else { |
| 1232 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 1233 | field.spanrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#span., |
| 1234 | "arguments to #[construct_with] must be primitives", |
| 1235 | )); |
| 1236 | } |
| 1237 | } |
| 1238 | if inner_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 { |
| 1239 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo syn 2.0.119 error/Error#::newrust-analyzer cargo syn 2.0.119 error/impl#[Error]new().( |
| 1240 | field.spanrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#span., |
| 1241 | "types in #[construct_with] for vec must be add up to a multiple of 8 bits", |
| 1242 | )); |
| 1243 | } |
| 1244 | inner_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`DivAssign<Self>`]div_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`DivAssign<Self>`]div_assign().8; // bytes not bits |
| 1245 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().mutators = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1246 | "{mutators} |
| 1247 | /// Set the value of the {name} field. |
| 1248 | #[inline] |
| 1249 | #[allow(trivial_numeric_casts)] |
| 1250 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1251 | pub fn set_{name}(&mut self, vals: &Vec<{inner_ty_str}>) {{ |
| 1252 | use pnet_macros_support::packet::PrimitiveValues; |
| 1253 | let _self = self; |
| 1254 | {inner_mutators} |
| 1255 | let mut additional_offset = 0; |
| 1256 | |
| 1257 | for val in vals.into_iter() {{ |
| 1258 | let vals = val.to_primitive_values(); |
| 1259 | |
| 1260 | {set_args} |
| 1261 | |
| 1262 | additional_offset += {inner_size}; |
| 1263 | }} |
| 1264 | }} |
| 1265 | ", |
| 1266 | mutators = &mutators[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 1267 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 1268 | inner_ty_str = inner_ty_str, |
| 1269 | inner_mutators = inner_mutators, |
| 1270 | //packet_length = field.packet_length.as_ref().unwrap(), |
| 1271 | inner_size = inner_size, |
| 1272 | set_args = set_args |
| 1273 | ); |
| 1274 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().accessors = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1275 | "{accessors} |
| 1276 | /// Get the value of the {name} field |
| 1277 | #[inline] |
| 1278 | #[allow(trivial_numeric_casts)] |
| 1279 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1280 | pub fn get_{name}(&self) -> Vec<{inner_ty_str}> {{ |
| 1281 | let _self = self; |
| 1282 | let length = {packet_length}; |
| 1283 | let vec_length = length.saturating_div({inner_size}); |
| 1284 | let mut vec = Vec::with_capacity(vec_length); |
| 1285 | |
| 1286 | {inner_accessors} |
| 1287 | |
| 1288 | let mut additional_offset = 0; |
| 1289 | |
| 1290 | for vec_offset in 0..vec_length {{ |
| 1291 | vec.push({inner_ty_str}::new({get_args})); |
| 1292 | additional_offset += {inner_size}; |
| 1293 | }} |
| 1294 | |
| 1295 | vec |
| 1296 | }} |
| 1297 | ", |
| 1298 | accessors = accessors, |
| 1299 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 1300 | inner_ty_str = inner_ty_str, |
| 1301 | inner_accessors = inner_accessors, |
| 1302 | packet_length = field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 1303 | inner_size = inner_size, |
| 1304 | get_args = &get_args[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...get_args.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index(). |
| 1305 | ); |
| 1306 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 1307 | } |
| 1308 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().accessors = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{accessors} |
| 1309 | /// Get the value of the {name} field (copies contents) |
| 1310 | #[inline] |
| 1311 | #[allow(trivial_numeric_casts)] |
| 1312 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1313 | pub fn get_{name}(&self) -> Vec<{inner_ty_str}> {{ |
| 1314 | use pnet_macros_support::packet::FromPacket; |
| 1315 | use core::cmp::min; |
| 1316 | let _self = self; |
| 1317 | let current_offset = {co}; |
| 1318 | let end = min(current_offset + {packet_length}, _self.packet.len()); |
| 1319 | |
| 1320 | {inner_ty_str}Iterable {{ |
| 1321 | buf: &_self.packet[current_offset..end] |
| 1322 | }}.map(|packet| packet.from_packet()) |
| 1323 | .collect::<Vec<_>>() |
| 1324 | }} |
| 1325 | |
| 1326 | /// Get the value of the {name} field as iterator |
| 1327 | #[inline] |
| 1328 | #[allow(trivial_numeric_casts)] |
| 1329 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1330 | pub fn get_{name}_iter(&self) -> {inner_ty_str}Iterable {{ |
| 1331 | use core::cmp::min; |
| 1332 | let _self = self; |
| 1333 | let current_offset = {co}; |
| 1334 | let end = min(current_offset + {packet_length}, _self.packet.len()); |
| 1335 | |
| 1336 | {inner_ty_str}Iterable {{ |
| 1337 | buf: &_self.packet[current_offset..end] |
| 1338 | }} |
| 1339 | }} |
| 1340 | ", |
| 1341 | accessors = accessors, |
| 1342 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 1343 | co = co, |
| 1344 | packet_length = field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 1345 | inner_ty_str = inner_ty_str); |
| 1346 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().mutators = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{mutators} |
| 1347 | /// Set the value of the {name} field (copies contents) |
| 1348 | #[inline] |
| 1349 | #[allow(trivial_numeric_casts)] |
| 1350 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1351 | pub fn set_{name}(&mut self, vals: &[{inner_ty_str}]) {{ |
| 1352 | use pnet_macros_support::packet::PacketSize; |
| 1353 | let _self = self; |
| 1354 | let mut current_offset = {co}; |
| 1355 | let end = current_offset + {packet_length}; |
| 1356 | for val in vals.into_iter() {{ |
| 1357 | let mut packet = Mutable{inner_ty_str}Packet::new(&mut _self.packet[current_offset..]).unwrap(); |
| 1358 | packet.populate(val); |
| 1359 | current_offset += packet.packet_size(); |
| 1360 | assert!(current_offset <= end); |
| 1361 | }} |
| 1362 | }} |
| 1363 | ", |
| 1364 | mutators = mutators, |
| 1365 | name = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name., |
| 1366 | co = co, |
| 1367 | packet_length = field.packet_lengthrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#packet_length..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 1368 | inner_ty_str = inner_ty_str); |
| 1369 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1370 | } |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | /// Given a type in the form `u([0-9]+)(be|le)?`, return a tuple of it's size and endianness |
| 1375 | /// |
| 1376 | /// If 1 <= size <= 8, Endianness will be Big. |
| 1377 | fn parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().(ty: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#)> { |
| 1378 | let re = Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#::newrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]new().(r"^u([0-9]+)(be|le|he)?$").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1379 | let iter = match re.captures_iterrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]captures_iter().(ty).nextrust-analyzer cargo regex 1.13.1 regex/string/impl#[`CaptureMatches<'r, 'h>`][Iterator]next().() { |
| 1380 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) => c, |
| 1381 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 1382 | }; |
| 1383 | if iter.lenrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().3 || iter.lenrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().2 { |
| 1384 | let size = iter.getrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]get().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().(); |
| 1385 | let (endianness, has_end) = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e) = iter.getrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Captures<'h>`]get().(2) { |
| 1386 | let e = e.as_strrust-analyzer cargo regex 1.13.1 regex/string/impl#[`Match<'h>`]as_str().(); |
| 1387 | if e rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."be" { |
| 1388 | (Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Yesrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#Yes#) |
| 1389 | } else if e rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."he" { |
| 1390 | (Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Hostrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Host#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Yesrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#Yes#) |
| 1391 | } else { |
| 1392 | (Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Yesrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#Yes#) |
| 1393 | } |
| 1394 | } else { |
| 1395 | (Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Norust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#No#) |
| 1396 | }; |
| 1397 | |
| 1398 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(sz) = size.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() { |
| 1399 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((sz, endianness, has_end)) |
| 1400 | } else { |
| 1401 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 1402 | } |
| 1403 | } else { |
| 1404 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | fn ty_to_stringrust-analyzer cargo pnet_macros 0.35.0 decorator/ty_to_string().(ty: &synrust-analyzer cargo syn 2.0.119 crate/::Typerust-analyzer cargo syn 2.0.119 ty/Type#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1409 | // XXX this inserts extra spaces (ex: "Vec < u8 >") |
| 1410 | let s = quoterust-analyzer cargo quote 1.0.47 quote!!(#ty).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 1411 | s.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(" < ", "<").replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(" > ", ">").replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(" >", ">") |
| 1412 | } |
| 1413 | |
| 1414 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1415 | fn test_parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/test_parse_ty().() { |
| 1416 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1417 | parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().("u8"), |
| 1418 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((8, Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Norust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#No#)) |
| 1419 | ); |
| 1420 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1421 | parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().("u21be"), |
| 1422 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((21, Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Yesrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#Yes#)) |
| 1423 | ); |
| 1424 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1425 | parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().("u21le"), |
| 1426 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((21, Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Yesrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#Yes#)) |
| 1427 | ); |
| 1428 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1429 | parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().("u21he"), |
| 1430 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((21, Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Hostrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Host#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Yesrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#Yes#)) |
| 1431 | ); |
| 1432 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1433 | parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().("u9"), |
| 1434 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((9, Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Norust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#No#)) |
| 1435 | ); |
| 1436 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1437 | parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().("u16"), |
| 1438 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((16, Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big#, EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Norust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#No#)) |
| 1439 | ); |
| 1440 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().("uable"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 1441 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().("u21re"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 1442 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().("i21be"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 1443 | } |
| 1444 | |
| 1445 | fn generate_sop_stringsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_sop_strings().(operations: &[SetOperationrust-analyzer cargo pnet_macros 0.35.0 util/SetOperation#]) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1446 | let mut op_strings = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 1447 | for (idx, sop) in operations.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 1448 | let pkt_replace = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("_self.packet[co + {}]", idx); |
| 1449 | let val_replace = "val"; |
| 1450 | let sop = sop |
| 1451 | .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 1452 | .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("{packet}", &pkt_replace[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().) |
| 1453 | .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("{val}", val_replace); |
| 1454 | op_strings = op_strings rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&sop[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().";\n"; |
| 1455 | } |
| 1456 | |
| 1457 | op_strings |
| 1458 | } |
| 1459 | |
| 1460 | enum AccessorMutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator# { |
| 1461 | Accessorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#Accessor#, |
| 1462 | Mutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#Mutator#, |
| 1463 | } |
| 1464 | |
| 1465 | fn generate_accessor_or_mutator_commentrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_or_mutator_comment().(name: &str, ty: &str, op_type: AccessorMutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1466 | let get_or_set = match op_type { |
| 1467 | AccessorMutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#::Accessorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#Accessor# => "Get", |
| 1468 | AccessorMutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#::Mutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#Mutator# => "Set", |
| 1469 | }; |
| 1470 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((_, endianness, end_specified)) = parse_tyrust-analyzer cargo pnet_macros 0.35.0 decorator/parse_ty().(ty) { |
| 1471 | if end_specified rust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[EndiannessSpecified][`PartialEq<Self>`]eq().==rust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[EndiannessSpecified][`PartialEq<Self>`]eq(). rust-analyzer cargo pnet_macros 0.35.0 decorator/impl#[EndiannessSpecified][`PartialEq<Self>`]eq().EndiannessSpecifiedrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#::Yesrust-analyzer cargo pnet_macros 0.35.0 decorator/EndiannessSpecified#Yes# { |
| 1472 | let return_or_want = match op_type { |
| 1473 | AccessorMutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#::Accessorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#Accessor# => "accessor returns", |
| 1474 | AccessorMutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#::Mutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#Mutator# => "mutator wants", |
| 1475 | }; |
| 1476 | let endian_str = match endianness { |
| 1477 | Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Bigrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Big# => "big-endian", |
| 1478 | Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Littlerust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Little# => "little-endian", |
| 1479 | Endiannessrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#::Hostrust-analyzer cargo pnet_macros 0.35.0 util/Endianness#Host# => "host-endian", |
| 1480 | }; |
| 1481 | |
| 1482 | return formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1483 | "/// {get_or_set} the {name} field. This field is always stored {endian} |
| 1484 | /// within the struct, but this {return_or_want} host order.", |
| 1485 | get_or_set = get_or_set, |
| 1486 | name = name, |
| 1487 | endian = endian_str, |
| 1488 | return_or_want = return_or_want |
| 1489 | ); |
| 1490 | } |
| 1491 | } |
| 1492 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1493 | "/// {get_or_set} the {name} field.", |
| 1494 | get_or_set = get_or_set, |
| 1495 | name = name |
| 1496 | ) |
| 1497 | } |
| 1498 | |
| 1499 | /// Given the name of a field, and a set of operations required to set that field, return |
| 1500 | /// the Rust code required to set the field |
| 1501 | fn generate_mutator_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_mutator_str().( |
| 1502 | name: &str, |
| 1503 | ty: &str, |
| 1504 | offset: &str, |
| 1505 | operations: &[SetOperationrust-analyzer cargo pnet_macros 0.35.0 util/SetOperation#], |
| 1506 | inner: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>, |
| 1507 | ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1508 | let op_strings = generate_sop_stringsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_sop_strings().(operations); |
| 1509 | |
| 1510 | let mutator = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(struct_name) = inner { |
| 1511 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1512 | "#[inline] |
| 1513 | #[allow(trivial_numeric_casts)] |
| 1514 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1515 | fn set_{name}(_self: &mut {struct_name}, val: {ty}) {{ |
| 1516 | let co = {co}; |
| 1517 | {operations} |
| 1518 | }}", |
| 1519 | struct_name = struct_name, |
| 1520 | name = name, |
| 1521 | ty = ty, |
| 1522 | co = offset, |
| 1523 | operations = op_strings |
| 1524 | ) |
| 1525 | } else { |
| 1526 | let comment = generate_accessor_or_mutator_commentrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_or_mutator_comment().(name, ty, AccessorMutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#::Mutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#Mutator#); |
| 1527 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1528 | "{comment} |
| 1529 | #[inline] |
| 1530 | #[allow(trivial_numeric_casts)] |
| 1531 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1532 | pub fn set_{name}(&mut self, val: {ty}) {{ |
| 1533 | let _self = self; |
| 1534 | let co = {co}; |
| 1535 | {operations} |
| 1536 | }}", |
| 1537 | comment = comment, |
| 1538 | name = name, |
| 1539 | ty = ty, |
| 1540 | co = offset, |
| 1541 | operations = op_strings |
| 1542 | ) |
| 1543 | }; |
| 1544 | |
| 1545 | mutator |
| 1546 | } |
| 1547 | |
| 1548 | fn generate_mutator_with_offset_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_mutator_with_offset_str().( |
| 1549 | name: &str, |
| 1550 | ty: &str, |
| 1551 | offset: &str, |
| 1552 | operations: &[SetOperationrust-analyzer cargo pnet_macros 0.35.0 util/SetOperation#], |
| 1553 | inner: &str, |
| 1554 | ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1555 | let op_strings = generate_sop_stringsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_sop_strings().(operations); |
| 1556 | |
| 1557 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1558 | "#[inline] |
| 1559 | #[allow(trivial_numeric_casts)] |
| 1560 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1561 | fn set_{name}(_self: &mut {struct_name}, val: {ty}, offset: usize) {{ |
| 1562 | let co = {co} + offset; |
| 1563 | {operations} |
| 1564 | }}", |
| 1565 | struct_name = inner, |
| 1566 | name = name, |
| 1567 | ty = ty, |
| 1568 | co = offset, |
| 1569 | operations = op_strings |
| 1570 | ) |
| 1571 | } |
| 1572 | |
| 1573 | /// Used to turn something like a u16be into |
| 1574 | /// "let b0 = ((_self.packet[co + 0] as u16be) << 8) as u16be; |
| 1575 | /// let b1 = ((_self.packet[co + 1] as u16be) as u16be; |
| 1576 | /// b0 | b1" |
| 1577 | fn generate_accessor_op_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_op_str().(name: &str, ty: &str, operations: &[GetOperationrust-analyzer cargo pnet_macros 0.35.0 util/GetOperation#]) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1578 | fn build_returnrust-analyzer cargo pnet_macros 0.35.0 decorator/build_return().(max: usize) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1579 | let mut ret = "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 1580 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#max { |
| 1581 | ret = ret rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("b{} | ", i)[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 1582 | } |
| 1583 | let new_len = ret.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().3; |
| 1584 | ret.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]truncate().(new_len); |
| 1585 | |
| 1586 | ret |
| 1587 | } |
| 1588 | |
| 1589 | let op_strings = if operations.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 { |
| 1590 | let replacement_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("({}[co] as {})", name, ty); |
| 1591 | operations |
| 1592 | .firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().() |
| 1593 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 1594 | .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 1595 | .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("{}", &replacement_str[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().) |
| 1596 | } else { |
| 1597 | let mut op_strings = "".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 1598 | for (idx, operation) in operations.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 1599 | let replacement_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("({}[co + {}] as {})", name, idx, ty); |
| 1600 | let operation = operation.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("{}", &replacement_str[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().); |
| 1601 | op_strings = op_strings rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("let b{} = ({}) as {};\n", idx, operation, ty)[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 1602 | } |
| 1603 | op_strings = op_strings rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("\n{}\n", build_returnrust-analyzer cargo pnet_macros 0.35.0 decorator/build_return().(operations.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()))[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 1604 | |
| 1605 | op_strings |
| 1606 | }; |
| 1607 | |
| 1608 | op_strings |
| 1609 | } |
| 1610 | |
| 1611 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1612 | fn test_generate_accessor_op_strrust-analyzer cargo pnet_macros 0.35.0 decorator/test_generate_accessor_op_str().() { |
| 1613 | { |
| 1614 | let ops = operationsrust-analyzer cargo pnet_macros 0.35.0 util/operations().(0, 24).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1615 | let result = generate_accessor_op_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_op_str().("test", "u24be", &ops); |
| 1616 | let expected = "let b0 = ((test[co + 0] as u24be) << 16) as u24be;\n\ |
| 1617 | let b1 = ((test[co + 1] as u24be) << 8) as u24be;\n\ |
| 1618 | let b2 = ((test[co + 2] as u24be)) as u24be;\n\n\ |
| 1619 | b0 | b1 | b2\n"; |
| 1620 | |
| 1621 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, expected); |
| 1622 | } |
| 1623 | |
| 1624 | { |
| 1625 | let ops = operationsrust-analyzer cargo pnet_macros 0.35.0 util/operations().(0, 16).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1626 | let result = generate_accessor_op_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_op_str().("test", "u16be", &ops); |
| 1627 | let expected = "let b0 = ((test[co + 0] as u16be) << 8) as u16be;\n\ |
| 1628 | let b1 = ((test[co + 1] as u16be)) as u16be;\n\n\ |
| 1629 | b0 | b1\n"; |
| 1630 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, expected); |
| 1631 | } |
| 1632 | |
| 1633 | { |
| 1634 | let ops = operationsrust-analyzer cargo pnet_macros 0.35.0 util/operations().(0, 8).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1635 | let result = generate_accessor_op_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_op_str().("test", "u8", &ops); |
| 1636 | let expected = "(test[co] as u8)"; |
| 1637 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, expected); |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | /// Given the name of a field, and a set of operations required to get the value of that field, |
| 1642 | /// return the Rust code required to get the field. |
| 1643 | #[inline] |
| 1644 | fn generate_accessor_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_str().( |
| 1645 | name: &str, |
| 1646 | ty: &str, |
| 1647 | offset: &str, |
| 1648 | operations: &[GetOperationrust-analyzer cargo pnet_macros 0.35.0 util/GetOperation#], |
| 1649 | inner: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>, |
| 1650 | ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1651 | let op_strings = generate_accessor_op_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_op_str().("_self.packet", ty, operations); |
| 1652 | |
| 1653 | let accessor = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(struct_name) = inner { |
| 1654 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1655 | "#[inline(always)] |
| 1656 | #[allow(trivial_numeric_casts, unused_parens)] |
| 1657 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1658 | fn get_{name}(_self: &{struct_name}) -> {ty} {{ |
| 1659 | let co = {co}; |
| 1660 | {operations} |
| 1661 | }}", |
| 1662 | struct_name = struct_name, |
| 1663 | name = name, |
| 1664 | ty = ty, |
| 1665 | co = offset, |
| 1666 | operations = op_strings |
| 1667 | ) |
| 1668 | } else { |
| 1669 | let comment = generate_accessor_or_mutator_commentrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_or_mutator_comment().(name, ty, AccessorMutatorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#::Accessorrust-analyzer cargo pnet_macros 0.35.0 decorator/AccessorMutator#Accessor#); |
| 1670 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1671 | "{comment} |
| 1672 | #[inline] |
| 1673 | #[allow(trivial_numeric_casts, unused_parens)] |
| 1674 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1675 | pub fn get_{name}(&self) -> {ty} {{ |
| 1676 | let _self = self; |
| 1677 | let co = {co}; |
| 1678 | {operations} |
| 1679 | }}", |
| 1680 | comment = comment, |
| 1681 | name = name, |
| 1682 | ty = ty, |
| 1683 | co = offset, |
| 1684 | operations = op_strings |
| 1685 | ) |
| 1686 | }; |
| 1687 | |
| 1688 | accessor |
| 1689 | } |
| 1690 | |
| 1691 | #[inline] |
| 1692 | fn generate_accessor_with_offset_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_with_offset_str().( |
| 1693 | name: &str, |
| 1694 | ty: &str, |
| 1695 | offset: &str, |
| 1696 | operations: &[GetOperationrust-analyzer cargo pnet_macros 0.35.0 util/GetOperation#], |
| 1697 | inner: &str, |
| 1698 | ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1699 | let op_strings = generate_accessor_op_strrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_accessor_op_str().("_self.packet", ty, operations); |
| 1700 | |
| 1701 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1702 | "#[inline(always)] |
| 1703 | #[allow(trivial_numeric_casts, unused_parens)] |
| 1704 | #[cfg_attr(feature = \"clippy\", allow(used_underscore_binding))] |
| 1705 | fn get_{name}(_self: &{struct_name}, offset: usize) -> {ty} {{ |
| 1706 | let co = {co} + offset; |
| 1707 | {operations} |
| 1708 | }}", |
| 1709 | struct_name = inner, |
| 1710 | name = name, |
| 1711 | ty = ty, |
| 1712 | co = offset, |
| 1713 | operations = op_strings |
| 1714 | ) |
| 1715 | } |
| 1716 | |
| 1717 | #[inline] |
| 1718 | fn current_offsetrust-analyzer cargo pnet_macros 0.35.0 decorator/current_offset().(bit_offset: usize, offset_fns: &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#]) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1719 | let base_offset = bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().8; |
| 1720 | |
| 1721 | offset_fns |
| 1722 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 1723 | .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]fold().(base_offset.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |a, b| a rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add()." + " rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&b[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 1724 | } |
| 1725 | |
| 1726 | #[inline] |
| 1727 | fn generate_get_fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/generate_get_fields().(packet: &Packetrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 1728 | let mut gets = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 1729 | |
| 1730 | for field in &packet.fieldsrust-analyzer cargo pnet_macros 0.35.0 decorator/Packet#fields. { |
| 1731 | if field.is_payloadrust-analyzer cargo pnet_macros 0.35.0 decorator/Field#is_payload. { |
| 1732 | gets = gets |
| 1733 | +rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 1734 | "{field} : {{ |
| 1735 | let payload = self.payload(); |
| 1736 | let mut vec = Vec::with_capacity(payload.len()); |
| 1737 | vec.extend_from_slice(payload); |
| 1738 | |
| 1739 | vec |
| 1740 | }},\n", |
| 1741 | field = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name. |
| 1742 | )[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index(). |
| 1743 | } else { |
| 1744 | gets = gets rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{field} : _self.get_{field}(),\n", field = field.namerust-analyzer cargo pnet_macros 0.35.0 decorator/Field#name.)[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index(). |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | gets |
| 1749 | } |