5
5
6
6
package io .lettuce .core .protocol ;
7
7
8
+ import io .lettuce .core .codec .StringCodec ;
8
9
import io .lettuce .core .protocol .CommandArgs .KeyArgument ;
9
10
import io .lettuce .core .protocol .CommandArgs .SingularArgument ;
10
11
import io .lettuce .core .protocol .CommandArgs .ValueArgument ;
@@ -22,19 +23,27 @@ public final class OtelCommandArgsUtil {
22
23
*/
23
24
public static List <String > getCommandArgs (CommandArgs <?, ?> commandArgs ) {
24
25
List <String > result = new ArrayList <>();
26
+ StringCodec stringCodec = new StringCodec ();
27
+
25
28
for (SingularArgument argument : commandArgs .singularArguments ) {
26
- String value = argument .toString ();
27
- if (argument instanceof KeyArgument && value .startsWith ("key<" ) && value .endsWith (">" )) {
28
- value = value .substring ("key<" .length (), value .length () - 1 );
29
- } else if (argument instanceof ValueArgument
30
- && value .startsWith ("value<" )
31
- && value .endsWith (">" )) {
32
- value = value .substring ("value<" .length (), value .length () - 1 );
33
- }
29
+ String value = getArgValue (stringCodec , argument );
34
30
result .add (value );
35
31
}
36
32
return result ;
37
33
}
38
34
35
+ @ SuppressWarnings ({"rawtypes" , "unchecked" })
36
+ private static String getArgValue (StringCodec stringCodec , SingularArgument argument ) {
37
+ if (argument instanceof KeyArgument ) {
38
+ KeyArgument keyArg = (KeyArgument ) argument ;
39
+ return stringCodec .decodeValue (keyArg .codec .encodeValue (keyArg .key ));
40
+ }
41
+ if (argument instanceof ValueArgument ) {
42
+ ValueArgument valueArg = (ValueArgument ) argument ;
43
+ return stringCodec .decodeValue (valueArg .codec .encodeValue (valueArg .val ));
44
+ }
45
+ return argument .toString ();
46
+ }
47
+
39
48
private OtelCommandArgsUtil () {}
40
49
}
0 commit comments