From e5428acbd91ecd78bc522f13dd76c1fc61ab9583 Mon Sep 17 00:00:00 2001 From: Andrew Kozin Date: Sat, 16 Sep 2023 13:26:55 +0100 Subject: [PATCH] Replace `json` with `serde_json` dependency for nats_server --- nats-server/Cargo.toml | 2 +- nats-server/src/lib.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/nats-server/Cargo.toml b/nats-server/Cargo.toml index b665ff67c..36234f764 100644 --- a/nats-server/Cargo.toml +++ b/nats-server/Cargo.toml @@ -10,7 +10,7 @@ license = "Apache-2.0" lazy_static = "1.4.0" regex = { version = "1.7.1", default-features = false, features = ["std", "unicode-perl"] } url = "2" -json = "0.12" +serde_json = "1.0.104" nuid = "0.5" rand = "0.8" tokio-retry = "0.3.0" diff --git a/nats-server/src/lib.rs b/nats-server/src/lib.rs index 57ba39f2e..fd5ba7a11 100644 --- a/nats-server/src/lib.rs +++ b/nats-server/src/lib.rs @@ -22,6 +22,7 @@ use std::{thread, time::Duration}; use lazy_static::lazy_static; use rand::Rng; use regex::Regex; +use serde_json::{self, Value}; pub struct Server { inner: Inner, @@ -77,8 +78,8 @@ impl Server { let mut r = BufReader::with_capacity(1024, TcpStream::connect(addr).unwrap()); let mut line = String::new(); r.read_line(&mut line).expect("did not receive INFO"); - let si = json::parse(&line["INFO".len()..]).unwrap(); - let port = si["port"].as_u16().expect("could not parse port"); + let si: Value = serde_json::from_str(&line["INFO".len()..]).expect("could not parse INFO"); + let port = si["port"].as_u64().expect("could not parse port") as u16; let mut scheme = "nats://"; if si["tls_required"].as_bool().unwrap_or(false) { scheme = "tls://"; @@ -91,8 +92,8 @@ impl Server { let mut r = BufReader::with_capacity(1024, TcpStream::connect(addr).unwrap()); let mut line = String::new(); r.read_line(&mut line).expect("did not receive INFO"); - let si = json::parse(&line["INFO".len()..]).unwrap(); - si["port"].as_u16().expect("could not parse port") + let si: Value = serde_json::from_str(&line["INFO".len()..]).expect("could not parse INFO"); + si["port"].as_u64().expect("could not parse port") as u16 } // Allow user/pass override.