std: clean up the order of {De,En}codable methods
This commit is contained in:
parent
4464e44750
commit
97cc571358
4 changed files with 92 additions and 93 deletions
|
@ -335,20 +335,6 @@ pub mod reader {
|
|||
f()
|
||||
}
|
||||
|
||||
fn read_seq<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_seq()");
|
||||
do self.push_doc(self.next_doc(EsVec)) {
|
||||
let len = self._next_uint(EsVecLen);
|
||||
debug!(" len=%u", len);
|
||||
f(len)
|
||||
}
|
||||
}
|
||||
|
||||
fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_seq_elt(idx=%u)", idx);
|
||||
self.push_doc(self.next_doc(EsVecElt), f)
|
||||
}
|
||||
|
||||
fn read_struct<T>(&self, name: &str, _len: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_struct(name=%s)", name);
|
||||
f()
|
||||
|
@ -373,6 +359,20 @@ pub mod reader {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_seq<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_seq()");
|
||||
do self.push_doc(self.next_doc(EsVec)) {
|
||||
let len = self._next_uint(EsVecLen);
|
||||
debug!(" len=%u", len);
|
||||
f(len)
|
||||
}
|
||||
}
|
||||
|
||||
fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_seq_elt(idx=%u)", idx);
|
||||
self.push_doc(self.next_doc(EsVecElt), f)
|
||||
}
|
||||
|
||||
fn read_map<T>(&self, _f: &fn(uint) -> T) -> T {
|
||||
debug!("read_map()");
|
||||
fail!(~"read_map is unimplemented");
|
||||
|
@ -613,17 +613,6 @@ pub mod writer {
|
|||
}
|
||||
fn emit_enum_variant_arg(&self, _idx: uint, f: &fn()) { f() }
|
||||
|
||||
fn emit_seq(&self, len: uint, f: &fn()) {
|
||||
do self.wr_tag(EsVec as uint) {
|
||||
self._emit_tagged_uint(EsVecLen, len);
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_seq_elt(&self, _idx: uint, f: &fn()) {
|
||||
self.wr_tag(EsVecElt as uint, f)
|
||||
}
|
||||
|
||||
fn emit_struct(&self, _name: &str, _len: uint, f: &fn()) { f() }
|
||||
fn emit_field(&self, name: &str, _idx: uint, f: &fn()) {
|
||||
self._emit_label(name);
|
||||
|
@ -640,6 +629,17 @@ pub mod writer {
|
|||
self.emit_enum_variant("Some", 1, 1, f)
|
||||
}
|
||||
|
||||
fn emit_seq(&self, len: uint, f: &fn()) {
|
||||
do self.wr_tag(EsVec as uint) {
|
||||
self._emit_tagged_uint(EsVecLen, len);
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_seq_elt(&self, _idx: uint, f: &fn()) {
|
||||
self.wr_tag(EsVecElt as uint, f)
|
||||
}
|
||||
|
||||
fn emit_map(&self, _len: uint, _f: &fn()) {
|
||||
fail!(~"emit_map is unimplemented");
|
||||
}
|
||||
|
|
|
@ -130,17 +130,6 @@ impl serialize::Encoder for Encoder {
|
|||
f();
|
||||
}
|
||||
|
||||
fn emit_seq(&self, _len: uint, f: &fn()) {
|
||||
self.wr.write_char('[');
|
||||
f();
|
||||
self.wr.write_char(']');
|
||||
}
|
||||
|
||||
fn emit_seq_elt(&self, idx: uint, f: &fn()) {
|
||||
if idx != 0 { self.wr.write_char(','); }
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_struct(&self, _name: &str, _len: uint, f: &fn()) {
|
||||
self.wr.write_char('{');
|
||||
f();
|
||||
|
@ -157,6 +146,17 @@ impl serialize::Encoder for Encoder {
|
|||
fn emit_option_none(&self) { self.emit_nil(); }
|
||||
fn emit_option_some(&self, f: &fn()) { f(); }
|
||||
|
||||
fn emit_seq(&self, _len: uint, f: &fn()) {
|
||||
self.wr.write_char('[');
|
||||
f();
|
||||
self.wr.write_char(']');
|
||||
}
|
||||
|
||||
fn emit_seq_elt(&self, idx: uint, f: &fn()) {
|
||||
if idx != 0 { self.wr.write_char(','); }
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_map(&self, _len: uint, f: &fn()) {
|
||||
self.wr.write_char('{');
|
||||
f();
|
||||
|
@ -241,29 +241,6 @@ impl serialize::Encoder for PrettyEncoder {
|
|||
f()
|
||||
}
|
||||
|
||||
fn emit_seq(&self, len: uint, f: &fn()) {
|
||||
if len == 0 {
|
||||
self.wr.write_str("[]");
|
||||
} else {
|
||||
self.wr.write_char('[');
|
||||
self.indent += 2;
|
||||
f();
|
||||
self.wr.write_char('\n');
|
||||
self.indent -= 2;
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
self.wr.write_char(']');
|
||||
}
|
||||
}
|
||||
fn emit_seq_elt(&self, idx: uint, f: &fn()) {
|
||||
if idx == 0 {
|
||||
self.wr.write_char('\n');
|
||||
} else {
|
||||
self.wr.write_str(",\n");
|
||||
}
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_struct(&self, _name: &str, len: uint, f: &fn()) {
|
||||
if len == 0 {
|
||||
self.wr.write_str("{}");
|
||||
|
@ -293,6 +270,29 @@ impl serialize::Encoder for PrettyEncoder {
|
|||
fn emit_option_none(&self) { self.emit_nil(); }
|
||||
fn emit_option_some(&self, f: &fn()) { f(); }
|
||||
|
||||
fn emit_seq(&self, len: uint, f: &fn()) {
|
||||
if len == 0 {
|
||||
self.wr.write_str("[]");
|
||||
} else {
|
||||
self.wr.write_char('[');
|
||||
self.indent += 2;
|
||||
f();
|
||||
self.wr.write_char('\n');
|
||||
self.indent -= 2;
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
self.wr.write_char(']');
|
||||
}
|
||||
}
|
||||
fn emit_seq_elt(&self, idx: uint, f: &fn()) {
|
||||
if idx == 0 {
|
||||
self.wr.write_char('\n');
|
||||
} else {
|
||||
self.wr.write_str(",\n");
|
||||
}
|
||||
self.wr.write_str(spaces(self.indent));
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_map(&self, len: uint, f: &fn()) {
|
||||
if len == 0 {
|
||||
self.wr.write_str("{}");
|
||||
|
@ -827,26 +827,6 @@ impl serialize::Decoder for Decoder {
|
|||
f()
|
||||
}
|
||||
|
||||
fn read_seq<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_seq()");
|
||||
let len = match self.stack.pop() {
|
||||
List(list) => {
|
||||
let len = list.len();
|
||||
do vec::consume_reverse(list) |_i, v| {
|
||||
self.stack.push(v);
|
||||
}
|
||||
len
|
||||
}
|
||||
_ => fail!(~"not a list"),
|
||||
};
|
||||
f(len)
|
||||
}
|
||||
|
||||
fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_seq_elt(idx=%u)", idx);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_struct<T>(&self, name: &str, len: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_struct(name=%s, len=%u)", name, len);
|
||||
let value = f();
|
||||
|
@ -880,6 +860,26 @@ impl serialize::Decoder for Decoder {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_seq<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_seq()");
|
||||
let len = match self.stack.pop() {
|
||||
List(list) => {
|
||||
let len = list.len();
|
||||
do vec::consume_reverse(list) |_i, v| {
|
||||
self.stack.push(v);
|
||||
}
|
||||
len
|
||||
}
|
||||
_ => fail!(~"not a list"),
|
||||
};
|
||||
f(len)
|
||||
}
|
||||
|
||||
fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T {
|
||||
debug!("read_seq_elt(idx=%u)", idx);
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_map<T>(&self, f: &fn(uint) -> T) -> T {
|
||||
debug!("read_map()");
|
||||
let len = match self.stack.pop() {
|
||||
|
|
|
@ -44,14 +44,10 @@ pub trait Encoder {
|
|||
fn emit_str(&self, v: &str);
|
||||
|
||||
// Compound types:
|
||||
|
||||
fn emit_enum(&self, name: &str, f: &fn());
|
||||
fn emit_enum_variant(&self, v_name: &str, v_id: uint, sz: uint, f: &fn());
|
||||
fn emit_enum_variant_arg(&self, idx: uint, f: &fn());
|
||||
|
||||
fn emit_seq(&self, len: uint, f: &fn());
|
||||
fn emit_seq_elt(&self, idx: uint, f: &fn());
|
||||
|
||||
fn emit_struct(&self, name: &str, _len: uint, f: &fn());
|
||||
fn emit_field(&self, f_name: &str, f_idx: uint, f: &fn());
|
||||
|
||||
|
@ -60,6 +56,9 @@ pub trait Encoder {
|
|||
fn emit_option_none(&self);
|
||||
fn emit_option_some(&self, f: &fn());
|
||||
|
||||
fn emit_seq(&self, len: uint, f: &fn());
|
||||
fn emit_seq_elt(&self, idx: uint, f: &fn());
|
||||
|
||||
fn emit_map(&self, len: uint, f: &fn());
|
||||
fn emit_map_elt_key(&self, idx: uint, f: &fn());
|
||||
fn emit_map_elt_val(&self, idx: uint, f: &fn());
|
||||
|
@ -90,15 +89,15 @@ pub trait Decoder {
|
|||
fn read_enum_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T;
|
||||
fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T;
|
||||
|
||||
fn read_seq<T>(&self, f: &fn(uint) -> T) -> T;
|
||||
fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T;
|
||||
|
||||
fn read_struct<T>(&self, name: &str, _len: uint, f: &fn() -> T) -> T;
|
||||
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T;
|
||||
|
||||
// Specialized types:
|
||||
fn read_option<T>(&self, f: &fn(bool) -> T) -> T;
|
||||
|
||||
fn read_seq<T>(&self, f: &fn(uint) -> T) -> T;
|
||||
fn read_seq_elt<T>(&self, idx: uint, f: &fn() -> T) -> T;
|
||||
|
||||
fn read_map<T>(&self, f: &fn(uint) -> T) -> T;
|
||||
fn read_map_elt_key<T>(&self, idx: uint, f: &fn() -> T) -> T;
|
||||
fn read_map_elt_val<T>(&self, idx: uint, f: &fn() -> T) -> T;
|
||||
|
|
|
@ -1253,13 +1253,6 @@ mod test {
|
|||
self.add_to_log(CallToEmitEnumVariantArg (idx)); f();
|
||||
}
|
||||
|
||||
fn emit_seq(&self, +_len: uint, f: &fn()) {
|
||||
self.add_unknown_to_log(); f();
|
||||
}
|
||||
fn emit_seq_elt(&self, +_idx: uint, f: &fn()) {
|
||||
self.add_unknown_to_log(); f();
|
||||
}
|
||||
|
||||
fn emit_struct(&self, name: &str, +len: uint, f: &fn()) {
|
||||
self.add_to_log(CallToEmitStruct (name.to_str(),len)); f();
|
||||
}
|
||||
|
@ -1279,6 +1272,13 @@ mod test {
|
|||
f();
|
||||
}
|
||||
|
||||
fn emit_seq(&self, +_len: uint, f: &fn()) {
|
||||
self.add_unknown_to_log(); f();
|
||||
}
|
||||
fn emit_seq_elt(&self, +_idx: uint, f: &fn()) {
|
||||
self.add_unknown_to_log(); f();
|
||||
}
|
||||
|
||||
fn emit_map(&self, _len: uint, f: &fn()) {
|
||||
self.add_unknown_to_log(); f();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue