options: convert SortOrder and SortTarget to RangeRequest.SortOrder and RangeRequest.SortTarget
package com.coreos.jetcd.options;
+import com.coreos.jetcd.api.RangeRequest;
import com.coreos.jetcd.data.ByteSequence;
+import com.coreos.jetcd.options.GetOption.SortOrder;
+import com.coreos.jetcd.options.GetOption.SortTarget;
import com.google.protobuf.ByteString;
import java.util.Arrays;
@@ -30,4 +33,40 @@ public class OptionsUtil {
return ByteSequence.fromBytes(NO_PREFIX_END);
}
+
+ /**
+ * convert client SortOrder to apu SortOrder.
+ */
+ public static RangeRequest.SortOrder toRangeRequestSortOrder(SortOrder order) {
+ switch (order) {
+ case NONE:
+ return RangeRequest.SortOrder.NONE;
+ case ASCEND:
+ return RangeRequest.SortOrder.ASCEND;
+ case DESCEND:
+ return RangeRequest.SortOrder.DESCEND;
+ default:
+ return RangeRequest.SortOrder.UNRECOGNIZED;
+ }
+ }
+
+ /**
+ * convert client SortTarget to apu SortTarget.
+ */
+ public static RangeRequest.SortTarget toRangeRequestSortTarget(SortTarget target) {
+ switch (target) {
+ case KEY:
+ return RangeRequest.SortTarget.KEY;
+ case CREATE:
+ return RangeRequest.SortTarget.CREATE;
+ case MOD:
+ return RangeRequest.SortTarget.MOD;
+ case VALUE:
+ return RangeRequest.SortTarget.VALUE;
+ case VERSION:
+ return RangeRequest.SortTarget.VERSION;
+ default:
+ return RangeRequest.SortTarget.UNRECOGNIZED;
+ }
+ }
}
