@@ -7,7 +7,6 @@ pub(super) struct AnyCursor<T: Type = Body>(usize, PhantomData<T>);
77
88pub ( super ) type BodyCursor = AnyCursor < Body > ;
99pub ( super ) type TitleCursor = AnyCursor < Title > ;
10- pub ( super ) type GroupCursor = AnyCursor < Group > ;
1110pub ( super ) type PropCursor = AnyCursor < Prop > ;
1211
1312pub ( super ) trait Type { }
@@ -17,13 +16,10 @@ pub(super) struct Body {}
1716#[ derive( Clone , Copy , Debug ) ]
1817pub ( super ) struct Title { }
1918#[ derive( Clone , Copy , Debug ) ]
20- pub ( super ) struct Group { }
21- #[ derive( Clone , Copy , Debug ) ]
2219pub ( super ) struct Prop { }
2320
2421impl Type for Body { }
2522impl Type for Title { }
26- impl Type for Group { }
2723impl Type for Prop { }
2824
2925pub enum MoveResult {
@@ -107,7 +103,7 @@ impl BodyCursor {
107103 self . 0 += 1 ;
108104 MoveResult :: Others
109105 }
110- _ => todo ! ( ) ,
106+ _ => todo ! ( "unknown block {}" , structure [ self . 0 ] ) ,
111107 }
112108 }
113109
@@ -149,10 +145,10 @@ impl TitleCursor {
149145 }
150146
151147 /// 生成组光标。
152- pub fn take_group_on ( & self , dtb : RefDtb , name : & str ) -> ( GroupCursor , usize , BodyCursor ) {
148+ pub fn take_group_on ( & self , dtb : RefDtb , name : & str ) -> ( BodyCursor , usize , BodyCursor ) {
153149 let name_bytes = name. as_bytes ( ) ;
154150 let name_skip = align ( name_bytes. len ( ) + 1 , BLOCK_LEN ) ;
155- let group = AnyCursor :: < Group > ( self . 0 , PhantomData ) ;
151+ let group = AnyCursor :: < Body > ( self . 0 , PhantomData ) ;
156152
157153 let mut body = AnyCursor :: < Body > ( self . 0 + 1 + name_skip, PhantomData ) ;
158154 let mut len = 1 ;
@@ -194,57 +190,6 @@ impl TitleCursor {
194190 }
195191}
196192
197- impl GroupCursor {
198- /// 读取缓存的下一项偏移。
199- pub fn offset_on ( & self , dtb : RefDtb ) -> usize {
200- ( dtb. borrow ( ) . structure [ self . 0 ] . 0 >> 8 ) as _
201- }
202-
203- /// 利用缓存的名字长度取出名字。
204- pub fn name_on < ' a > ( & self , dtb : RefDtb < ' a > ) -> ( & ' a [ u8 ] , BodyCursor ) {
205- let structure = & dtb. borrow ( ) . structure ;
206- let len_name = ( structure[ self . 0 ] . 0 & 0xff ) as usize ;
207- let bytes = structure[ self . 0 + 1 ] . lead_slice ( len_name) ;
208- (
209- bytes,
210- AnyCursor ( self . 0 + 1 + align ( len_name + 1 , BLOCK_LEN ) , PhantomData ) ,
211- )
212- }
213-
214- /// 初始化组反序列化。
215- pub fn init_on ( & self , dtb : RefDtb , len_item : usize , len_name : usize ) {
216- let mut body = AnyCursor :: < Body > ( self . 0 , PhantomData ) ;
217- for _ in 0 ..len_item {
218- let current = body. 0 ;
219- let len_total = dtb. borrow ( ) . structure [ current + 1 ]
220- . lead_slice ( u16:: MAX as _ )
221- . iter ( )
222- . enumerate ( )
223- . skip ( len_name + 1 )
224- . find ( |( _, b) | * * b == b'\0' )
225- . map ( |( i, _) | i)
226- . unwrap ( ) ;
227- body. step_n ( align ( len_total, BLOCK_LEN ) ) ;
228- body. skip_str_on ( dtb) ;
229- body. escape_from ( dtb) ;
230- let off_next = body. 0 - current;
231- dtb. borrow_mut ( ) . structure [ current] . 0 = ( off_next << 8 | len_total) as _ ;
232- }
233- }
234-
235- /// 组结构恢复原状。
236- pub fn drop_on ( & self , dtb : RefDtb , len_item : usize ) {
237- use StructureBlock as B ;
238- let structure = & mut * dtb. borrow_mut ( ) . structure ;
239- let mut i = self . 0 ;
240- for _ in 0 ..len_item {
241- let offset = ( structure[ i] . 0 >> 8 ) as usize ;
242- structure[ i] = B :: NODE_BEGIN ;
243- i += offset;
244- }
245- }
246- }
247-
248193impl PropCursor {
249194 pub fn name_on < ' a > ( & self , dtb : RefDtb < ' a > ) -> ( & ' a str , BodyCursor ) {
250195 let dtb = dtb. borrow ( ) ;
0 commit comments