@@ -6,6 +6,7 @@ use zerocopy::{AsBytes, FromBytes, FromZeroes};
6
6
7
7
use crate :: io:: buf:: { ZeroCopyBoxIoBuf , ZeroCopyBuf } ;
8
8
use crate :: io:: FileExt ;
9
+ use crate :: { LIBSQL_MAGIC , LIBSQL_PAGE_SIZE , LIBSQL_WAL_VERSION } ;
9
10
10
11
use super :: { Frame , Result } ;
11
12
@@ -19,6 +20,25 @@ pub struct CompactedSegmentDataHeader {
19
20
pub ( crate ) start_frame_no : lu64 ,
20
21
pub ( crate ) end_frame_no : lu64 ,
21
22
pub ( crate ) size_after : lu32 ,
23
+ /// for now, always 4096
24
+ pub ( crate ) page_size : lu16 ,
25
+ }
26
+ impl CompactedSegmentDataHeader {
27
+ fn check ( & self ) -> Result < ( ) > {
28
+ if self . magic . get ( ) != LIBSQL_MAGIC {
29
+ return Err ( super :: Error :: InvalidHeaderMagic ) ;
30
+ }
31
+
32
+ if self . page_size . get ( ) != LIBSQL_PAGE_SIZE {
33
+ return Err ( super :: Error :: InvalidPageSize ) ;
34
+ }
35
+
36
+ if self . version . get ( ) != LIBSQL_WAL_VERSION {
37
+ return Err ( super :: Error :: InvalidPageSize ) ;
38
+ }
39
+
40
+ Ok ( ( ) )
41
+ }
22
42
}
23
43
24
44
#[ derive( Debug , AsBytes , FromZeroes , FromBytes ) ]
@@ -37,7 +57,8 @@ impl<F: FileExt> CompactedSegment<F> {
37
57
let buf = ZeroCopyBuf :: new_uninit ( ) ;
38
58
let ( buf, ret) = file. read_exact_at_async ( buf, 0 ) . await ;
39
59
ret?;
40
- let header = buf. into_inner ( ) ;
60
+ let header: CompactedSegmentDataHeader = buf. into_inner ( ) ;
61
+ header. check ( ) ?;
41
62
Ok ( Self { file, header } )
42
63
}
43
64
0 commit comments