Skip to content

Commit

Permalink
fix: replace json with serde_json
Browse files Browse the repository at this point in the history
  • Loading branch information
mati865 committed Oct 13, 2024
1 parent 860f7b8 commit 88b519c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 23 deletions.
10 changes: 2 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ libflate = "1.2.0"
libc = "^0.2.124"
prost = "0.11"
winapi = "0.3.9"
json = "0.12.4"
serde_json = "1"

[dev-dependencies]
tokio = { version = "1.18", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion pyroscope_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pyroscope = { path = "../", default-features = false }
pyroscope_pprofrs = { path = "../pyroscope_backends/pyroscope_pprofrs", default-features = false }
pyroscope_rbspy = { path = "../pyroscope_backends/pyroscope_rbspy", default-features = false }
pyroscope_pyspy = { path = "../pyroscope_backends/pyroscope_pyspy", default-features = false }
json = "0.12.4"
serde_json = "1.0.115"

[dependencies.clap]
version = "3.2"
Expand Down
6 changes: 3 additions & 3 deletions pyroscope_cli/src/utils/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl AppConfig {
.map(|s| s.to_string())
.collect::<Vec<String>>();

AppConfig::set("command_args", &json::stringify(command_args))?;
AppConfig::set("command_args", &serde_json::to_string(&command_args)?)?;
}
}
if sub_exec.is_present("log_level") {
Expand Down Expand Up @@ -314,9 +314,9 @@ fn set_http_headers(cmd: &clap::ArgMatches) -> Result<()> {
http_headers_map.insert(kv[0].to_string(), kv[1].to_string());
}
}
let http_header = json::stringify(http_headers_map);
let http_header = serde_json::to_string(&http_headers_map)?;
AppConfig::set("http_headers_json", &http_header)?;
};
}
return Ok(());
}
}
3 changes: 3 additions & 0 deletions pyroscope_cli/src/utils/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum Error {

#[error(transparent)]
PyroscopeError(#[from] pyroscope::PyroscopeError),

#[error(transparent)]
Json(#[from] serde_json::Error),
}

impl Error {
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum PyroscopeError {
Io(#[from] std::io::Error),

#[error(transparent)]
Json(#[from] json::JsonError),
Json(#[from] serde_json::Error),
}

impl PyroscopeError {
Expand Down
16 changes: 7 additions & 9 deletions src/pyroscope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use crate::{
PyroscopeError,
};

use json;

use crate::backend::BackendImpl;
use crate::pyroscope::Compression::GZIP;
use crate::pyroscope::ReportEncoding::PPROF;
Expand Down Expand Up @@ -841,16 +839,16 @@ impl PyroscopeAgent<PyroscopeAgentRunning> {

pub fn parse_http_headers_json(http_headers_json: String) -> Result<HashMap<String, String>> {
let mut http_headers = HashMap::new();
let parsed = json::parse(&http_headers_json)?;
let parsed: serde_json::Value = serde_json::from_str(&http_headers_json)?;
if !parsed.is_object() {
return Err(PyroscopeError::AdHoc(format!(
"expected object, got {}",
parsed
)));
}
for (k, v) in parsed.entries() {
for (k, v) in parsed.as_object().unwrap() {
if v.is_string() {
http_headers.insert(k.to_string(), v.to_string());
http_headers.insert(k.to_string(), v.as_str().unwrap().to_string());
} else {
return Err(PyroscopeError::AdHoc(format!(
"invalid http header value, not a string: {}",
Expand All @@ -862,17 +860,17 @@ pub fn parse_http_headers_json(http_headers_json: String) -> Result<HashMap<Stri
}

pub fn parse_vec_string_json(s: String) -> Result<Vec<String>> {
let parsed = json::parse(&s)?;
let parsed: serde_json::Value = serde_json::from_str(&s)?;
if !parsed.is_array() {
return Err(PyroscopeError::AdHoc(format!(
"expected array, got {}",
parsed
)));
}
let mut res = Vec::with_capacity(parsed.len());
for v in parsed.members() {
let mut res = Vec::with_capacity(parsed.as_array().unwrap().len());
for v in parsed.as_array().unwrap() {
if v.is_string() {
res.push(v.to_string());
res.push(v.as_str().unwrap().to_string());
} else {
return Err(PyroscopeError::AdHoc(format!(
"invalid element value, not a string: {}",
Expand Down

0 comments on commit 88b519c

Please sign in to comment.