Skip to content

Commit 7e98989

Browse files
API Review feedback; fixed a bunch of type documentation; reduced type visibility in public API surface. (Azure#2100)
* Moved public AMQP types to the root of AMQP; fixed a bunch of type documentation * Refactored ProducerClient and ConsumerClient to use builder pattern.
1 parent beff652 commit 7e98989

28 files changed

+807
-760
lines changed

sdk/core/azure_core_amqp/examples/connection.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
// cargo run --example connection --package azure_core_amqp
1414

1515
use azure_core::Url;
16-
use azure_core_amqp::{
17-
connection::{AmqpConnection, AmqpConnectionApis},
18-
value::AmqpSymbol,
19-
};
16+
use azure_core_amqp::{AmqpConnection, AmqpConnectionApis, AmqpSymbol};
2017

2118
async fn amqp_connection_open() {
2219
let connection = AmqpConnection::new();

sdk/core/azure_core_amqp/src/fe2o3/messaging/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All Rights reserved
22
// Licensed under the MIT license.
33

4-
pub mod message_fields;
5-
pub mod message_source;
6-
pub mod message_target;
7-
pub mod messaging_types;
4+
pub(crate) mod message_fields;
5+
pub(crate) mod message_source;
6+
pub(crate) mod message_target;
7+
pub(crate) mod messaging_types;
88

99
use crate::{
1010
messaging::{AmqpMessage, AmqpMessageBody},
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All Rights reserved
22
// Licensed under the MIT license.
3-
pub mod cbs;
4-
pub mod connection;
5-
pub mod error;
6-
pub mod management;
7-
pub mod messaging;
8-
pub mod receiver;
9-
pub mod sender;
10-
pub mod session;
11-
pub mod value;
3+
pub(crate) mod cbs;
4+
pub(crate) mod connection;
5+
pub(crate) mod error;
6+
pub(crate) mod management;
7+
pub(crate) mod messaging;
8+
pub(crate) mod receiver;
9+
pub(crate) mod sender;
10+
pub(crate) mod session;
11+
pub(crate) mod value;

sdk/core/azure_core_amqp/src/fe2o3/value.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ impl From<AmqpValue> for fe2o3_amqp_types::primitives::Value {
203203
#[cfg(feature = "cplusplus")]
204204
AmqpValue::Composite(d) => fe2o3_amqp_types::primitives::Value::Described(Box::new(
205205
serde_amqp::described::Described {
206-
descriptor: d.descriptor.clone().into(),
207-
value: d.value.clone().into(),
206+
descriptor: d.descriptor().clone().into(),
207+
value: d.value().clone().into(),
208208
},
209209
)),
210210
AmqpValue::Described(d) => fe2o3_amqp_types::primitives::Value::Described(Box::new(
211211
serde_amqp::described::Described {
212-
descriptor: d.descriptor.clone().into(),
213-
value: d.value.clone().into(),
212+
descriptor: d.descriptor().clone().into(),
213+
value: d.value().clone().into(),
214214
},
215215
)),
216216
AmqpValue::Unknown => todo!(),
@@ -268,7 +268,7 @@ impl From<fe2o3_amqp_types::primitives::Value> for AmqpValue {
268268
AmqpDescriptor::Name(symbol.into())
269269
}
270270
};
271-
AmqpValue::Described(Box::new(AmqpDescribed { descriptor, value }))
271+
AmqpValue::Described(Box::new(AmqpDescribed::new(descriptor, value)))
272272
}
273273
fe2o3_amqp_types::primitives::Value::Decimal128(_) => todo!(),
274274
fe2o3_amqp_types::primitives::Value::Decimal32(_) => todo!(),
@@ -281,7 +281,7 @@ impl PartialEq<AmqpDescribed>
281281
for serde_amqp::described::Described<fe2o3_amqp_types::primitives::Value>
282282
{
283283
fn eq(&self, other: &AmqpDescribed) -> bool {
284-
self.descriptor == other.descriptor && self.value == other.value
284+
self.descriptor == *other.descriptor() && self.value == *other.value()
285285
}
286286
}
287287

sdk/core/azure_core_amqp/src/lib.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@ mod fe2o3;
55
#[cfg(any(not(feature = "fe2o3-amqp"), target_arch = "wasm32"))]
66
mod noop;
77

8-
pub mod cbs;
9-
pub mod connection;
10-
pub mod error;
11-
pub mod management;
12-
pub mod messaging;
13-
pub mod receiver;
14-
pub mod sender;
15-
pub mod session;
16-
pub mod value;
17-
18-
pub use uuid::Uuid;
8+
pub(crate) mod cbs;
9+
pub(crate) mod connection;
10+
pub(crate) mod error;
11+
pub(crate) mod management;
12+
pub(crate) mod messaging;
13+
pub(crate) mod receiver;
14+
pub(crate) mod sender;
15+
pub(crate) mod session;
16+
pub(crate) mod value;
1917

18+
pub use cbs::{AmqpClaimsBasedSecurity, AmqpClaimsBasedSecurityApis};
19+
pub use connection::{AmqpConnection, AmqpConnectionApis, AmqpConnectionOptions};
20+
pub use error::Error;
21+
pub use management::{AmqpManagement, AmqpManagementApis};
22+
pub use messaging::{
23+
AmqpAnnotationKey, AmqpAnnotations, AmqpDelivery, AmqpDeliveryApis, AmqpMessage,
24+
AmqpMessageBody, AmqpMessageHeader, AmqpMessageId, AmqpMessageProperties, AmqpSource,
25+
AmqpSourceFilter, AmqpTarget,
26+
};
27+
pub use receiver::{AmqpReceiver, AmqpReceiverApis, AmqpReceiverOptions, ReceiverCreditMode};
28+
pub use sender::{AmqpSendOptions, AmqpSender, AmqpSenderApis, AmqpSenderOptions};
29+
pub use session::{AmqpSession, AmqpSessionApis, AmqpSessionOptions};
2030
use std::fmt::Debug;
31+
pub use uuid::Uuid;
32+
pub use value::{AmqpDescribed, AmqpList, AmqpOrderedMap, AmqpSymbol, AmqpTimestamp, AmqpValue};
2133

2234
// AMQP Settle mode:
2335
// https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-sender-settle-mode

sdk/core/azure_core_amqp/src/messaging.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ impl AmqpMessage {
10811081
/// # Examples
10821082
///
10831083
/// ```
1084-
/// use azure_core_amqp::messaging::AmqpMessage;
1084+
/// use azure_core_amqp::AmqpMessage;
10851085
///
10861086
/// let mut message = AmqpMessage::default();
10871087
/// message.set_message_id(uuid::Uuid::new_v4());
@@ -1110,8 +1110,8 @@ impl AmqpMessage {
11101110
///
11111111
/// # Examples
11121112
/// ```
1113-
/// use azure_core_amqp::messaging::AmqpMessage;
1114-
/// use azure_core_amqp::value::AmqpSymbol;
1113+
/// use azure_core_amqp::AmqpMessage;
1114+
/// use azure_core_amqp::AmqpSymbol;
11151115
/// let mut message = AmqpMessage::default();
11161116
/// message.add_message_annotation(AmqpSymbol::from("key"), "value");
11171117
/// ```
@@ -1138,8 +1138,8 @@ impl AmqpMessage {
11381138
/// # Examples
11391139
///
11401140
/// ```
1141-
/// use azure_core_amqp::messaging::AmqpMessage;
1142-
/// use azure_core_amqp::messaging::AmqpMessageBody;
1141+
/// use azure_core_amqp::AmqpMessage;
1142+
/// use azure_core_amqp::AmqpMessageBody;
11431143
///
11441144
/// let mut message = AmqpMessage::default();
11451145
/// message.set_message_body(AmqpMessageBody::Value("Hello, world!".into()));
@@ -1229,7 +1229,7 @@ impl Deserializable<AmqpMessage> for AmqpMessage {
12291229
}
12301230
}
12311231

1232-
pub mod builders {
1232+
mod builders {
12331233
use super::*;
12341234

12351235
pub struct AmqpSourceBuilder {

sdk/core/azure_core_amqp/src/value.rs

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ use crate::{Deserializable, Serializable};
1616
#[cfg(feature = "cplusplus")]
1717
use azure_core::Result;
1818

19+
/// An AMQP symbol.
20+
///
21+
/// Symbols are used to identify a type of data. They are similar to strings, and represent symbolic values from a constrained domain.
1922
#[derive(Debug, PartialEq, Clone, Default, Eq)]
2023
pub struct AmqpSymbol(pub String);
2124

22-
// impl PartialEq<str> for AmqpSymbol {
23-
// fn eq(&self, other: &str) -> bool {
24-
// self.0.as_str() == other
25-
// }
26-
// }
27-
2825
impl PartialEq<AmqpSymbol> for str {
2926
fn eq(&self, other: &AmqpSymbol) -> bool {
3027
self == other.0.as_str()
@@ -77,6 +74,7 @@ impl Borrow<str> for AmqpSymbol {
7774
}
7875
}
7976

77+
/// A sequence of AMQP values
8078
#[derive(Debug, PartialEq, Clone, Default)]
8179
pub struct AmqpList(pub Vec<AmqpValue>);
8280

@@ -132,6 +130,10 @@ impl From<std::time::SystemTime> for AmqpTimestamp {
132130
}
133131
}
134132

133+
/// An ordered mapping from distinct keys to values.
134+
///
135+
/// This is a simple implementation of a map that is backed by a vector.
136+
/// It is not intended to be used for large maps, but rather for small maps where the order of the keys is important.
135137
#[derive(Debug, PartialEq, Clone, Default)]
136138
pub struct AmqpOrderedMap<K, V>
137139
where
@@ -164,8 +166,8 @@ where
164166

165167
#[derive(Debug, PartialEq, Clone)]
166168
pub struct AmqpDescribed {
167-
pub descriptor: AmqpDescriptor,
168-
pub value: AmqpValue,
169+
descriptor: AmqpDescriptor,
170+
value: AmqpValue,
169171
}
170172

171173
impl AmqpDescribed {
@@ -185,12 +187,18 @@ impl AmqpDescribed {
185187
}
186188
}
187189

190+
/// An AMQP Composite type.
191+
/// This is a complex type that is composed of a descriptor and a value.
192+
/// The descriptor is used to identify the type of the value.
193+
/// The value is the actual value.
188194
#[derive(Debug, PartialEq, Clone)]
195+
#[cfg(feature = "cplusplus")]
189196
pub struct AmqpComposite {
190-
pub descriptor: AmqpDescriptor,
191-
pub value: AmqpList,
197+
descriptor: AmqpDescriptor,
198+
value: AmqpList,
192199
}
193200

201+
#[cfg(feature = "cplusplus")]
194202
impl AmqpComposite {
195203
pub fn new(descriptor: impl Into<AmqpDescriptor>, value: impl Into<AmqpList>) -> Self {
196204
Self {
@@ -212,26 +220,48 @@ impl AmqpComposite {
212220
pub enum AmqpValue {
213221
#[default]
214222
Null,
223+
/// A boolean (true/false) value.
215224
Boolean(bool),
225+
/// An unsigned byte value.
216226
UByte(u8),
227+
/// An unsigned short value.
217228
UShort(u16),
229+
/// An unsigned integer value.
218230
UInt(u32),
231+
/// An unsigned long value.
219232
ULong(u64),
233+
/// A signed byte value.
220234
Byte(i8),
235+
/// A signed short value.
221236
Short(i16),
237+
/// A signed integer value.
222238
Int(i32),
239+
/// A signed long value.
223240
Long(i64),
241+
/// A 32-bit floating point value.
224242
Float(f32),
243+
/// A 64-bit floating point value.
225244
Double(f64),
245+
/// A single Unicode character.
226246
Char(char),
247+
/// A point in time.
227248
TimeStamp(AmqpTimestamp),
249+
/// A universally unique identifier.
228250
Uuid(Uuid),
251+
/// A sequence of octets.
229252
Binary(Vec<u8>),
253+
/// A sequence of Unicode characters.
230254
String(String),
255+
/// An AMQP Symbol.
231256
Symbol(AmqpSymbol),
257+
258+
/// An ordered list of AMQP values.
232259
List(AmqpList),
260+
/// An ordered map of AMQP values.
233261
Map(AmqpOrderedMap<AmqpValue, AmqpValue>),
262+
/// An array of AMQP values.
234263
Array(Vec<AmqpValue>),
264+
/// A described value.
235265
Described(Box<AmqpDescribed>),
236266
#[cfg(feature = "cplusplus")]
237267
Composite(Box<AmqpComposite>),
@@ -509,7 +539,6 @@ where
509539
mod tests {
510540
use super::*;
511541
use std::vec;
512-
use Uuid;
513542

514543
#[test]
515544
fn test_value_create_specific() {
@@ -889,4 +918,16 @@ mod tests {
889918
assert_eq!(unknown_value, AmqpValue::Unknown);
890919
assert_eq!(AmqpValue::Unknown, unknown_value);
891920
}
921+
922+
#[test]
923+
#[cfg(feature = "cplusplus")]
924+
fn amqp_composite() {
925+
let composite =
926+
AmqpComposite::new(0x270, AmqpList::from(vec![AmqpValue::from("String value")]));
927+
assert_eq!(composite.descriptor(), &AmqpDescriptor::Code(0x270));
928+
assert_eq!(
929+
composite.value(),
930+
&AmqpList::from(vec![AmqpValue::from("String value")])
931+
);
932+
}
892933
}

0 commit comments

Comments
 (0)