// Returns the size of the struct in bytes *as written*,
// along with the struct itself future-proofed to the latest version.
Returns the size of the struct in bytes *as written*,
along with the struct itself future-proofed to the latest version.
Returns the size of the struct in bytes * as written * along with the struct itself future - proofed to the latest version .
pub fn from_bytes(bytes: &[u8], version: u8) -> (u64, Self) {
        match version {
            // The version 1 header didn't have the size of the header struct itself
            // embedded within it, so we fake it.
            1 => {
                (48, // This is the size
                 Header { member_len:         LittleEndian::read_u64(&bytes[0..8]),
                          service_len:        LittleEndian::read_u64(&bytes[8..16]),
                          service_config_len: LittleEndian::read_u64(&bytes[16..24]),
                          service_file_len:   LittleEndian::read_u64(&bytes[24..32]),
                          election_len:       LittleEndian::read_u64(&bytes[32..40]),
                          update_len:         LittleEndian::read_u64(&bytes[40..48]),
                          departure_len:      0, })
            }
            // This should be the latest version of the header. As we deprecate
            // header versions, just roll this code up, and match it, then add
            // your new structure.
            //
            // So copy this struct to the last version number. Then add 8 to the previous struct's
            // (the size of a 64 bit integer) size. Then start the empty fields at 0. The result
            // will be that you read the back-compat version of the data format, and then write the
            // new.
            _ => {
                (LittleEndian::read_u64(&bytes[0..8]),
                 Header { member_len:         LittleEndian::read_u64(&bytes[8..16]),
                          service_len:        LittleEndian::read_u64(&bytes[16..24]),
                          service_config_len: LittleEndian::read_u64(&bytes[24..32]),
                          service_file_len:   LittleEndian::read_u64(&bytes[32..40]),
                          election_len:       LittleEndian::read_u64(&bytes[40..48]),
                          update_len:         LittleEndian::read_u64(&bytes[48..56]),
                          departure_len:      LittleEndian::read_u64(&bytes[56..64]), })
            }
        }
    }
pub fn from_bytes ( bytes : & [ u8 ] , version : u8 ) -> ( u64 , Self ) { match version { // The version 1 header didn't have the size of the header struct itself // embedded within it, so we fake it. 1 => { ( 48 , // This is the size Header { member_len : LittleEndian :: read_u64 ( & bytes [ 0 .. 8 ] ) , service_len : LittleEndian :: read_u64 ( & bytes [ 8 .. 16 ] ) , service_config_len : LittleEndian :: read_u64 ( & bytes [ 16 .. 24 ] ) , service_file_len : LittleEndian :: read_u64 ( & bytes [ 24 .. 32 ] ) , election_len : LittleEndian :: read_u64 ( & bytes [ 32 .. 40 ] ) , update_len : LittleEndian :: read_u64 ( & bytes [ 40 .. 48 ] ) , departure_len : 0 , } ) } // This should be the latest version of the header. As we deprecate // header versions, just roll this code up, and match it, then add // your new structure. // // So copy this struct to the last version number. Then add 8 to the previous struct's // (the size of a 64 bit integer) size. Then start the empty fields at 0. The result // will be that you read the back-compat version of the data format, and then write the // new. _ => { ( LittleEndian :: read_u64 ( & bytes [ 0 .. 8 ] ) , Header { member_len : LittleEndian :: read_u64 ( & bytes [ 8 .. 16 ] ) , service_len : LittleEndian :: read_u64 ( & bytes [ 16 .. 24 ] ) , service_config_len : LittleEndian :: read_u64 ( & bytes [ 24 .. 32 ] ) , service_file_len : LittleEndian :: read_u64 ( & bytes [ 32 .. 40 ] ) , election_len : LittleEndian :: read_u64 ( & bytes [ 40 .. 48 ] ) , update_len : LittleEndian :: read_u64 ( & bytes [ 48 .. 56 ] ) , departure_len : LittleEndian :: read_u64 ( & bytes [ 56 .. 64 ] ) , } ) } } }
Returns the size of the struct in bytes *as written*,
along with the struct itself future-proofed to the latest version.
Returns the size of the struct in bytes * as written * along with the struct itself future - proofed to the latest version .
bytes
&[u8]
version
u8