PragmaTwice commented on code in PR #2323:
URL: https://github.com/apache/kvrocks/pull/2323#discussion_r1608066508


##########
src/types/json.h:
##########
@@ -217,6 +217,42 @@ struct JsonValue {
     return results;
   }
 
+  StatusOr<Optionals<uint64_t>> StrBytes(std::string_view path, 
JsonStorageFormat format,
+                                         int max_nesting_depth = 
std::numeric_limits<int>::max()) const {
+    Optionals<uint64_t> results;
+    try {
+      jsoncons::jsonpath::json_query(
+          value, path,
+          [&results, max_nesting_depth, format](const std::string & /*path*/, 
const jsoncons::json &origin) {
+            if (!origin.empty()) {
+              Status s;
+              std::string buffer;
+              std::error_code ec;
+              if (format == JsonStorageFormat::JSON) {
+                jsoncons::json_options options;
+                options.max_nesting_depth(max_nesting_depth);
+                jsoncons::compact_json_string_encoder encoder{buffer, options};
+                origin.dump(encoder, ec);
+              } else if (format == JsonStorageFormat::CBOR) {
+                jsoncons::cbor::cbor_options options;
+                options.max_nesting_depth(max_nesting_depth);
+                
jsoncons::cbor::basic_cbor_encoder<jsoncons::string_sink<std::string>> 
encoder{buffer, options};
+                origin.dump(encoder, ec);

Review Comment:
   Please use the exception version and catch it later.



##########
src/types/json.h:
##########
@@ -217,6 +217,42 @@ struct JsonValue {
     return results;
   }
 
+  StatusOr<Optionals<uint64_t>> StrBytes(std::string_view path, 
JsonStorageFormat format,
+                                         int max_nesting_depth = 
std::numeric_limits<int>::max()) const {
+    Optionals<uint64_t> results;
+    try {
+      jsoncons::jsonpath::json_query(
+          value, path,
+          [&results, max_nesting_depth, format](const std::string & /*path*/, 
const jsoncons::json &origin) {
+            if (!origin.empty()) {
+              Status s;
+              std::string buffer;
+              std::error_code ec;
+              if (format == JsonStorageFormat::JSON) {
+                jsoncons::json_options options;
+                options.max_nesting_depth(max_nesting_depth);
+                jsoncons::compact_json_string_encoder encoder{buffer, options};
+                origin.dump(encoder, ec);
+              } else if (format == JsonStorageFormat::CBOR) {
+                jsoncons::cbor::cbor_options options;
+                options.max_nesting_depth(max_nesting_depth);
+                
jsoncons::cbor::basic_cbor_encoder<jsoncons::string_sink<std::string>> 
encoder{buffer, options};
+                origin.dump(encoder, ec);

Review Comment:
   Please use the exception version of `dump` and catch it later.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to