Skip to content

Commit 9b38aea

Browse files
authored
Add AttributeValue::Binary; align order of AttributeValue with spec (#238)
Signed-off-by: Bobby Calderwood <[email protected]>
1 parent f9dde9d commit 9b38aea

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/event/attributes.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ use url::Url;
1111
/// This represents the types defined in the [CloudEvent spec type system](https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system)
1212
#[derive(Debug, PartialEq, Eq)]
1313
pub enum AttributeValue<'a> {
14-
SpecVersion(SpecVersion),
14+
Boolean(&'a bool),
15+
Integer(&'a i64),
1516
String(&'a str),
17+
Binary(&'a [u8]),
1618
URI(&'a Url),
1719
URIRef(&'a UriReference),
18-
Boolean(&'a bool),
19-
Integer(&'a i64),
2020
Time(&'a DateTime<Utc>),
21+
SpecVersion(SpecVersion),
2122
}
2223

2324
impl<'a> From<&'a ExtensionValue> for AttributeValue<'a> {
@@ -33,13 +34,14 @@ impl<'a> From<&'a ExtensionValue> for AttributeValue<'a> {
3334
impl fmt::Display for AttributeValue<'_> {
3435
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3536
match self {
36-
AttributeValue::SpecVersion(s) => s.fmt(f),
37+
AttributeValue::Boolean(b) => f.serialize_bool(**b),
38+
AttributeValue::Integer(i) => f.serialize_i64(**i),
3739
AttributeValue::String(s) => f.write_str(s),
40+
AttributeValue::Binary(b) => f.write_str(&base64::encode(b)),
3841
AttributeValue::URI(s) => f.write_str(s.as_str()),
3942
AttributeValue::URIRef(s) => f.write_str(s.as_str()),
4043
AttributeValue::Time(s) => f.write_str(&s.to_rfc3339()),
41-
AttributeValue::Boolean(b) => f.serialize_bool(**b),
42-
AttributeValue::Integer(i) => f.serialize_i64(**i),
44+
AttributeValue::SpecVersion(s) => s.fmt(f),
4345
}
4446
}
4547
}

0 commit comments

Comments
 (0)