standardize to u64

This commit is contained in:
Ty Overby 2014-09-17 12:22:53 -07:00
parent 6053ac0711
commit 7d4cde7212
2 changed files with 15 additions and 12 deletions

View File

@ -26,7 +26,10 @@ impl <R: Reader> Decoder<IoError> for DecoderReader<R> {
Ok(()) Ok(())
} }
fn read_uint(&mut self) -> Result<uint, IoError> { fn read_uint(&mut self) -> Result<uint, IoError> {
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<u64, IoError> { fn read_u64(&mut self) -> Result<u64, IoError> {
self.reader.read_be_u64() self.reader.read_be_u64()
@ -71,7 +74,7 @@ impl <R: Reader> Decoder<IoError> for DecoderReader<R> {
self.reader.read_char() self.reader.read_char()
} }
fn read_str(&mut self) -> Result<String, IoError> { fn read_str(&mut self) -> Result<String, IoError> {
let len = try!(self.reader.read_be_uint()); let len = try!(self.read_uint());
let mut string = String::new(); let mut string = String::new();
for _ in range(0, len) { for _ in range(0, len) {
string.push_char(try!(self.reader.read_char())); string.push_char(try!(self.reader.read_char()));
@ -84,7 +87,7 @@ impl <R: Reader> Decoder<IoError> for DecoderReader<R> {
} }
fn read_enum_variant<T>(&mut self, _: &[&str], fn read_enum_variant<T>(&mut self, _: &[&str],
f: |&mut DecoderReader<R>, uint| -> Result<T, IoError>) -> Result<T, IoError> { f: |&mut DecoderReader<R>, uint| -> Result<T, IoError>) -> Result<T, IoError> {
let id = try!(self.reader.read_be_uint()); let id = try!(self.read_uint());
f(self, id) f(self, id)
} }
fn read_enum_variant_arg<T>(&mut self, _: uint, fn read_enum_variant_arg<T>(&mut self, _: uint,
@ -110,7 +113,7 @@ impl <R: Reader> Decoder<IoError> for DecoderReader<R> {
fn read_tuple<T>(&mut self, fn read_tuple<T>(&mut self,
f: |&mut DecoderReader<R>, uint| -> Result<T, IoError>) -> f: |&mut DecoderReader<R>, uint| -> Result<T, IoError>) ->
Result<T, IoError> { Result<T, IoError> {
let len = try!(self.reader.read_be_uint()); let len = try!(self.read_uint());
f(self, len) f(self, len)
} }
fn read_tuple_arg<T>(&mut self, _: uint, fn read_tuple_arg<T>(&mut self, _: uint,
@ -137,7 +140,7 @@ impl <R: Reader> Decoder<IoError> for DecoderReader<R> {
fn read_seq<T>(&mut self, fn read_seq<T>(&mut self,
f: |&mut DecoderReader<R>, uint| -> Result<T, IoError>) -> f: |&mut DecoderReader<R>, uint| -> Result<T, IoError>) ->
Result<T, IoError> { Result<T, IoError> {
let len = try!(self.reader.read_be_uint()); let len = try!(self.read_uint());
f(self, len) f(self, len)
} }
fn read_seq_elt<T>(&mut self, _: uint, fn read_seq_elt<T>(&mut self, _: uint,
@ -147,7 +150,7 @@ impl <R: Reader> Decoder<IoError> for DecoderReader<R> {
fn read_map<T>(&mut self, fn read_map<T>(&mut self,
f: |&mut DecoderReader<R>, uint| -> Result<T, IoError>) -> f: |&mut DecoderReader<R>, uint| -> Result<T, IoError>) ->
Result<T, IoError> { Result<T, IoError> {
let len = try!(self.reader.read_be_uint()); let len = try!(self.read_uint());
f(self, len) f(self, len)
} }
fn read_map_elt_key<T>(&mut self, _: uint, fn read_map_elt_key<T>(&mut self, _: uint,

View File

@ -21,7 +21,7 @@ impl <W> EncoderWriter<W> {
impl <W: Writer> Encoder<IoError> for EncoderWriter<W> { impl <W: Writer> Encoder<IoError> for EncoderWriter<W> {
fn emit_nil(&mut self) -> EwResult { Ok(()) } fn emit_nil(&mut self) -> EwResult { Ok(()) }
fn emit_uint(&mut self, v: uint) -> EwResult { 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 { fn emit_u64(&mut self, v: u64) -> EwResult {
self.writer.write_be_u64(v) self.writer.write_be_u64(v)
@ -63,7 +63,7 @@ impl <W: Writer> Encoder<IoError> for EncoderWriter<W> {
self.writer.write_char(v) self.writer.write_char(v)
} }
fn emit_str(&mut self, v: &str) -> EwResult { 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) self.writer.write_str(v)
} }
fn emit_enum(&mut self, _: &str, fn emit_enum(&mut self, _: &str,
@ -73,7 +73,7 @@ impl <W: Writer> Encoder<IoError> for EncoderWriter<W> {
fn emit_enum_variant(&mut self, fn emit_enum_variant(&mut self,
_: &str, v_id: uint, _: uint, _: &str, v_id: uint, _: uint,
f: |&mut EncoderWriter<W>| -> EwResult) -> EwResult { f: |&mut EncoderWriter<W>| -> EwResult) -> EwResult {
try!(self.writer.write_be_uint(v_id)); try!(self.emit_uint(v_id));
f(self) f(self)
} }
fn emit_enum_variant_arg(&mut self, _: uint, fn emit_enum_variant_arg(&mut self, _: uint,
@ -98,7 +98,7 @@ impl <W: Writer> Encoder<IoError> for EncoderWriter<W> {
} }
fn emit_tuple(&mut self, len: uint, fn emit_tuple(&mut self, len: uint,
f: |&mut EncoderWriter<W>| -> EwResult) -> EwResult { f: |&mut EncoderWriter<W>| -> EwResult) -> EwResult {
try!(self.writer.write_be_uint(len)); try!(self.emit_uint(len));
f(self) f(self)
} }
fn emit_tuple_arg(&mut self, _: uint, fn emit_tuple_arg(&mut self, _: uint,
@ -127,7 +127,7 @@ impl <W: Writer> Encoder<IoError> for EncoderWriter<W> {
} }
fn emit_seq(&mut self, len: uint, fn emit_seq(&mut self, len: uint,
f: |this: &mut EncoderWriter<W>| -> EwResult) -> EwResult { f: |this: &mut EncoderWriter<W>| -> EwResult) -> EwResult {
try!(self.writer.write_be_uint(len)); try!(self.emit_uint(len));
f(self) f(self)
} }
fn emit_seq_elt(&mut self, _: uint, fn emit_seq_elt(&mut self, _: uint,
@ -136,7 +136,7 @@ impl <W: Writer> Encoder<IoError> for EncoderWriter<W> {
} }
fn emit_map(&mut self, len: uint, fn emit_map(&mut self, len: uint,
f: |&mut EncoderWriter<W>| -> EwResult) -> EwResult { f: |&mut EncoderWriter<W>| -> EwResult) -> EwResult {
try!(self.writer.write_be_uint(len)); try!(self.emit_uint(len));
f(self) f(self)
} }
fn emit_map_elt_key(&mut self, _: uint, fn emit_map_elt_key(&mut self, _: uint,