Msgpack commands (#12664)

# Description

I thought about bringing `nu_plugin_msgpack` in, but that is MPL with a
clause that prevents other licenses, so rather than adapt that code I
decided to take a crack at just doing it straight from `rmp` to `Value`
without any `rmpv` in the middle. It seems like it's probably faster,
though I can't say for sure how much with the plugin overhead.

@IanManske I started on a `Read` implementation for `RawStream` but just
specialized to `from msgpack` here, but I'm thinking after release maybe
we can polish it up and make it a real one. It works!

# User-Facing Changes
New commands:

- `from msgpack`
- `from msgpackz`
- `to msgpack`
- `to msgpackz`

# Tests + Formatting
Pretty thorough tests added for the format deserialization, with a
roundtrip for serialization. Some example tests too for both `from
msgpack` and `to msgpack`.

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`


# After Submitting
- [ ] update release notes
This commit is contained in:
Devyn Cairns
2024-04-26 04:23:16 -07:00
committed by GitHub
parent 79ebf0c0a9
commit adf38c7c76
19 changed files with 1416 additions and 6 deletions

View File

@ -245,6 +245,7 @@ use tempfile::tempdir;
pub struct NuOpts {
pub cwd: Option<String>,
pub locale: Option<String>,
pub collapse_output: Option<bool>,
}
pub fn nu_run_test(opts: NuOpts, commands: impl AsRef<str>, with_std: bool) -> Outcome {
@ -299,9 +300,15 @@ pub fn nu_run_test(opts: NuOpts, commands: impl AsRef<str>, with_std: bool) -> O
.wait_with_output()
.expect("couldn't read from stdout/stderr");
let out = collapse_output(&output.stdout);
let out = String::from_utf8_lossy(&output.stdout);
let err = String::from_utf8_lossy(&output.stderr);
let out = if opts.collapse_output.unwrap_or(true) {
collapse_output(&out)
} else {
out.into_owned()
};
println!("=== stderr\n{}", err);
Outcome::new(out, err.into_owned(), output.status)
@ -382,7 +389,7 @@ where
.wait_with_output()
.expect("couldn't read from stdout/stderr");
let out = collapse_output(&output.stdout);
let out = collapse_output(&String::from_utf8_lossy(&output.stdout));
let err = String::from_utf8_lossy(&output.stderr);
println!("=== stderr\n{}", err);
@ -416,8 +423,7 @@ fn with_exe(name: &str) -> String {
}
}
fn collapse_output(std: &[u8]) -> String {
let out = String::from_utf8_lossy(std);
fn collapse_output(out: &str) -> String {
let out = out.lines().collect::<Vec<_>>().join("\n");
let out = out.replace("\r\n", "");
out.replace('\n', "")