Switch from serialization to std::serialize. (snapshot)
diff --git a/src/libstd/json.rs b/src/libstd/json.rs
index 70bffb2..770d621 100644
--- a/src/libstd/json.rs
+++ b/src/libstd/json.rs
@@ -65,15 +65,15 @@
return ss;
}
-pub struct Serializer {
+pub struct Encoder {
priv wr: io::Writer,
}
-pub fn Serializer(wr: io::Writer) -> Serializer {
- Serializer { wr: wr }
+pub fn Encoder(wr: io::Writer) -> Encoder {
+ Encoder { wr: wr }
}
-pub impl Serializer: serialization::Serializer {
+pub impl Encoder: serialize::Encoder {
fn emit_nil(&self) { self.wr.write_str("null") }
fn emit_uint(&self, v: uint) { self.emit_float(v as float); }
@@ -168,16 +168,16 @@
}
}
-pub struct PrettySerializer {
+pub struct PrettyEncoder {
priv wr: io::Writer,
priv mut indent: uint,
}
-pub fn PrettySerializer(wr: io::Writer) -> PrettySerializer {
- PrettySerializer { wr: wr, indent: 0 }
+pub fn PrettyEncoder(wr: io::Writer) -> PrettyEncoder {
+ PrettyEncoder { wr: wr, indent: 0 }
}
-pub impl PrettySerializer: serialization::Serializer {
+pub impl PrettyEncoder: serialize::Encoder {
fn emit_nil(&self) { self.wr.write_str("null") }
fn emit_uint(&self, v: uint) { self.emit_float(v as float); }
@@ -283,21 +283,19 @@
}
}
-pub impl<
- S: serialization::Serializer
-> Json: serialization::Serializable<S> {
- fn serialize(&self, s: &S) {
+pub impl<S: serialize::Encoder> Json: serialize::Encodable<S> {
+ fn encode(&self, s: &S) {
match *self {
- Number(v) => v.serialize(s),
- String(ref v) => v.serialize(s),
- Boolean(v) => v.serialize(s),
- List(ref v) => v.serialize(s),
+ Number(v) => v.encode(s),
+ String(ref v) => v.encode(s),
+ Boolean(v) => v.encode(s),
+ List(ref v) => v.encode(s),
Object(ref v) => {
do s.emit_rec || {
let mut idx = 0;
for v.each |key, value| {
do s.emit_field(*key, idx) {
- value.serialize(s);
+ value.encode(s);
}
idx += 1;
}
@@ -308,23 +306,23 @@
}
}
-/// Serializes a json value into a io::writer
+/// Encodes a json value into a io::writer
pub fn to_writer(wr: io::Writer, json: &Json) {
- json.serialize(&Serializer(wr))
+ json.encode(&Encoder(wr))
}
-/// Serializes a json value into a string
+/// Encodes a json value into a string
pub pure fn to_str(json: &Json) -> ~str unsafe {
// ugh, should be safe
io::with_str_writer(|wr| to_writer(wr, json))
}
-/// Serializes a json value into a io::writer
+/// Encodes a json value into a io::writer
pub fn to_pretty_writer(wr: io::Writer, json: &Json) {
- json.serialize(&PrettySerializer(wr))
+ json.encode(&PrettyEncoder(wr))
}
-/// Serializes a json value into a string
+/// Encodes a json value into a string
pub fn to_pretty_str(json: &Json) -> ~str {
io::with_str_writer(|wr| to_pretty_writer(wr, json))
}
@@ -336,7 +334,7 @@
priv mut col: uint,
}
-/// Deserializes a json value from an io::reader
+/// Decode a json value from an io::reader
pub fn Parser(rdr: io::Reader) -> Parser {
Parser {
rdr: rdr,
@@ -695,28 +693,28 @@
}
}
-/// Deserializes a json value from an io::reader
+/// Decodes a json value from an io::reader
pub fn from_reader(rdr: io::Reader) -> Result<Json, Error> {
Parser(rdr).parse()
}
-/// Deserializes a json value from a string
+/// Decodes a json value from a string
pub fn from_str(s: &str) -> Result<Json, Error> {
do io::with_str_reader(s) |rdr| {
from_reader(rdr)
}
}
-pub struct Deserializer {
+pub struct Decoder {
priv json: Json,
priv mut stack: ~[&Json],
}
-pub fn Deserializer(json: Json) -> Deserializer {
- Deserializer { json: move json, stack: ~[] }
+pub fn Decoder(json: Json) -> Decoder {
+ Decoder { json: move json, stack: ~[] }
}
-priv impl Deserializer {
+priv impl Decoder {
fn peek(&self) -> &self/Json {
if self.stack.len() == 0 { self.stack.push(&self.json); }
vec::last(self.stack)
@@ -728,7 +726,7 @@
}
}
-pub impl Deserializer: serialization::Deserializer {
+pub impl Decoder: serialize::Decoder {
fn read_nil(&self) -> () {
debug!("read_nil");
match *self.pop() {