Repository: 3Hren/msgpack-rust (rust)

Issue:
Relax assertion on negative extension types
I'm using the `rmpv` crate to serialize some data to MessagePack, some of this data contains dates, so the data needs to be serialized as a Timestamp extension type, with type `-1`. See spec here: https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type.

When trying to serialize that data (using `write_value(&mut buf, &Value::Ext(-1, <data_here>)`) the `rmp` crate panics at the following line:
https://github.com/3Hren/msgpack-rust/blob/e96d118/rmp/src/encode/mod.rs#L260

At the moment I'm using a local copy of the crate with that assertion removed, but it would be helpful if that assertion could be relaxed to at least allow the type `-1`.





Pull request description:
Allow timestamp extension
The timestamp extension is using `-1` as identifier, support such negative values.

Closes #174.

Patch:
diff --git a/rmp/src/encode/mod.rs b/rmp/src/encode/mod.rs
index b3676c7..e88ec91 100644
--- a/rmp/src/encode/mod.rs
+++ b/rmp/src/encode/mod.rs
@@ -257,8 +257,6 @@ pub fn write_map_len<W: Write>(wr: &mut W, len: u32) -> Result<Marker, ValueWrit
 /// Panics if `ty` is negative, because it is reserved for future MessagePack extension including
 /// 2-byte type information.
 pub fn write_ext_meta<W: Write>(wr: &mut W, len: u32, ty: i8) -> Result<Marker, ValueWriteError> {
-    assert!(ty >= 0);
-
     let marker = match len {
         1 => {
             write_marker(wr, Marker::FixExt1)?;


Test patch:
diff --git a/rmp/tests/func/encode/ext.rs b/rmp/tests/func/encode/ext.rs
index 363cb47..f625a9f 100644
--- a/rmp/tests/func/encode/ext.rs
+++ b/rmp/tests/func/encode/ext.rs
@@ -28,6 +28,13 @@ fn pass_pack_meta_fix4() {
     assert_eq!([0xd6, 0x10], buf);
 }
 
+#[test]
+fn pass_pack_meta_fix4_timesamp() {
+    let mut buf = [0x00, 0x00];
+    assert_eq!(Marker::FixExt4, write_ext_meta(&mut &mut buf[..], 4, -1).unwrap());
+    assert_eq!([0xd6, 0xff], buf);
+}
+
 #[test]
 fn pass_pack_meta_fix8() {
     let mut buf = [0x00, 0x00];