@@ -30,8 +30,7 @@ public class Subscribe implements IMessage {
3030
3131 private final long request ;
3232 private final String topic ;
33- private final String match ;
34- private final boolean getRetained ;
33+ private final SubscribeOptions options ;
3534
3635 private static final String MATCH_EXACT = "exact" ;
3736 private static final String MATCH_PREFIX = "prefix" ;
@@ -41,54 +40,48 @@ public Subscribe(long request, SubscribeOptions options, String topic) {
4140 this .request = request ;
4241 this .topic = topic ;
4342 if (options != null ) {
44- if (options .match != null ) {
45- if (!options .match .equals (MATCH_EXACT ) && !options .match .equals (MATCH_PREFIX ) &&
46- !options .match .equals (MATCH_WILDCARD )) {
43+ String match = options .getMatch ();
44+ if (match != null ) {
45+ if (!match .equals (MATCH_EXACT ) && !match .equals (MATCH_PREFIX ) &&
46+ !match .equals (MATCH_WILDCARD )) {
4747 throw new IllegalArgumentException ("match must be one of exact, prefix or wildcard." );
4848 }
4949 }
50- this .match = options .match ;
51- this .getRetained = options .getRetained ;
50+ this .options = options ;
5251 } else {
53- this .match = MATCH_EXACT ;
54- this .getRetained = false ;
52+ this .options = new SubscribeOptions (MATCH_EXACT , false );
5553 }
5654 }
5755
5856 public static Subscribe parse (List <Object > wmsg ) {
5957 MessageUtil .validateMessage (wmsg , MESSAGE_TYPE , "SUBSCRIBE" , 4 );
6058
6159 long request = MessageUtil .parseLong (wmsg .get (1 ));
62- Map < String , Object > options = ( Map <String , Object >) wmsg .get (2 );
60+ SubscribeOptions options = new SubscribeOptions (( Map <String , Object >) wmsg .get (2 ) );
6361
64- String match = null ;
65- if (options .containsKey ("match" )) {
66- match = (String ) options .get ("match" );
67- if (!match .equals (MATCH_EXACT ) && !match .equals (MATCH_PREFIX ) &&
68- !match .equals (MATCH_WILDCARD )) {
69- throw new ProtocolError ("match must be one of exact, prefix or wildcard." );
70- }
62+ String match = options .getMatch ();
63+ if (match != null && !match .equals (MATCH_EXACT ) && !match .equals (MATCH_PREFIX ) &&
64+ !match .equals (MATCH_WILDCARD )) {
65+ throw new ProtocolError ("match must be one of exact, prefix or wildcard." );
7166 }
72- boolean getRetained = getOrDefault (options , "get_retained" , false );
7367
7468 String topic = (String ) wmsg .get (3 );
75- SubscribeOptions opt = new SubscribeOptions (match , true , getRetained );
76- return new Subscribe (request , opt , topic );
69+ return new Subscribe (request , options , topic );
7770 }
7871
7972 @ Override
8073 public List <Object > marshal () {
8174 List <Object > marshaled = new ArrayList <>();
8275 marshaled .add (MESSAGE_TYPE );
8376 marshaled .add (request );
84- Map <String , Object > extra = new HashMap <>();
85- if (match != null && !match .equals (MATCH_EXACT )) {
86- extra .put ("match" , match );
87- }
88- if (getRetained ) {
89- extra .put ("get_retained" , getRetained );
77+
78+ SubscribeOptions options = new SubscribeOptions (this .options );
79+ String match = options .getMatch ();
80+ if (match != null && match .equals (MATCH_EXACT )) {
81+ options .removeMatch ();
9082 }
91- marshaled .add (extra );
83+
84+ marshaled .add (options );
9285 marshaled .add (topic );
9386 return marshaled ;
9487 }
0 commit comments