@@ -26,10 +26,10 @@ pub enum SimpleTupleValue {
26
26
27
27
impl SimpleTupleValue {
28
28
fn parse ( value : & str ) -> Self {
29
- if let Ok ( v) = value. parse :: < u64 > ( ) {
30
- SimpleTupleValue :: U64 ( v)
31
- } else if let Ok ( v) = value. parse :: < i64 > ( ) {
29
+ if let Ok ( v) = value. parse :: < i64 > ( ) {
32
30
SimpleTupleValue :: I64 ( v)
31
+ } else if let Ok ( v) = value. parse :: < u64 > ( ) {
32
+ SimpleTupleValue :: U64 ( v)
33
33
} else if let Ok ( v) = value. parse :: < f64 > ( ) {
34
34
SimpleTupleValue :: F64 ( v)
35
35
} else if let Ok ( v) = Uuid :: from_str ( value) {
@@ -54,7 +54,24 @@ impl fmt::Display for SimpleTupleValue {
54
54
write ! ( f, "{}" , style( v) . green( ) )
55
55
}
56
56
}
57
- SimpleTupleValue :: Bytes ( v) => write ! ( f, "{:?}" , style( v) . italic( ) ) ,
57
+ SimpleTupleValue :: Bytes ( v) => {
58
+ let hex_string = if v. len ( ) > 512 { & v[ ..512 ] } else { v }
59
+ . iter ( )
60
+ . map ( |byte| format ! ( "{:02x}" , byte) )
61
+ . collect :: < String > ( ) ;
62
+ write ! ( f, "{}" , style( hex_string) . italic( ) ) ?;
63
+
64
+ if v. len ( ) > 512 {
65
+ write ! (
66
+ f,
67
+ "{} {}" ,
68
+ style( "..." ) . italic( ) ,
69
+ style( format!( "({} bytes)" , v. len( ) ) ) . dim( )
70
+ ) ?;
71
+ }
72
+
73
+ Ok ( ( ) )
74
+ }
58
75
}
59
76
}
60
77
}
@@ -218,7 +235,7 @@ impl SimpleValue {
218
235
Some ( "str" ) => SimpleValue :: String ( value. to_string ( ) ) ,
219
236
Some ( "bytes" ) | Some ( "b" ) => {
220
237
let bytes = hex:: decode ( value. as_bytes ( ) )
221
- . with_context ( || format ! ( "Could not parse `{value:? }` as hex encoded bytes" ) ) ?;
238
+ . with_context ( || format ! ( "Could not parse `{value}` as hex encoded bytes" ) ) ?;
222
239
SimpleValue :: Bytes ( bytes)
223
240
}
224
241
Some ( type_hint) => bail ! ( "unknown type: `{type_hint}`" ) ,
@@ -258,7 +275,24 @@ impl fmt::Display for SimpleValue {
258
275
}
259
276
}
260
277
SimpleValue :: String ( v) => write ! ( f, "{}" , style( v) . green( ) ) ,
261
- SimpleValue :: Bytes ( v) => write ! ( f, "{:?}" , style( v) . italic( ) ) ,
278
+ SimpleValue :: Bytes ( v) => {
279
+ let hex_string = if v. len ( ) > 512 { & v[ ..512 ] } else { v }
280
+ . iter ( )
281
+ . map ( |byte| format ! ( "{:02x}" , byte) )
282
+ . collect :: < String > ( ) ;
283
+ write ! ( f, "{}" , style( hex_string) . italic( ) ) ?;
284
+
285
+ if v. len ( ) > 512 {
286
+ write ! (
287
+ f,
288
+ "{} {}" ,
289
+ style( "..." ) . italic( ) ,
290
+ style( format!( "({} bytes)" , v. len( ) ) ) . dim( )
291
+ ) ?;
292
+ }
293
+
294
+ Ok ( ( ) )
295
+ }
262
296
}
263
297
}
264
298
}
@@ -299,6 +333,11 @@ impl SimpleTupleSegment {
299
333
Some ( "uuid" ) => Uuid :: from_str ( value)
300
334
. map ( SimpleTupleValue :: Uuid )
301
335
. with_context ( || format ! ( "Could not parse `{value}` as UUID" ) ) ?,
336
+ Some ( "bytes" ) | Some ( "b" ) => {
337
+ let bytes = hex:: decode ( value. as_bytes ( ) )
338
+ . with_context ( || format ! ( "Could not parse `{value}` as hex encoded bytes" ) ) ?;
339
+ SimpleTupleValue :: Bytes ( bytes)
340
+ }
302
341
Some ( "str" ) => SimpleTupleValue :: String ( value. to_string ( ) ) ,
303
342
Some ( prefix) => bail ! ( "unknown type: `{prefix}`" ) ,
304
343
_ => SimpleTupleValue :: parse ( value) ,
0 commit comments