@@ -30,24 +30,25 @@ enum NodeType {
3030 // N_BINARY = 0x200
3131}
3232
33- impl From < u64 > for NodeType {
34- fn from ( n : u64 ) -> Self {
33+ impl TryFrom < u64 > for NodeType {
34+ type Error = RedisError ;
35+ fn try_from ( n : u64 ) -> Result < Self , Self :: Error > {
3536 match n {
36- 0x1u64 => Self :: Null ,
37- 0x2u64 => Self :: String ,
38- 0x4u64 => Self :: Number ,
39- 0x8u64 => Self :: Integer ,
40- 0x10u64 => Self :: Boolean ,
41- 0x20u64 => Self :: Dict ,
42- 0x40u64 => Self :: Array ,
43- 0x80u64 => Self :: KeyVal ,
44- _ => panic ! ( "Can't load old RedisJSON RDB1" ) ,
37+ 0x1u64 => Ok ( Self :: Null ) ,
38+ 0x2u64 => Ok ( Self :: String ) ,
39+ 0x4u64 => Ok ( Self :: Number ) ,
40+ 0x8u64 => Ok ( Self :: Integer ) ,
41+ 0x10u64 => Ok ( Self :: Boolean ) ,
42+ 0x20u64 => Ok ( Self :: Dict ) ,
43+ 0x40u64 => Ok ( Self :: Array ) ,
44+ 0x80u64 => Ok ( Self :: KeyVal ) ,
45+ _ => Err ( RedisError :: Str ( "Can't load old RedisJSON RDB1" ) ) ,
4546 }
4647 }
4748}
4849
4950pub fn json_rdb_load ( rdb : * mut raw:: RedisModuleIO ) -> RedisResult < Value > {
50- let node_type = raw:: load_unsigned ( rdb) ?. into ( ) ;
51+ let node_type = raw:: load_unsigned ( rdb) ?. try_into ( ) ? ;
5152 match node_type {
5253 NodeType :: Null => Ok ( Value :: Null ) ,
5354 NodeType :: Boolean => {
@@ -72,7 +73,7 @@ pub fn json_rdb_load(rdb: *mut raw::RedisModuleIO) -> RedisResult<Value> {
7273 let len = raw:: load_unsigned ( rdb) ?;
7374 let mut m = Map :: with_capacity ( len as usize ) ;
7475 for _ in 0 ..len {
75- let t: NodeType = raw:: load_unsigned ( rdb) ?. into ( ) ;
76+ let t: NodeType = raw:: load_unsigned ( rdb) ?. try_into ( ) ? ;
7677 if t != NodeType :: KeyVal {
7778 return Err ( RedisError :: Str ( "Can't load old RedisJSON RDB" ) ) ;
7879 }
0 commit comments