@@ -51,34 +51,32 @@ pub enum EbmlEncoderTag {
51
51
EsI16 , // 8
52
52
EsI8 , // 9
53
53
EsBool , // 10
54
- EsChar , // 11
55
- EsStr , // 12
56
- EsF64 , // 13
57
- EsF32 , // 14
58
- EsFloat , // 15
59
- EsEnum , // 16
60
- EsEnumVid , // 17
61
- EsEnumBody , // 18
62
- EsVec , // 19
63
- EsVecLen , // 20
64
- EsVecElt , // 21
65
- EsMap , // 22
66
- EsMapLen , // 23
67
- EsMapKey , // 24
68
- EsMapVal , // 25
54
+ EsStr , // 11
55
+ EsF64 , // 12
56
+ EsF32 , // 13
57
+ EsFloat , // 14
58
+ EsEnum , // 15
59
+ EsEnumVid , // 16
60
+ EsEnumBody , // 17
61
+ EsVec , // 18
62
+ EsVecLen , // 19
63
+ EsVecElt , // 20
69
64
70
65
EsOpaque ,
71
66
72
- EsLabel , // Used only when debugging
67
+ EsLabel // Used only when debugging
73
68
}
74
69
// --------------------------------------
75
70
76
71
pub mod reader {
77
- use super :: * ;
72
+ use core :: prelude :: * ;
78
73
74
+ use ebml:: { Doc , EbmlEncoderTag , EsBool , EsEnum , EsEnumBody , EsEnumVid } ;
75
+ use ebml:: { EsI16 , EsI32 , EsI64 , EsI8 , EsInt } ;
76
+ use ebml:: { EsLabel , EsOpaque , EsStr , EsU16 , EsU32 , EsU64 , EsU8 , EsUint } ;
77
+ use ebml:: { EsVec , EsVecElt , EsVecLen , TaggedDoc } ;
79
78
use serialize;
80
79
81
- use core:: prelude:: * ;
82
80
use core:: cast:: transmute;
83
81
use core:: int;
84
82
use core:: io;
@@ -323,14 +321,12 @@ pub mod reader {
323
321
r_doc
324
322
}
325
323
326
- fn push_doc < T > ( & mut self , exp_tag : EbmlEncoderTag ,
327
- f : & fn ( & mut Decoder ) -> T ) -> T {
328
- let d = self . next_doc ( exp_tag) ;
324
+ fn push_doc < T > ( & mut self , d : Doc , f : & fn ( ) -> T ) -> T {
329
325
let old_parent = self . parent ;
330
326
let old_pos = self . pos ;
331
327
self . parent = d;
332
328
self . pos = d. start ;
333
- let r = f ( self ) ;
329
+ let r = f ( ) ;
334
330
self . parent = old_parent;
335
331
self . pos = old_pos;
336
332
r
@@ -399,21 +395,10 @@ pub mod reader {
399
395
doc_as_u8 ( self . next_doc ( EsBool ) ) as bool
400
396
}
401
397
402
- fn read_f64 ( & mut self ) -> f64 {
403
- let bits = doc_as_u64 ( self . next_doc ( EsF64 ) ) ;
404
- unsafe { transmute ( bits) }
405
- }
406
- fn read_f32 ( & mut self ) -> f32 {
407
- let bits = doc_as_u32 ( self . next_doc ( EsF32 ) ) ;
408
- unsafe { transmute ( bits) }
409
- }
410
- fn read_float ( & mut self ) -> float {
411
- let bits = doc_as_u64 ( self . next_doc ( EsFloat ) ) ;
412
- ( unsafe { transmute :: < u64 , f64 > ( bits) } ) as float
413
- }
414
- fn read_char ( & mut self ) -> char {
415
- doc_as_u32 ( self . next_doc ( EsChar ) ) as char
416
- }
398
+ fn read_f64 ( & mut self ) -> f64 { fail ! ( "read_f64()" ) ; }
399
+ fn read_f32 ( & mut self ) -> f32 { fail ! ( "read_f32()" ) ; }
400
+ fn read_float ( & mut self ) -> float { fail ! ( "read_float()" ) ; }
401
+ fn read_char ( & mut self ) -> char { fail ! ( "read_char()" ) ; }
417
402
fn read_str ( & mut self ) -> ~str { doc_as_str ( self . next_doc ( EsStr ) ) }
418
403
419
404
// Compound types:
@@ -556,50 +541,66 @@ pub mod reader {
556
541
557
542
fn read_seq < T > ( & mut self , f : & fn ( & mut Decoder , uint ) -> T ) -> T {
558
543
debug ! ( "read_seq()" ) ;
559
- do self. push_doc ( EsVec ) |d| {
560
- let len = d. _next_uint ( EsVecLen ) ;
561
- debug ! ( " len=%u" , len) ;
562
- f ( d, len)
563
- }
544
+ let doc = self . next_doc ( EsVec ) ;
545
+
546
+ let ( old_parent, old_pos) = ( self . parent , self . pos ) ;
547
+ self . parent = doc;
548
+ self . pos = self . parent . start ;
549
+
550
+ let len = self . _next_uint ( EsVecLen ) ;
551
+ debug ! ( " len=%u" , len) ;
552
+ let result = f ( self , len) ;
553
+
554
+ self . parent = old_parent;
555
+ self . pos = old_pos;
556
+ result
564
557
}
565
558
566
559
fn read_seq_elt < T > ( & mut self , idx : uint , f : & fn ( & mut Decoder ) -> T )
567
560
-> T {
568
561
debug ! ( "read_seq_elt(idx=%u)" , idx) ;
569
- self . push_doc ( EsVecElt , f)
562
+ let doc = self . next_doc ( EsVecElt ) ;
563
+
564
+ let ( old_parent, old_pos) = ( self . parent , self . pos ) ;
565
+ self . parent = doc;
566
+ self . pos = self . parent . start ;
567
+
568
+ let result = f ( self ) ;
569
+
570
+ self . parent = old_parent;
571
+ self . pos = old_pos;
572
+ result
570
573
}
571
574
572
- fn read_map < T > ( & mut self , f : & fn ( & mut Decoder , uint ) -> T ) -> T {
575
+ fn read_map < T > ( & mut self , _ : & fn ( & mut Decoder , uint ) -> T ) -> T {
573
576
debug ! ( "read_map()" ) ;
574
- do self. push_doc ( EsMap ) |d| {
575
- let len = d. _next_uint ( EsMapLen ) ;
576
- debug ! ( " len=%u" , len) ;
577
- f ( d, len)
578
- }
577
+ fail ! ( "read_map is unimplemented" ) ;
579
578
}
580
579
581
580
fn read_map_elt_key < T > ( & mut self ,
582
581
idx : uint ,
583
- f : & fn ( & mut Decoder ) -> T )
582
+ _ : & fn ( & mut Decoder ) -> T )
584
583
-> T {
585
584
debug ! ( "read_map_elt_key(idx=%u)" , idx) ;
586
- self . push_doc ( EsMapKey , f )
585
+ fail ! ( "read_map_elt_val is unimplemented" ) ;
587
586
}
588
587
589
588
fn read_map_elt_val < T > ( & mut self ,
590
589
idx : uint ,
591
- f : & fn ( & mut Decoder ) -> T )
590
+ _ : & fn ( & mut Decoder ) -> T )
592
591
-> T {
593
592
debug ! ( "read_map_elt_val(idx=%u)" , idx) ;
594
- self . push_doc ( EsMapVal , f )
593
+ fail ! ( "read_map_elt_val is unimplemented" ) ;
595
594
}
596
595
}
597
596
}
598
597
599
598
pub mod writer {
600
- use super :: * ;
599
+ use ebml:: { EbmlEncoderTag , EsBool , EsEnum , EsEnumBody , EsEnumVid } ;
600
+ use ebml:: { EsI16 , EsI32 , EsI64 , EsI8 , EsInt } ;
601
+ use ebml:: { EsLabel , EsOpaque , EsStr , EsU16 , EsU32 , EsU64 , EsU8 , EsUint } ;
602
+ use ebml:: { EsVec , EsVecElt , EsVecLen } ;
601
603
602
- use core:: cast;
603
604
use core:: io;
604
605
use core:: str;
605
606
@@ -805,21 +806,19 @@ pub mod writer {
805
806
self . wr_tagged_u8 ( EsBool as uint , v as u8 )
806
807
}
807
808
808
- fn emit_f64 ( & mut self , v : f64 ) {
809
- let bits = unsafe { cast :: transmute ( v ) } ;
810
- self . wr_tagged_u64 ( EsF64 as uint , bits ) ;
809
+ // FIXME (#2742): implement these
810
+ fn emit_f64 ( & mut self , _v : f64 ) {
811
+ fail ! ( "Unimplemented: serializing an f64" ) ;
811
812
}
812
- fn emit_f32 ( & mut self , v : f32 ) {
813
- let bits = unsafe { cast:: transmute ( v) } ;
814
- self . wr_tagged_u32 ( EsF32 as uint , bits) ;
813
+ fn emit_f32 ( & mut self , _v : f32 ) {
814
+ fail ! ( "Unimplemented: serializing an f32" ) ;
815
815
}
816
- fn emit_float ( & mut self , v : float ) {
817
- let bits = unsafe { cast:: transmute ( v as f64 ) } ;
818
- self . wr_tagged_u64 ( EsFloat as uint , bits) ;
816
+ fn emit_float ( & mut self , _v : float ) {
817
+ fail ! ( "Unimplemented: serializing a float" ) ;
819
818
}
820
819
821
- fn emit_char ( & mut self , v : char ) {
822
- self . wr_tagged_u32 ( EsChar as uint , v as u32 ) ;
820
+ fn emit_char ( & mut self , _v : char ) {
821
+ fail ! ( "Unimplemented: serializing a char" ) ;
823
822
}
824
823
825
824
fn emit_str ( & mut self , v : & str ) {
@@ -915,23 +914,16 @@ pub mod writer {
915
914
self . end_tag ( ) ;
916
915
}
917
916
918
- fn emit_map ( & mut self , len : uint , f : & fn ( & mut Encoder ) ) {
919
- self . start_tag ( EsMap as uint ) ;
920
- self . _emit_tagged_uint ( EsMapLen , len) ;
921
- f ( self ) ;
922
- self . end_tag ( ) ;
917
+ fn emit_map ( & mut self , _len : uint , _f : & fn ( & mut Encoder ) ) {
918
+ fail ! ( "emit_map is unimplemented" ) ;
923
919
}
924
920
925
- fn emit_map_elt_key ( & mut self , _idx : uint , f : & fn ( & mut Encoder ) ) {
926
- self . start_tag ( EsMapKey as uint ) ;
927
- f ( self ) ;
928
- self . end_tag ( ) ;
921
+ fn emit_map_elt_key ( & mut self , _idx : uint , _f : & fn ( & mut Encoder ) ) {
922
+ fail ! ( "emit_map_elt_key is unimplemented" ) ;
929
923
}
930
924
931
- fn emit_map_elt_val ( & mut self , _idx : uint , f : & fn ( & mut Encoder ) ) {
932
- self . start_tag ( EsMapVal as uint ) ;
933
- f ( self ) ;
934
- self . end_tag ( ) ;
925
+ fn emit_map_elt_val ( & mut self , _idx : uint , _f : & fn ( & mut Encoder ) ) {
926
+ fail ! ( "emit_map_elt_val is unimplemented" ) ;
935
927
}
936
928
}
937
929
}
0 commit comments