remove serialize::ebml, add librbml
Our implementation of ebml has diverged from the standard in order to better serve the needs of the compiler, so it doesn't make much sense to call what we have ebml anyore. Furthermore, our implementation is pretty crufty, and should eventually be rewritten into a format that better suits the needs of the compiler. This patch factors out serialize::ebml into librbml, otherwise known as the Really Bad Markup Language. This is a stopgap library that shouldn't be used by end users, and will eventually be replaced by something better. [breaking-change]
This commit is contained in:
parent
ea1b637654
commit
e1dcbefe52
12 changed files with 895 additions and 877 deletions
|
|
@ -10,33 +10,33 @@
|
|||
|
||||
// ignore-test FIXME(#5121)
|
||||
|
||||
|
||||
extern crate time;
|
||||
extern crate rbml;
|
||||
extern crate serialize;
|
||||
extern crate time;
|
||||
|
||||
// These tests used to be separate files, but I wanted to refactor all
|
||||
// the common code.
|
||||
|
||||
use std::hashmap::{HashMap, HashSet};
|
||||
|
||||
use EBReader = serialize::ebml::reader;
|
||||
use EBWriter = serialize::ebml::writer;
|
||||
use EBReader = rbml::reader;
|
||||
use EBWriter = rbml::writer;
|
||||
use std::cmp::Eq;
|
||||
use std::cmp;
|
||||
use std::io;
|
||||
use serialize::{Decodable, Encodable};
|
||||
|
||||
fn test_ebml<'a, 'b, A:
|
||||
fn test_rbml<'a, 'b, A:
|
||||
Eq +
|
||||
Encodable<EBWriter::Encoder<'a>> +
|
||||
Decodable<EBReader::Decoder<'b>>
|
||||
>(a1: &A) {
|
||||
let mut wr = std::io::MemWriter::new();
|
||||
let mut ebml_w = EBwriter::Encoder::new(&mut wr);
|
||||
a1.encode(&mut ebml_w);
|
||||
let mut rbml_w = EBwriter::Encoder::new(&mut wr);
|
||||
a1.encode(&mut rbml_w);
|
||||
let bytes = wr.get_ref();
|
||||
|
||||
let d: serialize::ebml::Doc<'a> = EBDoc::new(bytes);
|
||||
let d: serialize::rbml::Doc<'a> = EBDoc::new(bytes);
|
||||
let mut decoder: EBReader::Decoder<'a> = EBreader::Decoder::new(d);
|
||||
let a2: A = Decodable::decode(&mut decoder);
|
||||
assert!(*a1 == a2);
|
||||
|
|
@ -133,40 +133,40 @@ enum CLike { A, B, C }
|
|||
|
||||
pub fn main() {
|
||||
let a = &Plus(@Minus(@Val(3u), @Val(10u)), @Plus(@Val(22u), @Val(5u)));
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &Spanned {lo: 0u, hi: 5u, node: 22u};
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &Point {x: 3u, y: 5u};
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &Top(22u);
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &Bottom(222u);
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &A;
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &B;
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
let a = &time::now();
|
||||
test_ebml(a);
|
||||
test_rbml(a);
|
||||
|
||||
test_ebml(&1.0f32);
|
||||
test_ebml(&1.0f64);
|
||||
test_ebml(&'a');
|
||||
test_rbml(&1.0f32);
|
||||
test_rbml(&1.0f64);
|
||||
test_rbml(&'a');
|
||||
|
||||
let mut a = HashMap::new();
|
||||
test_ebml(&a);
|
||||
test_rbml(&a);
|
||||
a.insert(1, 2);
|
||||
test_ebml(&a);
|
||||
test_rbml(&a);
|
||||
|
||||
let mut a = HashSet::new();
|
||||
test_ebml(&a);
|
||||
test_rbml(&a);
|
||||
a.insert(1);
|
||||
test_ebml(&a);
|
||||
test_rbml(&a);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,15 +16,16 @@
|
|||
#![feature(struct_variant)]
|
||||
|
||||
extern crate rand;
|
||||
extern crate rbml;
|
||||
extern crate serialize;
|
||||
|
||||
use std::io::MemWriter;
|
||||
use rand::{random, Rand};
|
||||
use rbml;
|
||||
use rbml::Doc;
|
||||
use rbml::writer::Encoder;
|
||||
use rbml::reader::Decoder;
|
||||
use serialize::{Encodable, Decodable};
|
||||
use serialize::ebml;
|
||||
use serialize::ebml::Doc;
|
||||
use serialize::ebml::writer::Encoder;
|
||||
use serialize::ebml::reader::Decoder;
|
||||
|
||||
#[deriving(Encodable, Decodable, Eq, Rand)]
|
||||
struct A;
|
||||
|
|
@ -61,7 +62,7 @@ fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder<'a>> +
|
|||
let mut w = MemWriter::new();
|
||||
let mut e = Encoder::new(&mut w);
|
||||
obj.encode(&mut e);
|
||||
let doc = ebml::Doc::new(@w.get_ref());
|
||||
let doc = rbml::Doc::new(@w.get_ref());
|
||||
let mut dec = Decoder::new(doc);
|
||||
let obj2 = Decodable::decode(&mut dec);
|
||||
assert!(obj == obj2);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
extern crate rbml;
|
||||
extern crate serialize;
|
||||
|
||||
use std::io;
|
||||
|
|
@ -16,7 +17,7 @@ use std::slice;
|
|||
|
||||
use serialize::{Encodable, Encoder};
|
||||
use serialize::json;
|
||||
use serialize::ebml::writer;
|
||||
use rbml::writer;
|
||||
|
||||
static BUF_CAPACITY: uint = 128;
|
||||
|
||||
|
|
@ -144,7 +145,7 @@ struct Bar {
|
|||
|
||||
enum WireProtocol {
|
||||
JSON,
|
||||
EBML,
|
||||
RBML,
|
||||
// ...
|
||||
}
|
||||
|
||||
|
|
@ -155,7 +156,7 @@ fn encode_json<'a,
|
|||
let mut encoder = json::Encoder::new(wr);
|
||||
val.encode(&mut encoder);
|
||||
}
|
||||
fn encode_ebml<'a,
|
||||
fn encode_rbml<'a,
|
||||
T: Encodable<writer::Encoder<'a, SeekableMemWriter>,
|
||||
std::io::IoError>>(val: &T,
|
||||
wr: &'a mut SeekableMemWriter) {
|
||||
|
|
@ -169,6 +170,6 @@ pub fn main() {
|
|||
let proto = JSON;
|
||||
match proto {
|
||||
JSON => encode_json(&target, &mut wr),
|
||||
EBML => encode_ebml(&target, &mut wr)
|
||||
RBML => encode_rbml(&target, &mut wr)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue