diff options
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/lib.rs | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 9b177a1..1508594 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs | |||
| @@ -60,14 +60,12 @@ impl Value { | |||
| 60 | pub fn write<W: Write>(&self, w: &mut W) -> Result<(), std::io::Error> { | 60 | pub fn write<W: Write>(&self, w: &mut W) -> Result<(), std::io::Error> { |
| 61 | match self { | 61 | match self { |
| 62 | Self::Integer(x) => { | 62 | Self::Integer(x) => { |
| 63 | let mut bb = [0u8]; | 63 | let bb = ['i' as u8]; |
| 64 | bb[0] = 'i' as u8; | ||
| 65 | w.write_all(&bb)?; | 64 | w.write_all(&bb)?; |
| 66 | w.write_all(&write_packed_int( *x ))?; | 65 | w.write_all(&write_packed_int( *x ))?; |
| 67 | }, | 66 | }, |
| 68 | Self::ByteString(s) => { | 67 | Self::ByteString(s) => { |
| 69 | let mut bb = [0u8]; | 68 | let bb = ['s' as u8]; |
| 70 | bb[0] = 's' as u8; | ||
| 71 | w.write_all(&bb)?; | 69 | w.write_all(&bb)?; |
| 72 | w.write_all(&write_packed_int( s.len() as i64 ))?; | 70 | w.write_all(&write_packed_int( s.len() as i64 ))?; |
| 73 | w.write_all( &s )?; | 71 | w.write_all( &s )?; |
| @@ -78,6 +76,13 @@ impl Value { | |||
| 78 | w.write_all( &bb )?; | 76 | w.write_all( &bb )?; |
| 79 | }, | 77 | }, |
| 80 | Self::List(l) => { | 78 | Self::List(l) => { |
| 79 | let mut bb = ['l' as u8]; | ||
| 80 | w.write_all(&bb)?; | ||
| 81 | for v in l { | ||
| 82 | v.write( w )?; | ||
| 83 | } | ||
| 84 | bb[0] = 'e' as u8; | ||
| 85 | w.write_all(&bb)?; | ||
| 81 | }, | 86 | }, |
| 82 | Self::Dictionary(d) => { | 87 | Self::Dictionary(d) => { |
| 83 | }, | 88 | }, |
| @@ -102,13 +107,34 @@ impl Value { | |||
| 102 | w.write_all( &bb )?; | 107 | w.write_all( &bb )?; |
| 103 | }, | 108 | }, |
| 104 | FpCategory::Normal => { | 109 | FpCategory::Normal => { |
| 105 | let div = 256f64.ln(); | 110 | let mut bin = Vec::<u8>::with_capacity(10); |
| 106 | todo!(); | 111 | let (negative, d) = if f.is_sign_negative() { (true, -*f) } else { (false, *f) }; |
| 107 | 112 | let scale : i64 = (d.ln() / 256.0f64.ln()) as i64; | |
| 113 | let scale = if scale < 0 { -1 } else { scale }; | ||
| 114 | let mut d = d / 256.0_f64.powf( scale as f64 ); | ||
| 115 | bin.push( d as u8 ); | ||
| 116 | d = d.fract(); | ||
| 117 | for _ in 0..15 { | ||
| 118 | d = d*256.0; | ||
| 119 | bin.push( d as u8 ); | ||
| 120 | d = d.fract(); | ||
| 121 | if d == 0.0 { | ||
| 122 | break; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | if negative { | ||
| 126 | w.write_all( &write_packed_int( -(bin.len() as i64) ) )?; | ||
| 127 | } else { | ||
| 128 | w.write_all( &write_packed_int( bin.len() as i64 ) )?; | ||
| 129 | } | ||
| 130 | w.write_all( &bin )?; | ||
| 131 | w.write_all( &write_packed_int( scale ) )?; | ||
| 108 | }, | 132 | }, |
| 109 | } | 133 | } |
| 110 | }, | 134 | }, |
| 111 | Self::Nothing => { | 135 | Self::Nothing => { |
| 136 | let bb = ['n' as u8]; | ||
| 137 | w.write_all( &bb )?; | ||
| 112 | }, | 138 | }, |
| 113 | } | 139 | } |
| 114 | Ok(()) | 140 | Ok(()) |
