Size: 872 bytes.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// cs/net/rpc/rpc.cc
#include "cs/net/rpc/rpc.hh"

#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <type_traits>

#include "cs/log.hh"
#include "cs/net/http/request.hh"
#include "cs/net/http/response.hh"
#include "cs/net/json/object.hh"
#include "cs/parsers/parsers.hh"
#include "cs/result.hh"

namespace cs::net::rpc {

std::string QueryParamsToJson(
    std::map<std::string, std::string> map) {
  cs::net::json::Object::KVMap kv;
  for (const auto& [key, value] : map) {
    cs::net::json::Object obj;
    if (auto result = cs::parsers::ParseInt(value);
        result.ok()) {
      obj = cs::net::json::Object::NewInt(result.value());
    } else {
      obj = cs::net::json::Object::NewString(value);
    }
    kv[key] = obj;
  }
  cs::net::json::Object json(kv);
  return json.str();
}

}  // namespace cs::net::rpc
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-3:8080 in 4ms.