Deserialize from bytes.
(buf: &[u8])
| 200 | |
| 201 | /// Deserialize from bytes. |
| 202 | pub fn from_bytes(buf: &[u8]) -> Option<Self> { |
| 203 | if buf.len() < 28 { |
| 204 | return None; |
| 205 | } |
| 206 | let version = u16::from_le_bytes(buf[0..2].try_into().ok()?); |
| 207 | let msg_type_raw = u16::from_le_bytes(buf[2..4].try_into().ok()?); |
| 208 | let source_node = u64::from_le_bytes(buf[4..12].try_into().ok()?); |
| 209 | let target_node = u64::from_le_bytes(buf[12..20].try_into().ok()?); |
| 210 | let vshard_id = u32::from_le_bytes(buf[20..24].try_into().ok()?); |
| 211 | let payload_len = u32::from_le_bytes(buf[24..28].try_into().ok()?) as usize; |
| 212 | |
| 213 | if buf.len() < 28 + payload_len { |
| 214 | return None; |
| 215 | } |
| 216 | let payload = buf[28..28 + payload_len].to_vec(); |
| 217 | |
| 218 | let msg_type = match msg_type_raw { |
| 219 | 1 => VShardMessageType::SegmentChunk, |
| 220 | 2 => VShardMessageType::SegmentComplete, |
| 221 | 3 => VShardMessageType::WalTail, |
| 222 | 4 => VShardMessageType::RoutingUpdate, |
| 223 | 5 => VShardMessageType::RoutingAck, |
| 224 | 10 => VShardMessageType::GhostCreate, |
| 225 | 11 => VShardMessageType::GhostDelete, |
| 226 | 12 => VShardMessageType::GhostVerifyRequest, |
| 227 | 13 => VShardMessageType::GhostVerifyResponse, |
| 228 | 20 => VShardMessageType::MigrationBaseCopy, |
| 229 | 22 => VShardMessageType::GsiForward, |
| 230 | 23 => VShardMessageType::EdgeValidation, |
| 231 | 30 => VShardMessageType::GraphAlgoSuperstep, |
| 232 | 31 => VShardMessageType::GraphAlgoContributions, |
| 233 | 32 => VShardMessageType::GraphAlgoSuperstepAck, |
| 234 | 33 => VShardMessageType::GraphAlgoComplete, |
| 235 | 40 => VShardMessageType::TsScatterRequest, |
| 236 | 41 => VShardMessageType::TsScatterResponse, |
| 237 | 42 => VShardMessageType::TsRetentionCommand, |
| 238 | 43 => VShardMessageType::TsRetentionAck, |
| 239 | 44 => VShardMessageType::TsArchiveCommand, |
| 240 | 45 => VShardMessageType::TsArchiveAck, |
| 241 | 50 => VShardMessageType::VectorScatterRequest, |
| 242 | 51 => VShardMessageType::VectorScatterResponse, |
| 243 | 52 => VShardMessageType::VectorCoarseRouteRequest, |
| 244 | 53 => VShardMessageType::VectorCoarseRouteResponse, |
| 245 | 54 => VShardMessageType::VectorBuildExchangeRequest, |
| 246 | 55 => VShardMessageType::VectorBuildExchangeResponse, |
| 247 | 56 => VShardMessageType::VectorMemRegionRequest, |
| 248 | 57 => VShardMessageType::VectorMemRegionResponse, |
| 249 | 60 => VShardMessageType::SpatialScatterRequest, |
| 250 | 61 => VShardMessageType::SpatialScatterResponse, |
| 251 | 70 => VShardMessageType::CrossShardEvent, |
| 252 | 71 => VShardMessageType::CrossShardEventAck, |
| 253 | 72 => VShardMessageType::NotifyBroadcast, |
| 254 | 73 => VShardMessageType::NotifyBroadcastAck, |
| 255 | 80 => VShardMessageType::ArrayShardSliceReq, |
| 256 | 81 => VShardMessageType::ArrayShardSliceResp, |
| 257 | 82 => VShardMessageType::ArrayShardAggReq, |
| 258 | 83 => VShardMessageType::ArrayShardAggResp, |
| 259 | 84 => VShardMessageType::ArrayShardPutReq, |