Commit graph

20 commits

Author SHA1 Message Date
Jonas Schäfer
84de7fc248 xso-proc: add support for namespaced attributes 2024-06-24 12:39:32 +02:00
Jonas Schäfer
219d682295 xso-proc: add support for renaming attributes
This is akin to `#[serde(rename = ..)]` and thus useful.
2024-06-24 11:33:10 +02:00
Jonas Schäfer
212c5c4a83 xso-proc: add support for parsing attributes into Strings
This is bare-bones and is missing many features which we intend to add
in future commits, such as parsing from attributes whose names differ
from the field names and parsing into non-String types.
2024-06-24 11:33:10 +02:00
Jonas Schäfer
183bef5cf6 xso-proc: completely overengineer everything for no good reason!
Well, not really, of course. All of this will make sense once we start
adding support for fields and non-struct types. Refactoring the code now
before we start to add actual member field parsing is much easier.

How do I know that this will work out? Well, my crystal ball knows it.
Don't believe me? Okay, ChatGPT told me ... Alright alright, I went
through the entire process of implementing this feature *twice* at this
point and have a pretty good idea of where to draw the abstraction lines
so that everything falls neatly into place. You'll have to trust me on
this one.

(Or, you know, check out old branches in my xmpp-rs repo. That might
work, too. `feature/derive-macro-streaming-full` might be a name to look
for if you dare.)
2024-06-23 18:43:34 +02:00
Jonas Schäfer
2efef5ceeb xso-proc: add support for string literals for namespaces
Makes it easier to use ad-hoc.
2024-06-23 12:40:18 +02:00
Jonas Schäfer
4d1166b66d xso-proc: allow paths as XML names
Not sure if this is something useful to have, but it feels consistent
with `namespace`.
2024-06-23 12:40:18 +02:00
Jonas Schäfer
bc785fde28 parsers: replace generate_empty_element with derive 2024-06-23 12:20:02 +02:00
Jonas Schäfer
0adfd1218b xso-proc: start making derive macros for FromXml and IntoXml
For now, these macros only support empty elements. Everything else will
be rejected with a compile-time error.
2024-06-23 12:20:02 +02:00
Jonas Schäfer
6ef8dbefa3 parsers: use Error type from xso
This is a large change and as such, it needs good motivation. Let me
remind you of the ultimate goal: we want a derive macro which allows us
to FromXml/IntoXml, and that derive macro should be usable from
`xmpp_parsers` and other crates.

For that, any code generated by the derive macro mustn't depend on any
code in the `xmpp_parsers` crate, because you cannot name the crate you
are in portably (`xmpp_parsers::..` wouldn't resolve within
`xmpp_parsers`, and `crate::..` would point at other crates if the macro
was used in other crates).

We also want to interoperate with code already implementing
`TryFrom<Element>` and `Into<Element>` on structs. This ultimately
requires that we have an error type which is shared by the two
implementations and that error type must be declared in the `xso` crate
to be usable by the macros.

Thus, we port the error type over to use the type declared in `xso`.

This changes the structure of the error type greatly; I do not think
that `xso` should have to know about all the different types we are
parsing there and they don't deserve special treatment. Wrapping them in
a `Box<dyn ..>` seems more appropriate.
2024-06-23 09:40:52 +02:00
Jonas Schäfer
cb3da52ba2 parsers: add streamable parsing
This adds shims which provide FromXml and IntoXml implementations to
*all* macro-generated types in `xmpp_parsers`. Mind that this does not
cover all types in `xmpp_parsers`, but a good share of them.

This is another first step toward real, fully streamed parsing.
2024-06-18 16:54:11 +02:00
Jonas Schäfer
2f7d5edb8a Make TryFrom<Element> chainable
This allows constructs like:

```rust
let residual = match Iq::try_from(stanza) {
  Ok(iq) => return handle_iq(..),
  Err(Error::TypeMismatch(_, _, v)) => v,
  Err(other) => return handle_parse_error(..),
};
let residual = match Message::try_from(stanza) {
  ..
};
let residual = ..
log::warn!("unhandled object: {:?}", residual);
```

The interesting part of this is that this could be used in a loop over a
Vec<Box<dyn FnMut(Element) -> ControlFlow<SomeResult, Element>>, i.e. in
a parsing loop for a generic XML/XMPP stream.

The advantage is that the stanza.is() check runs only once (in
check_self!) and doesn't need to be duplicated outside, and it reduces
the use of magic strings.
2024-03-03 14:50:29 +00:00
Jonas Schäfer
3b3a4ff0c8 Do not .clone() Element in code generated with generate_element
This should improve performance a little.
2024-03-03 15:05:11 +01:00
Werner Kroneman
18cb6f6e2d Refactored the "helpers" so that they use a common Codec trait; this makes them composable as well. 2024-01-10 19:49:53 +00:00
Emmanuel Gil Peyrot
3f90e84c5b xmpp-parsers: Add a hexadecimal codec
That one accepts both uppercase and lowercase hexadecimal input, and
outputs in lowercase.

It requires no separator between bytes, unlike ColonSeparatedHex.
2024-01-05 17:36:43 +01:00
b522eaf7f3 parsers: clippy pass
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2023-12-15 19:26:06 +00:00
Emmanuel Gil Peyrot
4460a59bc8 xmpp-parsers: XEP-0257: Correctly serialise no-cert-management
This element was previously always put in the generated element.
2023-09-05 17:08:30 +02:00
Emmanuel Gil Peyrot
022a920300 xmpp-parsers: Update to the new jid crate 2023-06-20 18:59:26 +02:00
Emmanuel Gil Peyrot
2955a0fe60 parsers: Bump base64
Version 0.21 replaced base64::decode() with an Engine trait and multiple
structs implementing it for various alphabets, various performance
profiles, etc.  It is slightly longer to import but in the end does the
very same thing.
2023-04-03 11:28:41 +02:00
Emmanuel Gil Peyrot
9e9f484bd9 xmpp-parsers: Simplify trailing comma handling in macros
Since Rust 1.32.0 (so basically forever ago) we can use the $(…)?
construct in macros to mean one or zero times this chunk of tokens.
This allows making the last comma optional in lists of things.
2022-03-22 15:59:00 +01:00
Emmanuel Gil Peyrot
9410849d7a Rename the xmpp-parsers directory to parsers
This doesn’t change anything to the name of the crate, just makes
autocompletion easier by not sharing the same prefix as the xmpp crate.
2021-10-11 08:24:16 +02:00