ibb: Add documentation.

This commit is contained in:
Emmanuel Gil Peyrot 2018-07-02 13:47:32 +02:00
parent 75d5bd3665
commit 5f2062483a
2 changed files with 39 additions and 9 deletions

View file

@ -4,37 +4,65 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#![deny(missing_docs)]
use helpers::Base64; use helpers::Base64;
use iq::IqSetPayload; use iq::IqSetPayload;
generate_id!(StreamId); generate_id!(
/// An identifier matching a stream.
StreamId);
generate_attribute!(Stanza, "stanza", { generate_attribute!(
/// Which stanza type to use to exchange data.
Stanza, "stanza", {
/// `<iq/>` gives a feedback on whether the chunk has been received or not,
/// which is useful in the case the recipient might not receive them in a
/// timely manner, or to do your own throttling based on the results.
Iq => "iq", Iq => "iq",
/// `<message/>` can be faster, since it doesnt require any feedback, but in
/// practice it will be throttled by the servers on the way.
Message => "message", Message => "message",
}, Default = Iq); }, Default = Iq);
generate_element!(Open, "open", IBB, generate_element!(
/// Starts an In-Band Bytestream session with the given parameters.
Open, "open", IBB,
attributes: [ attributes: [
/// Maximum size in bytes for each chunk.
block_size: u16 = "block-size" => required, block_size: u16 = "block-size" => required,
/// The identifier to be used to create a stream.
sid: StreamId = "sid" => required, sid: StreamId = "sid" => required,
/// Which stanza type to use to exchange data.
stanza: Stanza = "stanza" => default, stanza: Stanza = "stanza" => default,
]); ]);
impl IqSetPayload for Open {} impl IqSetPayload for Open {}
generate_element_with_text!(Data, "data", IBB, generate_element_with_text!(
/// Exchange a chunk of data in an open stream.
Data, "data", IBB,
[ [
/// Sequence number of this chunk, must wraparound after 65535.
seq: u16 = "seq" => required, seq: u16 = "seq" => required,
/// The identifier of the stream on which data is being exchanged.
sid: StreamId = "sid" => required sid: StreamId = "sid" => required
], ],
/// Vector of bytes to be exchanged.
data: Base64<Vec<u8>> data: Base64<Vec<u8>>
); );
impl IqSetPayload for Data {} impl IqSetPayload for Data {}
generate_element!(Close, "close", IBB, generate_element!(
/// Close an open stream.
Close, "close", IBB,
attributes: [ attributes: [
/// The identifier of the stream to be closed.
sid: StreamId = "sid" => required, sid: StreamId = "sid" => required,
]); ]);

View file

@ -286,7 +286,8 @@ macro_rules! generate_empty_element {
} }
macro_rules! generate_id { macro_rules! generate_id {
($elem:ident) => ( ($(#[$meta:meta])* $elem:ident) => (
$(#[$meta])*
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct $elem(pub String); pub struct $elem(pub String);
impl ::std::str::FromStr for $elem { impl ::std::str::FromStr for $elem {
@ -338,10 +339,10 @@ macro_rules! generate_elem_id {
} }
macro_rules! generate_element_with_text { macro_rules! generate_element_with_text {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, $text_ident:ident: $codec:ident < $text_type:ty >) => ( ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, $(#[$text_meta:meta])* $text_ident:ident: $codec:ident < $text_type:ty >) => (
generate_element_with_text!($(#[$meta])* $elem, $name, $ns, [], $text_ident: $codec<$text_type>); generate_element_with_text!($(#[$meta])* $elem, $name, $ns, [], $(#[$text_meta])* $text_ident: $codec<$text_type>);
); );
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),*], $text_ident:ident: $codec:ident < $text_type:ty >) => ( ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),*], $(#[$text_meta:meta])* $text_ident:ident: $codec:ident < $text_type:ty >) => (
$(#[$meta])* $(#[$meta])*
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct $elem { pub struct $elem {
@ -349,6 +350,7 @@ macro_rules! generate_element_with_text {
$(#[$attr_meta])* $(#[$attr_meta])*
pub $attr: $attr_type, pub $attr: $attr_type,
)* )*
$(#[$text_meta])*
pub $text_ident: $text_type, pub $text_ident: $text_type,
} }