martindisch / coap-lite

A lightweight CoAP message manipulation crate, ideal for embedded environments
Other
26 stars 18 forks source link

feat: add missing CoAP Content-Formats #23

Closed JKRhb closed 2 years ago

JKRhb commented 2 years ago

This PR updates the Crate's registered Content-Formats. The enum should now contain all formats currently registered with IANA.

I was a bit unsure regarding the capitalization, let me know if anything should be spelled differently :)

JKRhb commented 2 years ago

@martindisch Thank you for your review! I think all of your comments should be addressed now, I also took another look at the names and fixed two more typos.

You are right that the enum names are very verbose. In the latest commit, I tried to reduce the length of some enum names and added the exact representation to a doc comment. If these changes are okay with you, feel free to merge right away (preferably squashing the commits in the process), otherwise I could drop the commit, keeping the original version.

martindisch commented 2 years ago

I like it! Although I did notice that now we have

So maybe it's best if we consistently don't even bother and only include the "value" part everywhere, making it even shorter. I tried that out and made sure we have a doc comment everywhere we slightly deviate from the name. I couldn't push the commit though, as it seems you didn't check the box that lets me update your feature branch. So here's the diff instead

diff --git a/src/packet.rs b/src/packet.rs
index 9980653..16d76ad 100644
--- a/src/packet.rs
+++ b/src/packet.rs
@@ -111,11 +111,11 @@ impl From<CoapOption> for u16 {
 pub enum ContentFormat {
     TextPlain,
     /// Media-Type: `application/cose; cose-type="cose-encrypt0"`, ID: 16
-    ApplicationCoseTypeEncrypt0,
+    ApplicationCoseEncrypt0,
     /// Media-Type: `application/cose; cose-type="cose-mac0"`, ID: 17
-    ApplicationCoseTypeMac0,
+    ApplicationCoseMac0,
     /// Media-Type: `application/cose; cose-type="cose-sign1"`, ID: 18
-    ApplicationCoseTypeSign1,
+    ApplicationCoseSign1,
     ApplicationAceCbor,
     ImageGif,
     ImageJpeg,
@@ -132,11 +132,11 @@ pub enum ContentFormat {
     ApplicationMultipartCore,
     ApplicationCborSeq,
     /// Media-Type: `application/cose; cose-type="cose-encrypt"`, ID: 96
-    ApplicationCoseTypeEncrypt,
+    ApplicationCoseEncrypt,
     /// Media-Type: `application/cose; cose-type="cose-mac"`, ID: 97
-    ApplicationCoseTypeMac,
+    ApplicationCoseMac,
     /// Media-Type: `application/cose; cose-type="cose-sign"`, ID: 98
-    ApplicationCoseTypeSign,
+    ApplicationCoseSign,
     ApplicationCoseKey,
     ApplicationCoseKeySet,
     ApplicationSenmlJSON,
@@ -145,7 +145,8 @@ pub enum ContentFormat {
     ApplicationSensmlCBOR,
     ApplicationSenmlExi,
     ApplicationSensmlExi,
-    ApplicationYangDataCborIdSid,
+    /// Media-Type: `application/yang-data+cbor; id=sid`, ID: 140
+    ApplicationYangDataCborSid,
     ApplicationCoapGroupJson,
     ApplicationDotsCbor,
     ApplicationMissingBlocksCborSeq,
@@ -164,7 +165,8 @@ pub enum ContentFormat {
     ApplicationSenmlEtchJson,
     ApplicationSenmlEtchCbor,
     ApplicationYangDataCbor,
-    ApplicationYangDataCborIdName,
+    /// Media-Type: `application/yang-data+cbor; id=name`, ID: 341
+    ApplicationYangDataCborName,
     ApplicationTdJson,
     ApplicationVoucherCoseCbor,
     ApplicationVndOcfCbor,
@@ -185,9 +187,9 @@ impl TryFrom<usize> for ContentFormat {
     fn try_from(number: usize) -> Result<ContentFormat, InvalidContentFormat> {
         match number {
             0 => Ok(ContentFormat::TextPlain),
-            16 => Ok(ContentFormat::ApplicationCoseTypeEncrypt0),
-            17 => Ok(ContentFormat::ApplicationCoseTypeMac0),
-            18 => Ok(ContentFormat::ApplicationCoseTypeSign1),
+            16 => Ok(ContentFormat::ApplicationCoseEncrypt0),
+            17 => Ok(ContentFormat::ApplicationCoseMac0),
+            18 => Ok(ContentFormat::ApplicationCoseSign1),
             19 => Ok(ContentFormat::ApplicationAceCbor),
             21 => Ok(ContentFormat::ImageGif),
             22 => Ok(ContentFormat::ImageJpeg),
@@ -203,9 +205,9 @@ impl TryFrom<usize> for ContentFormat {
             61 => Ok(ContentFormat::ApplicationCWt),
             62 => Ok(ContentFormat::ApplicationMultipartCore),
             63 => Ok(ContentFormat::ApplicationCborSeq),
-            96 => Ok(ContentFormat::ApplicationCoseTypeEncrypt),
-            97 => Ok(ContentFormat::ApplicationCoseTypeMac),
-            98 => Ok(ContentFormat::ApplicationCoseTypeSign),
+            96 => Ok(ContentFormat::ApplicationCoseEncrypt),
+            97 => Ok(ContentFormat::ApplicationCoseMac),
+            98 => Ok(ContentFormat::ApplicationCoseSign),
             101 => Ok(ContentFormat::ApplicationCoseKey),
             102 => Ok(ContentFormat::ApplicationCoseKeySet),
             110 => Ok(ContentFormat::ApplicationSenmlJSON),
@@ -214,7 +216,7 @@ impl TryFrom<usize> for ContentFormat {
             113 => Ok(ContentFormat::ApplicationSensmlCBOR),
             114 => Ok(ContentFormat::ApplicationSenmlExi),
             115 => Ok(ContentFormat::ApplicationSensmlExi),
-            140 => Ok(ContentFormat::ApplicationYangDataCborIdSid),
+            140 => Ok(ContentFormat::ApplicationYangDataCborSid),
             256 => Ok(ContentFormat::ApplicationCoapGroupJson),
             271 => Ok(ContentFormat::ApplicationDotsCbor),
             272 => Ok(ContentFormat::ApplicationMissingBlocksCborSeq),
@@ -231,7 +233,7 @@ impl TryFrom<usize> for ContentFormat {
             320 => Ok(ContentFormat::ApplicationSenmlEtchJson),
             322 => Ok(ContentFormat::ApplicationSenmlEtchCbor),
             340 => Ok(ContentFormat::ApplicationYangDataCbor),
-            341 => Ok(ContentFormat::ApplicationYangDataCborIdName),
+            341 => Ok(ContentFormat::ApplicationYangDataCborName),
             432 => Ok(ContentFormat::ApplicationTdJson),
             836 => Ok(ContentFormat::ApplicationVoucherCoseCbor),
             10000 => Ok(ContentFormat::ApplicationVndOcfCbor),
@@ -253,9 +255,9 @@ impl From<ContentFormat> for usize {
     fn from(format: ContentFormat) -> usize {
         match format {
             ContentFormat::TextPlain => 0,
-            ContentFormat::ApplicationCoseTypeEncrypt0 => 16,
-            ContentFormat::ApplicationCoseTypeMac0 => 17,
-            ContentFormat::ApplicationCoseTypeSign1 => 18,
+            ContentFormat::ApplicationCoseEncrypt0 => 16,
+            ContentFormat::ApplicationCoseMac0 => 17,
+            ContentFormat::ApplicationCoseSign1 => 18,
             ContentFormat::ApplicationAceCbor => 19,
             ContentFormat::ImageGif => 21,
             ContentFormat::ImageJpeg => 22,
@@ -271,9 +273,9 @@ impl From<ContentFormat> for usize {
             ContentFormat::ApplicationCWt => 61,
             ContentFormat::ApplicationMultipartCore => 62,
             ContentFormat::ApplicationCborSeq => 63,
-            ContentFormat::ApplicationCoseTypeEncrypt => 96,
-            ContentFormat::ApplicationCoseTypeMac => 97,
-            ContentFormat::ApplicationCoseTypeSign => 98,
+            ContentFormat::ApplicationCoseEncrypt => 96,
+            ContentFormat::ApplicationCoseMac => 97,
+            ContentFormat::ApplicationCoseSign => 98,
             ContentFormat::ApplicationCoseKey => 101,
             ContentFormat::ApplicationCoseKeySet => 102,
             ContentFormat::ApplicationSenmlJSON => 110,
@@ -282,7 +284,7 @@ impl From<ContentFormat> for usize {
             ContentFormat::ApplicationSensmlCBOR => 113,
             ContentFormat::ApplicationSenmlExi => 114,
             ContentFormat::ApplicationSensmlExi => 115,
-            ContentFormat::ApplicationYangDataCborIdSid => 140,
+            ContentFormat::ApplicationYangDataCborSid => 140,
             ContentFormat::ApplicationCoapGroupJson => 256,
             ContentFormat::ApplicationDotsCbor => 271,
             ContentFormat::ApplicationMissingBlocksCborSeq => 272,
@@ -299,7 +301,7 @@ impl From<ContentFormat> for usize {
             ContentFormat::ApplicationSenmlEtchJson => 320,
             ContentFormat::ApplicationSenmlEtchCbor => 322,
             ContentFormat::ApplicationYangDataCbor => 340,
-            ContentFormat::ApplicationYangDataCborIdName => 341,
+            ContentFormat::ApplicationYangDataCborName => 341,
             ContentFormat::ApplicationTdJson => 432,
             ContentFormat::ApplicationVoucherCoseCbor => 836,
             ContentFormat::ApplicationVndOcfCbor => 10000,

Do you think that's good or would you rather do it differently?

JKRhb commented 2 years ago

I couldn't push the commit though, as it seems you didn't check the box that lets me update your feature branch. So here's the diff instead

I think the checkbox was missing due to the fact that I opened the PR from an organization repository :/ Thank you for the diff, though! The changes look good, I applied them and squashed the commits :) If the state of the PR looks good to you, feel free to merge :)

martindisch commented 2 years ago

Looks like one change from the diff got lost in the process, the rest is great.

diff --git a/src/packet.rs b/src/packet.rs
index b68b1c0..16d76ad 100644
--- a/src/packet.rs
+++ b/src/packet.rs
@@ -145,7 +145,8 @@ pub enum ContentFormat {
     ApplicationSensmlCBOR,
     ApplicationSenmlExi,
     ApplicationSensmlExi,
-    ApplicationYangDataCborIdSid,
+    /// Media-Type: `application/yang-data+cbor; id=sid`, ID: 140
+    ApplicationYangDataCborSid,
     ApplicationCoapGroupJson,
     ApplicationDotsCbor,
     ApplicationMissingBlocksCborSeq,
@@ -215,7 +216,7 @@ impl TryFrom<usize> for ContentFormat {
             113 => Ok(ContentFormat::ApplicationSensmlCBOR),
             114 => Ok(ContentFormat::ApplicationSenmlExi),
             115 => Ok(ContentFormat::ApplicationSensmlExi),
-            140 => Ok(ContentFormat::ApplicationYangDataCborIdSid),
+            140 => Ok(ContentFormat::ApplicationYangDataCborSid),
             256 => Ok(ContentFormat::ApplicationCoapGroupJson),
             271 => Ok(ContentFormat::ApplicationDotsCbor),
             272 => Ok(ContentFormat::ApplicationMissingBlocksCborSeq),
@@ -283,7 +284,7 @@ impl From<ContentFormat> for usize {
             ContentFormat::ApplicationSensmlCBOR => 113,
             ContentFormat::ApplicationSenmlExi => 114,
             ContentFormat::ApplicationSensmlExi => 115,
-            ContentFormat::ApplicationYangDataCborIdSid => 140,
+            ContentFormat::ApplicationYangDataCborSid => 140,
             ContentFormat::ApplicationCoapGroupJson => 256,
             ContentFormat::ApplicationDotsCbor => 271,
             ContentFormat::ApplicationMissingBlocksCborSeq => 272,
JKRhb commented 2 years ago

Looks like one change from the diff got lost in the process, the rest is great.

Oh, sorry, should be fixed now!

martindisch commented 2 years ago

Published as 0.10.0. Thank you!