@@ -60,6 +60,7 @@ pub enum BinaryFrame {
6060 mode : u8 , // 0 = exec, 1 = run
6161 file_path : String ,
6262 bridge_code : String ,
63+ post_restore_script : String ,
6364 user_code : String ,
6465 } ,
6566 BridgeResponse {
@@ -224,6 +225,7 @@ fn encode_body(buf: &mut Vec<u8>, frame: &BinaryFrame) -> io::Result<()> {
224225 mode,
225226 file_path,
226227 bridge_code,
228+ post_restore_script,
227229 user_code,
228230 } => {
229231 buf. push ( MSG_EXECUTE ) ;
@@ -235,6 +237,10 @@ fn encode_body(buf: &mut Vec<u8>, frame: &BinaryFrame) -> io::Result<()> {
235237 let bc_bytes = bridge_code. as_bytes ( ) ;
236238 buf. extend_from_slice ( & ( bc_bytes. len ( ) as u32 ) . to_be_bytes ( ) ) ;
237239 buf. extend_from_slice ( bc_bytes) ;
240+ // post_restore_script length (u32 BE)
241+ let prs_bytes = post_restore_script. as_bytes ( ) ;
242+ buf. extend_from_slice ( & ( prs_bytes. len ( ) as u32 ) . to_be_bytes ( ) ) ;
243+ buf. extend_from_slice ( prs_bytes) ;
238244 // user_code (rest of frame)
239245 buf. extend_from_slice ( user_code. as_bytes ( ) ) ;
240246 }
@@ -377,13 +383,16 @@ fn decode_body(buf: &[u8]) -> io::Result<BinaryFrame> {
377383 let file_path = read_utf8 ( buf, & mut pos, fp_len) ?;
378384 let bc_len = read_u32 ( buf, & mut pos) ? as usize ;
379385 let bridge_code = read_utf8 ( buf, & mut pos, bc_len) ?;
386+ let prs_len = read_u32 ( buf, & mut pos) ? as usize ;
387+ let post_restore_script = read_utf8 ( buf, & mut pos, prs_len) ?;
380388 let remaining = buf. len ( ) - pos;
381389 let user_code = read_utf8 ( buf, & mut pos, remaining) ?;
382390 Ok ( BinaryFrame :: Execute {
383391 session_id,
384392 mode,
385393 file_path,
386394 bridge_code,
395+ post_restore_script,
387396 user_code,
388397 } )
389398 }
@@ -640,6 +649,7 @@ mod tests {
640649 mode : 0 ,
641650 file_path : "" . into ( ) ,
642651 bridge_code : "(function(){ /* bridge */ })()" . into ( ) ,
652+ post_restore_script : "" . into ( ) ,
643653 user_code : "console.log('hello')" . into ( ) ,
644654 } ) ;
645655 }
@@ -651,6 +661,7 @@ mod tests {
651661 mode : 1 ,
652662 file_path : "/app/index.mjs" . into ( ) ,
653663 bridge_code : "(function(){ /* bridge */ })()" . into ( ) ,
664+ post_restore_script : "__runtimeApplyConfig({})" . into ( ) ,
654665 user_code : "export default 42" . into ( ) ,
655666 } ) ;
656667 }
@@ -900,6 +911,7 @@ mod tests {
900911 mode: 0 ,
901912 file_path: "" . into( ) ,
902913 bridge_code: "bridge()" . into( ) ,
914+ post_restore_script: "" . into( ) ,
903915 user_code: "1+1" . into( ) ,
904916 } ,
905917 BinaryFrame :: DestroySession {
@@ -989,6 +1001,7 @@ mod tests {
9891001 mode: 0 ,
9901002 file_path: "" . into( ) ,
9911003 bridge_code: "" . into( ) ,
1004+ post_restore_script: "" . into( ) ,
9921005 user_code: "" . into( ) ,
9931006 } ,
9941007 BinaryFrame :: BridgeResponse {
@@ -1085,6 +1098,7 @@ mod tests {
10851098 mode: 0 ,
10861099 file_path: "" . into( ) ,
10871100 bridge_code: "" . into( ) ,
1101+ post_restore_script: "" . into( ) ,
10881102 user_code: "" . into( ) ,
10891103 } ,
10901104 0x05 ,
@@ -1354,6 +1368,7 @@ mod tests {
13541368 mode : 0 ,
13551369 file_path : long_path,
13561370 bridge_code : "" . into ( ) ,
1371+ post_restore_script : "" . into ( ) ,
13571372 user_code : "" . into ( ) ,
13581373 } ;
13591374 let result = frame_to_bytes ( & frame) ;
0 commit comments