From 7d4cde7212fcc5709abbf275a9a2bf9acd28bfc9 Mon Sep 17 00:00:00 2001 From: Ty Overby Date: Wed, 17 Sep 2014 12:22:53 -0700 Subject: [PATCH] standardize to u64 --- src/reader.rs | 15 +++++++++------ src/writer.rs | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index a766aa1..d8be8a6 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -26,7 +26,10 @@ impl Decoder for DecoderReader { Ok(()) } fn read_uint(&mut self) -> Result { - self.reader.read_be_uint() + match self.reader.read_be_u64() { + Ok(x) => Ok(x as uint), + Err(e) => Err(e) + } } fn read_u64(&mut self) -> Result { self.reader.read_be_u64() @@ -71,7 +74,7 @@ impl Decoder for DecoderReader { self.reader.read_char() } fn read_str(&mut self) -> Result { - let len = try!(self.reader.read_be_uint()); + let len = try!(self.read_uint()); let mut string = String::new(); for _ in range(0, len) { string.push_char(try!(self.reader.read_char())); @@ -84,7 +87,7 @@ impl Decoder for DecoderReader { } fn read_enum_variant(&mut self, _: &[&str], f: |&mut DecoderReader, uint| -> Result) -> Result { - let id = try!(self.reader.read_be_uint()); + let id = try!(self.read_uint()); f(self, id) } fn read_enum_variant_arg(&mut self, _: uint, @@ -110,7 +113,7 @@ impl Decoder for DecoderReader { fn read_tuple(&mut self, f: |&mut DecoderReader, uint| -> Result) -> Result { - let len = try!(self.reader.read_be_uint()); + let len = try!(self.read_uint()); f(self, len) } fn read_tuple_arg(&mut self, _: uint, @@ -137,7 +140,7 @@ impl Decoder for DecoderReader { fn read_seq(&mut self, f: |&mut DecoderReader, uint| -> Result) -> Result { - let len = try!(self.reader.read_be_uint()); + let len = try!(self.read_uint()); f(self, len) } fn read_seq_elt(&mut self, _: uint, @@ -147,7 +150,7 @@ impl Decoder for DecoderReader { fn read_map(&mut self, f: |&mut DecoderReader, uint| -> Result) -> Result { - let len = try!(self.reader.read_be_uint()); + let len = try!(self.read_uint()); f(self, len) } fn read_map_elt_key(&mut self, _: uint, diff --git a/src/writer.rs b/src/writer.rs index 222364e..16a2ff3 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -21,7 +21,7 @@ impl EncoderWriter { impl Encoder for EncoderWriter { fn emit_nil(&mut self) -> EwResult { Ok(()) } fn emit_uint(&mut self, v: uint) -> EwResult { - self.writer.write_be_uint(v) + self.writer.write_be_u64(v as u64) } fn emit_u64(&mut self, v: u64) -> EwResult { self.writer.write_be_u64(v) @@ -63,7 +63,7 @@ impl Encoder for EncoderWriter { self.writer.write_char(v) } fn emit_str(&mut self, v: &str) -> EwResult { - try!(self.writer.write_be_uint(v.len())); + try!(self.emit_uint(v.len())); self.writer.write_str(v) } fn emit_enum(&mut self, _: &str, @@ -73,7 +73,7 @@ impl Encoder for EncoderWriter { fn emit_enum_variant(&mut self, _: &str, v_id: uint, _: uint, f: |&mut EncoderWriter| -> EwResult) -> EwResult { - try!(self.writer.write_be_uint(v_id)); + try!(self.emit_uint(v_id)); f(self) } fn emit_enum_variant_arg(&mut self, _: uint, @@ -98,7 +98,7 @@ impl Encoder for EncoderWriter { } fn emit_tuple(&mut self, len: uint, f: |&mut EncoderWriter| -> EwResult) -> EwResult { - try!(self.writer.write_be_uint(len)); + try!(self.emit_uint(len)); f(self) } fn emit_tuple_arg(&mut self, _: uint, @@ -127,7 +127,7 @@ impl Encoder for EncoderWriter { } fn emit_seq(&mut self, len: uint, f: |this: &mut EncoderWriter| -> EwResult) -> EwResult { - try!(self.writer.write_be_uint(len)); + try!(self.emit_uint(len)); f(self) } fn emit_seq_elt(&mut self, _: uint, @@ -136,7 +136,7 @@ impl Encoder for EncoderWriter { } fn emit_map(&mut self, len: uint, f: |&mut EncoderWriter| -> EwResult) -> EwResult { - try!(self.writer.write_be_uint(len)); + try!(self.emit_uint(len)); f(self) } fn emit_map_elt_key(&mut self, _: uint,