De-export std::{ebml, ebml2}. Part of #3583.
This commit is contained in:
parent
009a38044c
commit
fb83b40174
3 changed files with 41 additions and 89 deletions
|
@ -4,31 +4,6 @@
|
||||||
use core::Option;
|
use core::Option;
|
||||||
use option::{Some, None};
|
use option::{Some, None};
|
||||||
|
|
||||||
export Doc;
|
|
||||||
export doc_at;
|
|
||||||
export maybe_get_doc;
|
|
||||||
export get_doc;
|
|
||||||
export docs;
|
|
||||||
export tagged_docs;
|
|
||||||
export doc_data;
|
|
||||||
export doc_as_str;
|
|
||||||
export doc_as_u8;
|
|
||||||
export doc_as_u16;
|
|
||||||
export doc_as_u32;
|
|
||||||
export doc_as_u64;
|
|
||||||
export doc_as_i8;
|
|
||||||
export doc_as_i16;
|
|
||||||
export doc_as_i32;
|
|
||||||
export doc_as_i64;
|
|
||||||
export Writer;
|
|
||||||
export serializer;
|
|
||||||
export ebml_deserializer;
|
|
||||||
export EbmlDeserializer;
|
|
||||||
export deserializer;
|
|
||||||
export with_doc_data;
|
|
||||||
export get_doc;
|
|
||||||
export extensions;
|
|
||||||
|
|
||||||
type EbmlTag = {id: uint, size: uint};
|
type EbmlTag = {id: uint, size: uint};
|
||||||
|
|
||||||
type EbmlState = {ebml_tag: EbmlTag, tag_pos: uint, data_pos: uint};
|
type EbmlState = {ebml_tag: EbmlTag, tag_pos: uint, data_pos: uint};
|
||||||
|
@ -37,7 +12,7 @@ type EbmlState = {ebml_tag: EbmlTag, tag_pos: uint, data_pos: uint};
|
||||||
// separate modules within this file.
|
// separate modules within this file.
|
||||||
|
|
||||||
// ebml reading
|
// ebml reading
|
||||||
type Doc = {data: @~[u8], start: uint, end: uint};
|
pub type Doc = {data: @~[u8], start: uint, end: uint};
|
||||||
|
|
||||||
type TaggedDoc = {tag: uint, doc: Doc};
|
type TaggedDoc = {tag: uint, doc: Doc};
|
||||||
|
|
||||||
|
@ -72,11 +47,11 @@ fn vuint_at(data: &[u8], start: uint) -> {val: uint, next: uint} {
|
||||||
} else { error!("vint too big"); fail; }
|
} else { error!("vint too big"); fail; }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Doc(data: @~[u8]) -> Doc {
|
pub fn Doc(data: @~[u8]) -> Doc {
|
||||||
return {data: data, start: 0u, end: vec::len::<u8>(*data)};
|
return {data: data, start: 0u, end: vec::len::<u8>(*data)};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {
|
pub fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {
|
||||||
let elt_tag = vuint_at(*data, start);
|
let elt_tag = vuint_at(*data, start);
|
||||||
let elt_size = vuint_at(*data, elt_tag.next);
|
let elt_size = vuint_at(*data, elt_tag.next);
|
||||||
let end = elt_size.next + elt_size.val;
|
let end = elt_size.next + elt_size.val;
|
||||||
|
@ -84,7 +59,7 @@ fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {
|
||||||
doc: {data: data, start: elt_size.next, end: end}};
|
doc: {data: data, start: elt_size.next, end: end}};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_get_doc(d: Doc, tg: uint) -> Option<Doc> {
|
pub fn maybe_get_doc(d: Doc, tg: uint) -> Option<Doc> {
|
||||||
let mut pos = d.start;
|
let mut pos = d.start;
|
||||||
while pos < d.end {
|
while pos < d.end {
|
||||||
let elt_tag = vuint_at(*d.data, pos);
|
let elt_tag = vuint_at(*d.data, pos);
|
||||||
|
@ -101,7 +76,7 @@ fn maybe_get_doc(d: Doc, tg: uint) -> Option<Doc> {
|
||||||
return None::<Doc>;
|
return None::<Doc>;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_doc(d: Doc, tg: uint) -> Doc {
|
pub fn get_doc(d: Doc, tg: uint) -> Doc {
|
||||||
match maybe_get_doc(d, tg) {
|
match maybe_get_doc(d, tg) {
|
||||||
Some(d) => return d,
|
Some(d) => return d,
|
||||||
None => {
|
None => {
|
||||||
|
@ -111,7 +86,7 @@ fn get_doc(d: Doc, tg: uint) -> Doc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn docs(d: Doc, it: fn(uint, Doc) -> bool) {
|
pub fn docs(d: Doc, it: fn(uint, Doc) -> bool) {
|
||||||
let mut pos = d.start;
|
let mut pos = d.start;
|
||||||
while pos < d.end {
|
while pos < d.end {
|
||||||
let elt_tag = vuint_at(*d.data, pos);
|
let elt_tag = vuint_at(*d.data, pos);
|
||||||
|
@ -123,7 +98,7 @@ fn docs(d: Doc, it: fn(uint, Doc) -> bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tagged_docs(d: Doc, tg: uint, it: fn(Doc) -> bool) {
|
pub fn tagged_docs(d: Doc, tg: uint, it: fn(Doc) -> bool) {
|
||||||
let mut pos = d.start;
|
let mut pos = d.start;
|
||||||
while pos < d.end {
|
while pos < d.end {
|
||||||
let elt_tag = vuint_at(*d.data, pos);
|
let elt_tag = vuint_at(*d.data, pos);
|
||||||
|
@ -137,43 +112,43 @@ fn tagged_docs(d: Doc, tg: uint, it: fn(Doc) -> bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_data(d: Doc) -> ~[u8] { vec::slice::<u8>(*d.data, d.start, d.end) }
|
pub fn doc_data(d: Doc) -> ~[u8] { vec::slice::<u8>(*d.data, d.start, d.end) }
|
||||||
|
|
||||||
fn with_doc_data<T>(d: Doc, f: fn(x: &[u8]) -> T) -> T {
|
pub fn with_doc_data<T>(d: Doc, f: fn(x: &[u8]) -> T) -> T {
|
||||||
return f(vec::view(*d.data, d.start, d.end));
|
return f(vec::view(*d.data, d.start, d.end));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_str(d: Doc) -> ~str { return str::from_bytes(doc_data(d)); }
|
pub fn doc_as_str(d: Doc) -> ~str { return str::from_bytes(doc_data(d)); }
|
||||||
|
|
||||||
fn doc_as_u8(d: Doc) -> u8 {
|
pub fn doc_as_u8(d: Doc) -> u8 {
|
||||||
assert d.end == d.start + 1u;
|
assert d.end == d.start + 1u;
|
||||||
return (*d.data)[d.start];
|
return (*d.data)[d.start];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_u16(d: Doc) -> u16 {
|
pub fn doc_as_u16(d: Doc) -> u16 {
|
||||||
assert d.end == d.start + 2u;
|
assert d.end == d.start + 2u;
|
||||||
return io::u64_from_be_bytes(*d.data, d.start, 2u) as u16;
|
return io::u64_from_be_bytes(*d.data, d.start, 2u) as u16;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_u32(d: Doc) -> u32 {
|
pub fn doc_as_u32(d: Doc) -> u32 {
|
||||||
assert d.end == d.start + 4u;
|
assert d.end == d.start + 4u;
|
||||||
return io::u64_from_be_bytes(*d.data, d.start, 4u) as u32;
|
return io::u64_from_be_bytes(*d.data, d.start, 4u) as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_u64(d: Doc) -> u64 {
|
pub fn doc_as_u64(d: Doc) -> u64 {
|
||||||
assert d.end == d.start + 8u;
|
assert d.end == d.start + 8u;
|
||||||
return io::u64_from_be_bytes(*d.data, d.start, 8u);
|
return io::u64_from_be_bytes(*d.data, d.start, 8u);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_i8(d: Doc) -> i8 { doc_as_u8(d) as i8 }
|
pub fn doc_as_i8(d: Doc) -> i8 { doc_as_u8(d) as i8 }
|
||||||
fn doc_as_i16(d: Doc) -> i16 { doc_as_u16(d) as i16 }
|
pub fn doc_as_i16(d: Doc) -> i16 { doc_as_u16(d) as i16 }
|
||||||
fn doc_as_i32(d: Doc) -> i32 { doc_as_u32(d) as i32 }
|
pub fn doc_as_i32(d: Doc) -> i32 { doc_as_u32(d) as i32 }
|
||||||
fn doc_as_i64(d: Doc) -> i64 { doc_as_u64(d) as i64 }
|
pub fn doc_as_i64(d: Doc) -> i64 { doc_as_u64(d) as i64 }
|
||||||
|
|
||||||
// ebml writing
|
// ebml writing
|
||||||
type Writer_ = {writer: io::Writer, mut size_positions: ~[uint]};
|
type Writer_ = {writer: io::Writer, mut size_positions: ~[uint]};
|
||||||
|
|
||||||
enum Writer {
|
pub enum Writer {
|
||||||
Writer_(Writer_)
|
Writer_(Writer_)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +172,7 @@ fn write_vuint(w: io::Writer, n: uint) {
|
||||||
fail fmt!("vint to write too big: %?", n);
|
fail fmt!("vint to write too big: %?", n);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Writer(w: io::Writer) -> Writer {
|
pub fn Writer(w: io::Writer) -> Writer {
|
||||||
let size_positions: ~[uint] = ~[];
|
let size_positions: ~[uint] = ~[];
|
||||||
return Writer_({writer: w, mut size_positions: size_positions});
|
return Writer_({writer: w, mut size_positions: size_positions});
|
||||||
}
|
}
|
||||||
|
@ -409,11 +384,11 @@ impl ebml::Writer: serialization::Serializer {
|
||||||
type EbmlDeserializer_ = {mut parent: ebml::Doc,
|
type EbmlDeserializer_ = {mut parent: ebml::Doc,
|
||||||
mut pos: uint};
|
mut pos: uint};
|
||||||
|
|
||||||
enum EbmlDeserializer {
|
pub enum EbmlDeserializer {
|
||||||
EbmlDeserializer_(EbmlDeserializer_)
|
EbmlDeserializer_(EbmlDeserializer_)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ebml_deserializer(d: ebml::Doc) -> EbmlDeserializer {
|
pub fn ebml_deserializer(d: ebml::Doc) -> EbmlDeserializer {
|
||||||
EbmlDeserializer_({mut parent: d, mut pos: d.start})
|
EbmlDeserializer_({mut parent: d, mut pos: d.start})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,27 +3,6 @@ use serialization2;
|
||||||
// Simple Extensible Binary Markup Language (ebml) reader and writer on a
|
// Simple Extensible Binary Markup Language (ebml) reader and writer on a
|
||||||
// cursor model. See the specification here:
|
// cursor model. See the specification here:
|
||||||
// http://www.matroska.org/technical/specs/rfc/index.html
|
// http://www.matroska.org/technical/specs/rfc/index.html
|
||||||
export Doc;
|
|
||||||
export doc_at;
|
|
||||||
export maybe_get_doc;
|
|
||||||
export get_doc;
|
|
||||||
export docs;
|
|
||||||
export tagged_docs;
|
|
||||||
export doc_data;
|
|
||||||
export doc_as_str;
|
|
||||||
export doc_as_u8;
|
|
||||||
export doc_as_u16;
|
|
||||||
export doc_as_u32;
|
|
||||||
export doc_as_u64;
|
|
||||||
export doc_as_i8;
|
|
||||||
export doc_as_i16;
|
|
||||||
export doc_as_i32;
|
|
||||||
export doc_as_i64;
|
|
||||||
export Serializer;
|
|
||||||
export Deserializer;
|
|
||||||
export with_doc_data;
|
|
||||||
export get_doc;
|
|
||||||
export extensions;
|
|
||||||
|
|
||||||
struct EbmlTag {
|
struct EbmlTag {
|
||||||
id: uint,
|
id: uint,
|
||||||
|
@ -82,11 +61,11 @@ fn vuint_at(data: &[u8], start: uint) -> {val: uint, next: uint} {
|
||||||
} else { error!("vint too big"); fail; }
|
} else { error!("vint too big"); fail; }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Doc(data: @~[u8]) -> Doc {
|
pub fn Doc(data: @~[u8]) -> Doc {
|
||||||
Doc { data: data, start: 0u, end: vec::len::<u8>(*data) }
|
Doc { data: data, start: 0u, end: vec::len::<u8>(*data) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {
|
pub fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {
|
||||||
let elt_tag = vuint_at(*data, start);
|
let elt_tag = vuint_at(*data, start);
|
||||||
let elt_size = vuint_at(*data, elt_tag.next);
|
let elt_size = vuint_at(*data, elt_tag.next);
|
||||||
let end = elt_size.next + elt_size.val;
|
let end = elt_size.next + elt_size.val;
|
||||||
|
@ -96,7 +75,7 @@ fn doc_at(data: @~[u8], start: uint) -> TaggedDoc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_get_doc(d: Doc, tg: uint) -> Option<Doc> {
|
pub fn maybe_get_doc(d: Doc, tg: uint) -> Option<Doc> {
|
||||||
let mut pos = d.start;
|
let mut pos = d.start;
|
||||||
while pos < d.end {
|
while pos < d.end {
|
||||||
let elt_tag = vuint_at(*d.data, pos);
|
let elt_tag = vuint_at(*d.data, pos);
|
||||||
|
@ -109,7 +88,7 @@ fn maybe_get_doc(d: Doc, tg: uint) -> Option<Doc> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_doc(d: Doc, tg: uint) -> Doc {
|
pub fn get_doc(d: Doc, tg: uint) -> Doc {
|
||||||
match maybe_get_doc(d, tg) {
|
match maybe_get_doc(d, tg) {
|
||||||
Some(d) => d,
|
Some(d) => d,
|
||||||
None => {
|
None => {
|
||||||
|
@ -119,7 +98,7 @@ fn get_doc(d: Doc, tg: uint) -> Doc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn docs(d: Doc, it: fn(uint, Doc) -> bool) {
|
pub fn docs(d: Doc, it: fn(uint, Doc) -> bool) {
|
||||||
let mut pos = d.start;
|
let mut pos = d.start;
|
||||||
while pos < d.end {
|
while pos < d.end {
|
||||||
let elt_tag = vuint_at(*d.data, pos);
|
let elt_tag = vuint_at(*d.data, pos);
|
||||||
|
@ -132,7 +111,7 @@ fn docs(d: Doc, it: fn(uint, Doc) -> bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tagged_docs(d: Doc, tg: uint, it: fn(Doc) -> bool) {
|
pub fn tagged_docs(d: Doc, tg: uint, it: fn(Doc) -> bool) {
|
||||||
let mut pos = d.start;
|
let mut pos = d.start;
|
||||||
while pos < d.end {
|
while pos < d.end {
|
||||||
let elt_tag = vuint_at(*d.data, pos);
|
let elt_tag = vuint_at(*d.data, pos);
|
||||||
|
@ -147,38 +126,38 @@ fn tagged_docs(d: Doc, tg: uint, it: fn(Doc) -> bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_data(d: Doc) -> ~[u8] { vec::slice::<u8>(*d.data, d.start, d.end) }
|
pub fn doc_data(d: Doc) -> ~[u8] { vec::slice::<u8>(*d.data, d.start, d.end) }
|
||||||
|
|
||||||
fn with_doc_data<T>(d: Doc, f: fn(x: &[u8]) -> T) -> T {
|
pub fn with_doc_data<T>(d: Doc, f: fn(x: &[u8]) -> T) -> T {
|
||||||
f(vec::view(*d.data, d.start, d.end))
|
f(vec::view(*d.data, d.start, d.end))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_str(d: Doc) -> ~str { str::from_bytes(doc_data(d)) }
|
pub fn doc_as_str(d: Doc) -> ~str { str::from_bytes(doc_data(d)) }
|
||||||
|
|
||||||
fn doc_as_u8(d: Doc) -> u8 {
|
pub fn doc_as_u8(d: Doc) -> u8 {
|
||||||
assert d.end == d.start + 1u;
|
assert d.end == d.start + 1u;
|
||||||
(*d.data)[d.start]
|
(*d.data)[d.start]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_u16(d: Doc) -> u16 {
|
pub fn doc_as_u16(d: Doc) -> u16 {
|
||||||
assert d.end == d.start + 2u;
|
assert d.end == d.start + 2u;
|
||||||
io::u64_from_be_bytes(*d.data, d.start, 2u) as u16
|
io::u64_from_be_bytes(*d.data, d.start, 2u) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_u32(d: Doc) -> u32 {
|
pub fn doc_as_u32(d: Doc) -> u32 {
|
||||||
assert d.end == d.start + 4u;
|
assert d.end == d.start + 4u;
|
||||||
io::u64_from_be_bytes(*d.data, d.start, 4u) as u32
|
io::u64_from_be_bytes(*d.data, d.start, 4u) as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_u64(d: Doc) -> u64 {
|
pub fn doc_as_u64(d: Doc) -> u64 {
|
||||||
assert d.end == d.start + 8u;
|
assert d.end == d.start + 8u;
|
||||||
io::u64_from_be_bytes(*d.data, d.start, 8u)
|
io::u64_from_be_bytes(*d.data, d.start, 8u)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn doc_as_i8(d: Doc) -> i8 { doc_as_u8(d) as i8 }
|
pub fn doc_as_i8(d: Doc) -> i8 { doc_as_u8(d) as i8 }
|
||||||
fn doc_as_i16(d: Doc) -> i16 { doc_as_u16(d) as i16 }
|
pub fn doc_as_i16(d: Doc) -> i16 { doc_as_u16(d) as i16 }
|
||||||
fn doc_as_i32(d: Doc) -> i32 { doc_as_u32(d) as i32 }
|
pub fn doc_as_i32(d: Doc) -> i32 { doc_as_u32(d) as i32 }
|
||||||
fn doc_as_i64(d: Doc) -> i64 { doc_as_u64(d) as i64 }
|
pub fn doc_as_i64(d: Doc) -> i64 { doc_as_u64(d) as i64 }
|
||||||
|
|
||||||
// ebml writing
|
// ebml writing
|
||||||
struct Serializer {
|
struct Serializer {
|
||||||
|
@ -206,7 +185,7 @@ fn write_vuint(w: io::Writer, n: uint) {
|
||||||
fail fmt!("vint to write too big: %?", n);
|
fail fmt!("vint to write too big: %?", n);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Serializer(w: io::Writer) -> Serializer {
|
pub fn Serializer(w: io::Writer) -> Serializer {
|
||||||
let size_positions: ~[uint] = ~[];
|
let size_positions: ~[uint] = ~[];
|
||||||
Serializer { writer: w, mut size_positions: size_positions }
|
Serializer { writer: w, mut size_positions: size_positions }
|
||||||
}
|
}
|
||||||
|
@ -450,7 +429,7 @@ struct Deserializer {
|
||||||
priv mut pos: uint,
|
priv mut pos: uint,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Deserializer(d: Doc) -> Deserializer {
|
pub fn Deserializer(d: Doc) -> Deserializer {
|
||||||
Deserializer { mut parent: d, mut pos: d.start }
|
Deserializer { mut parent: d, mut pos: d.start }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,9 +89,7 @@ mod treemap;
|
||||||
|
|
||||||
// And ... other stuff
|
// And ... other stuff
|
||||||
|
|
||||||
#[legacy_exports]
|
|
||||||
mod ebml;
|
mod ebml;
|
||||||
#[legacy_exports]
|
|
||||||
mod ebml2;
|
mod ebml2;
|
||||||
mod dbg;
|
mod dbg;
|
||||||
#[legacy_exports]
|
#[legacy_exports]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue