diff --git a/Cargo.lock b/Cargo.lock index 8f5f84fb03..501c3f79fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,6 +128,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" +[[package]] +name = "capnp" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae9b8a7119420b5279ddc2b4ee553ee15bcf4605df6135a26f03ffe153bee97c" + +[[package]] +name = "capnpc" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b47bce811162518b5c38f746ed584bd2922ae7bb560ef64f230d2e4ee0d111fe" +dependencies = [ + "capnp", +] + [[package]] name = "cc" version = "1.0.71" @@ -653,6 +668,7 @@ dependencies = [ "nu-json", "nu-parser", "nu-path", + "nu-plugin", "nu-protocol", "nu-table", "nu-term-grid", @@ -694,6 +710,7 @@ name = "nu-parser" version = "0.1.0" dependencies = [ "miette", + "nu-plugin", "nu-protocol", "thiserror", ] @@ -706,6 +723,15 @@ dependencies = [ "dunce", ] +[[package]] +name = "nu-plugin" +version = "0.1.0" +dependencies = [ + "capnp", + "capnpc", + "nu-protocol", +] + [[package]] name = "nu-protocol" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index d08ad421b5..973fae44cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,14 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace] -members = ["crates/nu-cli", "crates/nu-engine", "crates/nu-parser", "crates/nu-command", "crates/nu-protocol"] +members = [ + "crates/nu-cli", + "crates/nu-engine", + "crates/nu-parser", + "crates/nu-command", + "crates/nu-protocol", + "crates/nu-plugin", +] [dependencies] reedline = { git = "https://github.com/nushell/reedline", branch = "main" } diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index 233dc75e0e..99d13d33c3 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -13,6 +13,7 @@ nu-protocol = { path = "../nu-protocol" } nu-table = { path = "../nu-table" } nu-term-grid = { path = "../nu-term-grid" } nu-parser = { path = "../nu-parser" } +nu-plugin = { path = "../nu-plugin" } trash = { version = "1.3.0", optional = true } unicode-segmentation = "1.8.0" diff --git a/crates/nu-command/src/core_commands/mod.rs b/crates/nu-command/src/core_commands/mod.rs index 78e3604969..626ac16cda 100644 --- a/crates/nu-command/src/core_commands/mod.rs +++ b/crates/nu-command/src/core_commands/mod.rs @@ -9,6 +9,8 @@ mod hide; mod if_; mod let_; mod module; +mod register; +mod run_plugin; mod source; mod use_; @@ -23,5 +25,7 @@ pub use hide::Hide; pub use if_::If; pub use let_::Let; pub use module::Module; +pub use register::Register; +pub use run_plugin::RunPlugin; pub use source::Source; pub use use_::Use; diff --git a/crates/nu-command/src/core_commands/register.rs b/crates/nu-command/src/core_commands/register.rs new file mode 100644 index 0000000000..9578e717e0 --- /dev/null +++ b/crates/nu-command/src/core_commands/register.rs @@ -0,0 +1,34 @@ +use nu_protocol::ast::Call; +use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::{PipelineData, Signature, SyntaxShape}; + +#[derive(Clone)] +pub struct Register; + +impl Command for Register { + fn name(&self) -> &str { + "register" + } + + fn usage(&self) -> &str { + "Register a plugin" + } + + fn signature(&self) -> nu_protocol::Signature { + Signature::build("register").required( + "plugin", + SyntaxShape::Filepath, + "location of bin for plugin", + ) + } + + fn run( + &self, + _engine_state: &EngineState, + _stack: &mut Stack, + _call: &Call, + _input: PipelineData, + ) -> Result { + Ok(PipelineData::new()) + } +} diff --git a/crates/nu-command/src/core_commands/run_plugin.rs b/crates/nu-command/src/core_commands/run_plugin.rs new file mode 100644 index 0000000000..c8b448fb02 --- /dev/null +++ b/crates/nu-command/src/core_commands/run_plugin.rs @@ -0,0 +1,30 @@ +use nu_protocol::ast::Call; +use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::{PipelineData, Signature}; + +#[derive(Clone)] +pub struct RunPlugin; + +impl Command for RunPlugin { + fn name(&self) -> &str { + "run_plugin" + } + + fn usage(&self) -> &str { + "test for plugin encoding" + } + + fn signature(&self) -> nu_protocol::Signature { + Signature::build("run_plugin") + } + + fn run( + &self, + _context: &EngineState, + _stack: &mut Stack, + _call: &Call, + _input: PipelineData, + ) -> Result { + Ok(PipelineData::new()) + } +} diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 1ad9792457..f9e041e006 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -72,8 +72,10 @@ pub fn create_default_context() -> EngineState { Mv, ParEach, Ps, + Register, Range, Rm, + RunPlugin, Select, Size, Split, diff --git a/crates/nu-parser/Cargo.toml b/crates/nu-parser/Cargo.toml index 96dd9444a5..2dc4d6dc27 100644 --- a/crates/nu-parser/Cargo.toml +++ b/crates/nu-parser/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" miette = "3.0.0" thiserror = "1.0.29" nu-protocol = { path = "../nu-protocol"} +nu-plugin = { path = "../nu-plugin"} diff --git a/crates/nu-parser/src/errors.rs b/crates/nu-parser/src/errors.rs index 2f5f2145a6..e3e44b793f 100644 --- a/crates/nu-parser/src/errors.rs +++ b/crates/nu-parser/src/errors.rs @@ -178,4 +178,12 @@ pub enum ParseError { #[error("Module export not found.")] #[diagnostic(code(nu::parser::export_not_found), url(docsrs))] ExportNotFound(#[label = "could not find imports"] Span), + + #[error("File not found")] + #[diagnostic(code(nu::parser::export_not_found), url(docsrs))] + FileNotFound(String), + + #[error("Plugin error")] + #[diagnostic(code(nu::parser::export_not_found), url(docsrs))] + PluginError(String), } diff --git a/crates/nu-parser/src/lib.rs b/crates/nu-parser/src/lib.rs index 8fc5e559c8..dc5534c9e6 100644 --- a/crates/nu-parser/src/lib.rs +++ b/crates/nu-parser/src/lib.rs @@ -11,6 +11,6 @@ pub use flatten::{flatten_block, FlatShape}; pub use lex::{lex, Token, TokenContents}; pub use lite_parse::{lite_parse, LiteBlock}; pub use parse_keywords::{ - parse_alias, parse_def, parse_def_predecl, parse_let, parse_module, parse_use, + parse_alias, parse_def, parse_def_predecl, parse_let, parse_module, parse_plugin, parse_use, }; pub use parser::{find_captures_in_expr, parse, Import, VarDecl}; diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index ab2c14d7bc..200fb9d7c5 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -1,3 +1,4 @@ +use nu_plugin::plugin::{get_signature, PluginDeclaration}; use nu_protocol::{ ast::{Block, Call, Expr, Expression, ImportPattern, ImportPatternMember, Pipeline, Statement}, engine::StateWorkingSet, @@ -923,3 +924,87 @@ pub fn parse_source( )), ) } + +pub fn parse_plugin( + working_set: &mut StateWorkingSet, + spans: &[Span], +) -> (Statement, Option) { + let name = working_set.get_span_contents(spans[0]); + + if name != b"register" { + return ( + garbage_statement(spans), + Some(ParseError::UnknownState( + "internal error: Wrong call name for parse plugin function".into(), + span(spans), + )), + ); + } + + if let Some(decl_id) = working_set.find_decl(b"register") { + let (call, call_span, mut err) = + parse_internal_call(working_set, spans[0], &spans[1..], decl_id); + + let error = { + match spans.len() { + 1 => Some(ParseError::MissingPositional( + "plugin location".into(), + spans[0], + )), + 2 => { + let name_expr = working_set.get_span_contents(spans[1]); + if let Ok(filename) = String::from_utf8(name_expr.to_vec()) { + let source_file = Path::new(&filename); + + if source_file.exists() & source_file.is_file() { + // get signature from plugin + match get_signature(source_file) { + Err(err) => Some(ParseError::PluginError(format!("{}", err))), + Ok(signature) => { + // create plugin command declaration (need struct impl Command) + // store declaration in working set + let plugin_decl = PluginDeclaration::new(filename, signature); + working_set.add_decl(Box::new(plugin_decl)); + + None + } + } + } else { + Some(ParseError::FileNotFound(filename)) + } + } else { + Some(ParseError::NonUtf8(spans[1])) + } + } + _ => { + let span = spans[2..].iter().fold(spans[2], |acc, next| Span { + start: acc.start, + end: next.end, + }); + + Some(ParseError::ExtraPositional(span)) + } + } + }; + + err = error.or(err); + + ( + Statement::Pipeline(Pipeline::from_vec(vec![Expression { + expr: Expr::Call(call), + span: call_span, + ty: Type::Unknown, + custom_completion: None, + }])), + err, + ) + } else { + ( + garbage_statement(spans), + Some(ParseError::UnknownState( + "internal error: Register declaration not found".into(), + span(spans), + )), + ) + } +} diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index a49e324841..25be7f6d79 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -15,7 +15,8 @@ use nu_protocol::{ }; use crate::parse_keywords::{ - parse_alias, parse_def, parse_def_predecl, parse_hide, parse_let, parse_module, parse_use, + parse_alias, parse_def, parse_def_predecl, parse_hide, parse_let, parse_module, parse_plugin, + parse_use, }; #[derive(Debug, Clone)] @@ -3006,6 +3007,7 @@ pub fn parse_statement( Some(ParseError::UnexpectedKeyword("export".into(), spans[0])), ), b"hide" => parse_hide(working_set, spans), + b"register" => parse_plugin(working_set, spans), _ => { let (expr, err) = parse_expression(working_set, spans, true); (Statement::Pipeline(Pipeline::from_vec(vec![expr])), err) diff --git a/crates/nu-plugin/Cargo.toml b/crates/nu-plugin/Cargo.toml new file mode 100644 index 0000000000..cb5346eab7 --- /dev/null +++ b/crates/nu-plugin/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "nu-plugin" +version = "0.1.0" +edition = "2018" + +[dependencies] +capnp = "0.14.3" +nu-protocol = { path = "../nu-protocol" } + +[build-dependencies] +capnpc = "0.14.3" + + diff --git a/crates/nu-plugin/schema/plugin.capnp b/crates/nu-plugin/schema/plugin.capnp new file mode 100644 index 0000000000..8992bc0f99 --- /dev/null +++ b/crates/nu-plugin/schema/plugin.capnp @@ -0,0 +1,132 @@ +@0xb299d30dc02d72bc; +# Schema representing all the structs that are used to comunicate with +# the plugins. +# This schema, together with the command capnp proto is used to generate +# the rust file that defines the serialization/deserialization objects +# required to comunicate with the plugins created for nushell +# +# If you modify the schema remember to compile it to generate the corresponding +# rust file and place that file into the main nu-plugin folder. +# After compiling, you may need to run cargo fmt on the file so it passes the CI + +# Generic structs used as helpers for the encoding +struct Option(T) { + union { + none @0 :Void; + some @1 :T; + } +} + +struct Err(T) { + union { + err @0 :Text; + ok @1 :T; + } +} + +struct Map(Key, Value) { + struct Entry { + key @0 :Key; + value @1 :Value; + } + entries @0 :List(Entry); +} + +# Main plugin structures +struct Span { + start @0 :UInt64; + end @1 :UInt64; +} + +# Resulting value from plugin +struct Value { + span @0: Span; + + union { + void @1 :Void; + bool @2 :Bool; + int @3 :Int64; + float @4 :Float64; + string @5 :Text; + list @6 :List(Value); + } +} + +# Structs required to define the plugin signature +struct Signature { + name @0 :Text; + usage @1 :Text; + extraUsage @2 :Text; + requiredPositional @3 :List(Argument); + optionalPositional @4 :List(Argument); + rest @5 :Option(Argument); + named @6 :List(Flag); + isFilter @7 :Bool; +} + +struct Flag { + long @0 :Text; + short @1 :Option(Text); + arg @2 :Shape; + required @3 :Bool; + desc @4 :Text; +} + +struct Argument { + name @0 :Text; + desc @1 :Text; + shape @2 :Shape; +} + +# If we require more complex signatures for the plugins this could be +# changed to a union +enum Shape { + none @0; + any @1; + string @2; + number @3; + int @4; + boolean @5; +} + +# The next structs define the call information sent to th plugin +struct Expression { + union { + garbage @0 :Void; + bool @1 :Bool; + int @2 :Int64; + float @3 :Float64; + string @4 :Text; + list @5 :List(Expression); + # The expression list can be exteded based on the user need + # If a plugin requires something from the expression object, it + # will need to be added to this list + } +} + +struct Call { + head @0: Span; + positional @1 :List(Expression); + named @2 :Map(Text, Option(Expression)); +} + +struct CallInfo { + call @0: Call; + input @1: Value; +} + +# Main communication structs with the plugin +struct PluginCall { + union { + signature @0 :Void; + callInfo @1 :CallInfo; + } +} + +struct PluginResponse { + union { + error @0 :Text; + signature @1 :Signature; + value @2 :Value; + } +} diff --git a/crates/nu-plugin/src/lib.rs b/crates/nu-plugin/src/lib.rs new file mode 100644 index 0000000000..ff33a46384 --- /dev/null +++ b/crates/nu-plugin/src/lib.rs @@ -0,0 +1,6 @@ +pub mod plugin; +pub mod plugin_call; +pub mod plugin_capnp; +pub mod serializers; + +pub use plugin::{serve_plugin, Plugin}; diff --git a/crates/nu-plugin/src/plugin.rs b/crates/nu-plugin/src/plugin.rs new file mode 100644 index 0000000000..672c648463 --- /dev/null +++ b/crates/nu-plugin/src/plugin.rs @@ -0,0 +1,262 @@ +use crate::plugin_call::{self, decode_call, encode_response}; +use std::io::BufReader; +use std::process::{Command as CommandSys, Stdio}; +use std::{fmt::Display, path::Path}; + +use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::{ast::Call, Signature, Value}; +use nu_protocol::{PipelineData, ShellError}; + +const OUTPUT_BUFFER_SIZE: usize = 8192; + +#[derive(Debug)] +pub struct CallInfo { + pub call: Call, + pub input: Value, +} + +// Information sent to the plugin +#[derive(Debug)] +pub enum PluginCall { + Signature, + CallInfo(Box), +} + +// Information received from the plugin +#[derive(Debug)] +pub enum PluginResponse { + Error(String), + Signature(Box), + Value(Box), +} + +#[derive(Debug)] +pub enum PluginError { + MissingSignature, + UnableToGetStdout, + UnableToSpawn(String), + EncodingError(String), + DecodingError(String), +} + +impl Display for PluginError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + PluginError::MissingSignature => write!(f, "missing signature in plugin"), + PluginError::UnableToGetStdout => write!(f, "couldn't get stdout from child process"), + PluginError::UnableToSpawn(err) => { + write!(f, "error in spawned child process: {}", err) + } + PluginError::EncodingError(err) => { + write!(f, "error while encoding: {}", err) + } + PluginError::DecodingError(err) => { + write!(f, "error while decoding: {}", err) + } + } + } +} + +pub fn get_signature(path: &Path) -> Result, PluginError> { + let mut plugin_cmd = create_command(path); + + // Both stdout and stdin are piped so we can get the information from the plugin + plugin_cmd.stdout(Stdio::piped()); + plugin_cmd.stdin(Stdio::piped()); + + match plugin_cmd.spawn() { + Err(err) => Err(PluginError::UnableToSpawn(format!("{}", err))), + Ok(mut child) => { + // Create message to plugin to indicate that signature is required and + // send call to plugin asking for signature + if let Some(mut stdin_writer) = child.stdin.take() { + plugin_call::encode_call(&PluginCall::Signature, &mut stdin_writer)? + } + + // deserialize response from plugin to extract the signature + let signature = if let Some(stdout_reader) = child.stdout.take() { + let mut buf_read = BufReader::with_capacity(OUTPUT_BUFFER_SIZE, stdout_reader); + let response = plugin_call::decode_response(&mut buf_read)?; + + match response { + PluginResponse::Signature(sign) => Ok(sign), + PluginResponse::Error(msg) => Err(PluginError::DecodingError(msg)), + _ => Err(PluginError::DecodingError("signature not found".into())), + } + } else { + Err(PluginError::UnableToGetStdout) + }?; + + match child.wait() { + Err(err) => Err(PluginError::UnableToSpawn(format!("{}", err))), + Ok(_) => Ok(signature), + } + } + } +} + +fn create_command(path: &Path) -> CommandSys { + //TODO. The selection of shell could be modifiable from the config file. + if cfg!(windows) { + let mut process = CommandSys::new("cmd"); + process.arg("/c"); + process.arg(path); + + process + } else { + let mut process = CommandSys::new("sh"); + process.arg("-c").arg(path); + + process + } +} + +#[derive(Debug, Clone)] +pub struct PluginDeclaration { + name: String, + signature: Box, + filename: String, +} + +impl PluginDeclaration { + pub fn new(filename: String, signature: Box) -> Self { + Self { + name: signature.name.clone(), + signature, + filename, + } + } +} + +impl Command for PluginDeclaration { + fn name(&self) -> &str { + &self.name + } + + fn signature(&self) -> Signature { + self.signature.as_ref().clone() + } + + fn usage(&self) -> &str { + "plugin name plus arguments" + } + + fn run( + &self, + _engine_state: &EngineState, + _stack: &mut Stack, + call: &Call, + input: PipelineData, + ) -> Result { + // Call the command with self path + // Decode information from plugin + // Create PipelineData + let source_file = Path::new(&self.filename); + let mut plugin_cmd = create_command(source_file); + + // Both stdout and stdin are piped so we can get the information from the plugin + plugin_cmd.stdout(Stdio::piped()); + plugin_cmd.stdin(Stdio::piped()); + + match plugin_cmd.spawn() { + Err(err) => Err(ShellError::PluginError(format!("{}", err))), + Ok(mut child) => { + let input = match input { + PipelineData::Value(value) => value, + PipelineData::Stream(stream) => { + let values = stream.collect::>(); + + Value::List { + vals: values, + span: call.head, + } + } + }; + + // PluginCall information + let plugin_call = PluginCall::CallInfo(Box::new(CallInfo { + call: call.clone(), + input, + })); + + // Create message to plugin to indicate that signature is required and + // send call to plugin asking for signature + if let Some(mut stdin_writer) = child.stdin.take() { + plugin_call::encode_call(&plugin_call, &mut stdin_writer) + .map_err(|err| ShellError::PluginError(err.to_string()))? + } + + // Deserialize response from plugin to extract the resulting value + let pipeline_data = if let Some(stdout_reader) = child.stdout.take() { + let mut buf_read = BufReader::with_capacity(OUTPUT_BUFFER_SIZE, stdout_reader); + let response = plugin_call::decode_response(&mut buf_read) + .map_err(|err| ShellError::PluginError(err.to_string()))?; + + match response { + PluginResponse::Value(value) => { + Ok(PipelineData::Value(value.as_ref().clone())) + } + PluginResponse::Error(msg) => Err(PluginError::DecodingError(msg)), + _ => Err(PluginError::DecodingError( + "result value from plugin not found".into(), + )), + } + } else { + Err(PluginError::UnableToGetStdout) + } + .map_err(|err| ShellError::PluginError(err.to_string()))?; + + match child.wait() { + Err(err) => Err(ShellError::PluginError(format!("{}", err))), + Ok(_) => Ok(pipeline_data), + } + } + } + } + + fn is_plugin(&self) -> bool { + true + } +} + +/// The `Plugin` trait defines the API which plugins use to "hook" into nushell. +pub trait Plugin { + fn signature(&self) -> Signature; + fn run(&self, call: &Call, input: &Value) -> Result; +} + +// Function used in the plugin definition for the communication protocol between +// nushell and the external plugin. +// If you want to create a new plugin you have to use this function as the main +// entry point for the plugin +pub fn serve_plugin(plugin: &mut impl Plugin) { + let mut stdin_buf = BufReader::with_capacity(OUTPUT_BUFFER_SIZE, std::io::stdin()); + let plugin_call = decode_call(&mut stdin_buf); + + match plugin_call { + Err(err) => { + let response = PluginResponse::Error(err.to_string()); + encode_response(&response, &mut std::io::stdout()).expect("Error encoding response"); + } + Ok(plugin_call) => { + match plugin_call { + // Sending the signature back to nushell to create the declaration definition + PluginCall::Signature => { + let response = PluginResponse::Signature(Box::new(plugin.signature())); + encode_response(&response, &mut std::io::stdout()) + .expect("Error encoding response"); + } + PluginCall::CallInfo(call_info) => { + let value = plugin.run(&call_info.call, &call_info.input); + + let response = match value { + Ok(value) => PluginResponse::Value(Box::new(value)), + Err(err) => PluginResponse::Error(err.to_string()), + }; + encode_response(&response, &mut std::io::stdout()) + .expect("Error encoding response"); + } + } + } + } +} diff --git a/crates/nu-plugin/src/plugin_call.rs b/crates/nu-plugin/src/plugin_call.rs new file mode 100644 index 0000000000..7e359615fa --- /dev/null +++ b/crates/nu-plugin/src/plugin_call.rs @@ -0,0 +1,335 @@ +use crate::plugin::{CallInfo, PluginCall, PluginError, PluginResponse}; +use crate::plugin_capnp::{plugin_call, plugin_response}; +use crate::serializers::{call, signature, value}; +use capnp::serialize_packed; + +pub fn encode_call( + plugin_call: &PluginCall, + writer: &mut impl std::io::Write, +) -> Result<(), PluginError> { + let mut message = ::capnp::message::Builder::new_default(); + + let mut builder = message.init_root::(); + + match &plugin_call { + PluginCall::Signature => builder.set_signature(()), + PluginCall::CallInfo(call_info) => { + let mut call_info_builder = builder.reborrow().init_call_info(); + + // Serializing argument information from the call + let call_builder = call_info_builder + .reborrow() + .get_call() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + call::serialize_call(&call_info.call, call_builder) + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + // Serializing the input value from the call info + let value_builder = call_info_builder + .reborrow() + .get_input() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + value::serialize_value(&call_info.input, value_builder); + } + }; + + serialize_packed::write_message(writer, &message) + .map_err(|e| PluginError::EncodingError(e.to_string())) +} + +pub fn decode_call(reader: &mut impl std::io::BufRead) -> Result { + let message_reader = + serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap(); + + let reader = message_reader + .get_root::() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + match reader.which() { + Err(capnp::NotInSchema(_)) => Err(PluginError::DecodingError("value not in schema".into())), + Ok(plugin_call::Signature(())) => Ok(PluginCall::Signature), + Ok(plugin_call::CallInfo(reader)) => { + let reader = reader.map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let call_reader = reader + .get_call() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let call = call::deserialize_call(call_reader) + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let input_reader = reader + .get_input() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let input = value::deserialize_value(input_reader) + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + Ok(PluginCall::CallInfo(Box::new(CallInfo { call, input }))) + } + } +} + +pub fn encode_response( + plugin_response: &PluginResponse, + writer: &mut impl std::io::Write, +) -> Result<(), PluginError> { + let mut message = ::capnp::message::Builder::new_default(); + + let mut builder = message.init_root::(); + + match &plugin_response { + PluginResponse::Error(msg) => builder.reborrow().set_error(msg.as_str()), + PluginResponse::Signature(sign) => { + let signature_builder = builder.reborrow().init_signature(); + signature::serialize_signature(sign, signature_builder) + } + PluginResponse::Value(val) => { + let value_builder = builder.reborrow().init_value(); + value::serialize_value(val, value_builder); + } + }; + + serialize_packed::write_message(writer, &message) + .map_err(|e| PluginError::EncodingError(e.to_string())) +} + +pub fn decode_response(reader: &mut impl std::io::BufRead) -> Result { + let message_reader = + serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap(); + + let reader = message_reader + .get_root::() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + match reader.which() { + Err(capnp::NotInSchema(_)) => Err(PluginError::DecodingError("value not in schema".into())), + Ok(plugin_response::Error(reader)) => { + let msg = reader.map_err(|e| PluginError::DecodingError(e.to_string()))?; + + Ok(PluginResponse::Error(msg.to_string())) + } + Ok(plugin_response::Signature(reader)) => { + let reader = reader.map_err(|e| PluginError::DecodingError(e.to_string()))?; + let sign = signature::deserialize_signature(reader) + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + Ok(PluginResponse::Signature(Box::new(sign))) + } + Ok(plugin_response::Value(reader)) => { + let reader = reader.map_err(|e| PluginError::DecodingError(e.to_string()))?; + let val = value::deserialize_value(reader) + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + Ok(PluginResponse::Value(Box::new(val))) + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::plugin::{PluginCall, PluginResponse}; + use nu_protocol::{ + ast::{Call, Expr, Expression}, + Signature, Span, Spanned, SyntaxShape, Value, + }; + + fn compare_expressions(lhs: &Expression, rhs: &Expression) { + match (&lhs.expr, &rhs.expr) { + (Expr::Bool(a), Expr::Bool(b)) => assert_eq!(a, b), + (Expr::Int(a), Expr::Int(b)) => assert_eq!(a, b), + (Expr::Float(a), Expr::Float(b)) => assert_eq!(a, b), + (Expr::String(a), Expr::String(b)) => assert_eq!(a, b), + _ => panic!("not matching values"), + } + } + + #[test] + fn callinfo_round_trip_signature() { + let plugin_call = PluginCall::Signature; + + let mut buffer: Vec = Vec::new(); + encode_call(&plugin_call, &mut buffer).expect("unable to serialize message"); + let returned = decode_call(&mut buffer.as_slice()).expect("unable to deserialize message"); + + match returned { + PluginCall::Signature => {} + PluginCall::CallInfo(_) => panic!("decoded into wrong value"), + } + } + + #[test] + fn callinfo_round_trip_callinfo() { + let input = Value::Bool { + val: false, + span: Span { start: 1, end: 20 }, + }; + + let call = Call { + decl_id: 1, + head: Span { start: 0, end: 10 }, + positional: vec![ + Expression { + expr: Expr::Float(1.0), + span: Span { start: 0, end: 10 }, + ty: nu_protocol::Type::Float, + custom_completion: None, + }, + Expression { + expr: Expr::String("something".into()), + span: Span { start: 0, end: 10 }, + ty: nu_protocol::Type::Float, + custom_completion: None, + }, + ], + named: vec![( + Spanned { + item: "name".to_string(), + span: Span { start: 0, end: 10 }, + }, + Some(Expression { + expr: Expr::Float(1.0), + span: Span { start: 0, end: 10 }, + ty: nu_protocol::Type::Float, + custom_completion: None, + }), + )], + }; + + let plugin_call = PluginCall::CallInfo(Box::new(CallInfo { + call: call.clone(), + input: input.clone(), + })); + + let mut buffer: Vec = Vec::new(); + encode_call(&plugin_call, &mut buffer).expect("unable to serialize message"); + let returned = decode_call(&mut buffer.as_slice()).expect("unable to deserialize message"); + + match returned { + PluginCall::Signature => panic!("returned wrong call type"), + PluginCall::CallInfo(call_info) => { + assert_eq!(input, call_info.input); + assert_eq!(call.head, call_info.call.head); + assert_eq!(call.positional.len(), call_info.call.positional.len()); + + call.positional + .iter() + .zip(call_info.call.positional.iter()) + .for_each(|(lhs, rhs)| compare_expressions(lhs, rhs)); + + call.named + .iter() + .zip(call_info.call.named.iter()) + .for_each(|(lhs, rhs)| { + // Comparing the keys + assert_eq!(lhs.0.item, rhs.0.item); + + match (&lhs.1, &rhs.1) { + (None, None) => {} + (Some(a), Some(b)) => compare_expressions(a, b), + _ => panic!("not matching values"), + } + }); + } + } + } + + #[test] + fn response_round_trip_signature() { + let signature = Signature::build("nu-plugin") + .required("first", SyntaxShape::String, "first required") + .required("second", SyntaxShape::Int, "second required") + .required_named("first_named", SyntaxShape::String, "first named", Some('f')) + .required_named( + "second_named", + SyntaxShape::String, + "second named", + Some('s'), + ) + .rest("remaining", SyntaxShape::Int, "remaining"); + + let response = PluginResponse::Signature(Box::new(signature.clone())); + + let mut buffer: Vec = Vec::new(); + encode_response(&response, &mut buffer).expect("unable to serialize message"); + let returned = + decode_response(&mut buffer.as_slice()).expect("unable to deserialize message"); + + match returned { + PluginResponse::Error(_) => panic!("returned wrong call type"), + PluginResponse::Value(_) => panic!("returned wrong call type"), + PluginResponse::Signature(returned_signature) => { + assert_eq!(signature.name, returned_signature.name); + assert_eq!(signature.usage, returned_signature.usage); + assert_eq!(signature.extra_usage, returned_signature.extra_usage); + assert_eq!(signature.is_filter, returned_signature.is_filter); + + signature + .required_positional + .iter() + .zip(returned_signature.required_positional.iter()) + .for_each(|(lhs, rhs)| assert_eq!(lhs, rhs)); + + signature + .optional_positional + .iter() + .zip(returned_signature.optional_positional.iter()) + .for_each(|(lhs, rhs)| assert_eq!(lhs, rhs)); + + signature + .named + .iter() + .zip(returned_signature.named.iter()) + .for_each(|(lhs, rhs)| assert_eq!(lhs, rhs)); + + assert_eq!( + signature.rest_positional, + returned_signature.rest_positional, + ); + } + } + } + + #[test] + fn response_round_trip_value() { + let value = Value::Int { + val: 10, + span: Span { start: 2, end: 30 }, + }; + + let response = PluginResponse::Value(Box::new(value.clone())); + + let mut buffer: Vec = Vec::new(); + encode_response(&response, &mut buffer).expect("unable to serialize message"); + let returned = + decode_response(&mut buffer.as_slice()).expect("unable to deserialize message"); + + match returned { + PluginResponse::Error(_) => panic!("returned wrong call type"), + PluginResponse::Signature(_) => panic!("returned wrong call type"), + PluginResponse::Value(returned_value) => { + assert_eq!(&value, returned_value.as_ref()) + } + } + } + + #[test] + fn response_round_trip_error() { + let message = "some error".to_string(); + let response = PluginResponse::Error(message.clone()); + + let mut buffer: Vec = Vec::new(); + encode_response(&response, &mut buffer).expect("unable to serialize message"); + let returned = + decode_response(&mut buffer.as_slice()).expect("unable to deserialize message"); + + match returned { + PluginResponse::Error(msg) => assert_eq!(message, msg), + PluginResponse::Signature(_) => panic!("returned wrong call type"), + PluginResponse::Value(_) => panic!("returned wrong call type"), + } + } +} diff --git a/crates/nu-plugin/src/plugin_capnp.rs b/crates/nu-plugin/src/plugin_capnp.rs new file mode 100644 index 0000000000..cd49bad6e0 --- /dev/null +++ b/crates/nu-plugin/src/plugin_capnp.rs @@ -0,0 +1,4179 @@ +// @generated by the capnpc-rust plugin to the Cap'n Proto schema compiler. +// DO NOT EDIT. +// source: plugin.capnp + +pub mod option { + /* T */ + pub use self::Which::{None, Some}; + + #[derive(Copy, Clone)] + pub struct Owned { + _phantom: ::core::marker::PhantomData, + } + impl<'a, T> ::capnp::traits::Owned<'a> for Owned + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + type Reader = Reader<'a, T>; + type Builder = Builder<'a, T>; + } + impl<'a, T> ::capnp::traits::OwnedStruct<'a> for Owned + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + type Reader = Reader<'a, T>; + type Builder = Builder<'a, T>; + } + impl ::capnp::traits::Pipelined for Owned + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + reader: ::capnp::private::layout::StructReader<'a>, + _phantom: ::core::marker::PhantomData, + } + + impl<'a, T> ::capnp::traits::HasTypeId for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a, T> ::capnp::traits::FromStructReader<'a> for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a, T> { + Reader { + reader, + _phantom: ::core::marker::PhantomData, + } + } + } + + impl<'a, T> ::capnp::traits::FromPointerReader<'a> for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a, T> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a, T> ::capnp::traits::Imbue<'a> for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a, T> Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + pub fn reborrow(&self) -> Reader<'_, T> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + pub fn has_some(&self) -> bool { + if self.reader.get_data_field::(0) != 1 { + return false; + } + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.reader.get_data_field::(0) { + 0 => ::core::result::Result::Ok(None(())), + 1 => ::core::result::Result::Ok(Some( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + builder: ::capnp::private::layout::StructBuilder<'a>, + _phantom: ::core::marker::PhantomData, + } + impl<'a, T> ::capnp::traits::HasStructSize for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a, T> ::capnp::traits::HasTypeId for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a, T> ::capnp::traits::FromStructBuilder<'a> for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a, T> { + Builder { + builder, + _phantom: ::core::marker::PhantomData, + } + } + } + + impl<'a, T> ::capnp::traits::ImbueMut<'a> for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a, T> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a, T> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a, T> ::capnp::traits::SetPointerBuilder for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a, T>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a, T> Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + pub fn into_reader(self) -> Reader<'a, T> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_, T> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_, T> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn set_none(&mut self, _value: ()) { + self.builder.set_data_field::(0, 0); + } + #[inline] + pub fn initn_some(self, length: u32) -> >::Builder { + self.builder.set_data_field::(0, 1); + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).initn_as(length) + } + #[inline] + pub fn set_some( + &mut self, + value: >::Reader, + ) -> ::capnp::Result<()> { + self.builder.set_data_field::(0, 1); + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_some(self) -> >::Builder { + self.builder.set_data_field::(0, 1); + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).init_as() + } + pub fn has_some(&self) -> bool { + if self.builder.get_data_field::(0) != 1 { + return false; + } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.builder.get_data_field::(0) { + 0 => ::core::result::Result::Ok(None(())), + 1 => ::core::result::Result::Ok(Some( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + _phantom: ::core::marker::PhantomData, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + _phantom: ::core::marker::PhantomData, + } + } + } + impl Pipeline + where + T: ::capnp::traits::Pipelined, + ::Pipeline: ::capnp::capability::FromTypelessPipeline, + { + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 1, + pointers: 1, + }; + pub const TYPE_ID: u64 = 0xd0d8_5bbb_e991_4dd9; + } + pub enum Which { + None(()), + Some(A0), + } + pub type WhichReader<'a, T> = Which<::capnp::Result<>::Reader>>; + pub type WhichBuilder<'a, T> = + Which<::capnp::Result<>::Builder>>; +} + +pub mod err { + /* T */ + pub use self::Which::{Err, Ok}; + + #[derive(Copy, Clone)] + pub struct Owned { + _phantom: ::core::marker::PhantomData, + } + impl<'a, T> ::capnp::traits::Owned<'a> for Owned + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + type Reader = Reader<'a, T>; + type Builder = Builder<'a, T>; + } + impl<'a, T> ::capnp::traits::OwnedStruct<'a> for Owned + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + type Reader = Reader<'a, T>; + type Builder = Builder<'a, T>; + } + impl ::capnp::traits::Pipelined for Owned + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + reader: ::capnp::private::layout::StructReader<'a>, + _phantom: ::core::marker::PhantomData, + } + + impl<'a, T> ::capnp::traits::HasTypeId for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a, T> ::capnp::traits::FromStructReader<'a> for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a, T> { + Reader { + reader, + _phantom: ::core::marker::PhantomData, + } + } + } + + impl<'a, T> ::capnp::traits::FromPointerReader<'a> for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a, T> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a, T> ::capnp::traits::Imbue<'a> for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a, T> Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + pub fn reborrow(&self) -> Reader<'_, T> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + pub fn has_err(&self) -> bool { + if self.reader.get_data_field::(0) != 0 { + return false; + } + !self.reader.get_pointer_field(0).is_null() + } + pub fn has_ok(&self) -> bool { + if self.reader.get_data_field::(0) != 1 { + return false; + } + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.reader.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Err( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + 1 => ::core::result::Result::Ok(Ok( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + builder: ::capnp::private::layout::StructBuilder<'a>, + _phantom: ::core::marker::PhantomData, + } + impl<'a, T> ::capnp::traits::HasStructSize for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a, T> ::capnp::traits::HasTypeId for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a, T> ::capnp::traits::FromStructBuilder<'a> for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a, T> { + Builder { + builder, + _phantom: ::core::marker::PhantomData, + } + } + } + + impl<'a, T> ::capnp::traits::ImbueMut<'a> for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a, T> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a, T> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a, T> ::capnp::traits::SetPointerBuilder for Reader<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a, T>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a, T> Builder<'a, T> + where + T: for<'c> ::capnp::traits::Owned<'c>, + { + pub fn into_reader(self) -> Reader<'a, T> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_, T> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_, T> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn set_err(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.set_data_field::(0, 0); + self.builder.get_pointer_field(0).set_text(value); + } + #[inline] + pub fn init_err(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.set_data_field::(0, 0); + self.builder.get_pointer_field(0).init_text(size) + } + pub fn has_err(&self) -> bool { + if self.builder.get_data_field::(0) != 0 { + return false; + } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn initn_ok(self, length: u32) -> >::Builder { + self.builder.set_data_field::(0, 1); + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).initn_as(length) + } + #[inline] + pub fn set_ok( + &mut self, + value: >::Reader, + ) -> ::capnp::Result<()> { + self.builder.set_data_field::(0, 1); + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_ok(self) -> >::Builder { + self.builder.set_data_field::(0, 1); + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).init_as() + } + pub fn has_ok(&self) -> bool { + if self.builder.get_data_field::(0) != 1 { + return false; + } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.builder.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Err( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + 1 => ::core::result::Result::Ok(Ok( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + _phantom: ::core::marker::PhantomData, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + _phantom: ::core::marker::PhantomData, + } + } + } + impl Pipeline + where + T: ::capnp::traits::Pipelined, + ::Pipeline: ::capnp::capability::FromTypelessPipeline, + { + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 1, + pointers: 1, + }; + pub const TYPE_ID: u64 = 0xaed6_5bd3_8214_33f8; + } + pub enum Which { + Err(A0), + Ok(A1), + } + pub type WhichReader<'a, T> = Which< + ::capnp::Result<::capnp::text::Reader<'a>>, + ::capnp::Result<>::Reader>, + >; + pub type WhichBuilder<'a, T> = Which< + ::capnp::Result<::capnp::text::Builder<'a>>, + ::capnp::Result<>::Builder>, + >; +} + +pub mod map { + /* Key,Value */ + #[derive(Copy, Clone)] + pub struct Owned { + _phantom: ::core::marker::PhantomData<(Key, Value)>, + } + impl<'a, Key, Value> ::capnp::traits::Owned<'a> for Owned + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + type Reader = Reader<'a, Key, Value>; + type Builder = Builder<'a, Key, Value>; + } + impl<'a, Key, Value> ::capnp::traits::OwnedStruct<'a> for Owned + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + type Reader = Reader<'a, Key, Value>; + type Builder = Builder<'a, Key, Value>; + } + impl ::capnp::traits::Pipelined for Owned + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + reader: ::capnp::private::layout::StructReader<'a>, + _phantom: ::core::marker::PhantomData<(Key, Value)>, + } + + impl<'a, Key, Value> ::capnp::traits::HasTypeId for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a, Key, Value> ::capnp::traits::FromStructReader<'a> for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a, Key, Value> { + Reader { + reader, + _phantom: ::core::marker::PhantomData, + } + } + } + + impl<'a, Key, Value> ::capnp::traits::FromPointerReader<'a> for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a, Key, Value> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a, Key, Value> ::capnp::traits::Imbue<'a> for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a, Key, Value> Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + pub fn reborrow(&self) -> Reader<'_, Key, Value> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_entries( + self, + ) -> ::capnp::Result< + ::capnp::struct_list::Reader<'a, crate::plugin_capnp::map::entry::Owned>, + > { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ) + } + pub fn has_entries(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + } + + pub struct Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + builder: ::capnp::private::layout::StructBuilder<'a>, + _phantom: ::core::marker::PhantomData<(Key, Value)>, + } + impl<'a, Key, Value> ::capnp::traits::HasStructSize for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a, Key, Value> ::capnp::traits::HasTypeId for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a, Key, Value> ::capnp::traits::FromStructBuilder<'a> for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a, Key, Value> { + Builder { + builder, + _phantom: ::core::marker::PhantomData, + } + } + } + + impl<'a, Key, Value> ::capnp::traits::ImbueMut<'a> for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a, Key, Value> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a, Key, Value> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a, Key, Value> ::capnp::traits::SetPointerBuilder for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a, Key, Value>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a, Key, Value> Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + pub fn into_reader(self) -> Reader<'a, Key, Value> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_, Key, Value> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_, Key, Value> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_entries( + self, + ) -> ::capnp::Result< + ::capnp::struct_list::Builder<'a, crate::plugin_capnp::map::entry::Owned>, + > { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_entries( + &mut self, + value: ::capnp::struct_list::Reader< + 'a, + crate::plugin_capnp::map::entry::Owned, + >, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_entries( + self, + size: u32, + ) -> ::capnp::struct_list::Builder<'a, crate::plugin_capnp::map::entry::Owned> + { + ::capnp::traits::FromPointerBuilder::init_pointer( + self.builder.get_pointer_field(0), + size, + ) + } + pub fn has_entries(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + _phantom: ::core::marker::PhantomData<(Key, Value)>, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + _phantom: ::core::marker::PhantomData, + } + } + } + impl Pipeline + where + Key: ::capnp::traits::Pipelined, + ::Pipeline: ::capnp::capability::FromTypelessPipeline, + Value: ::capnp::traits::Pipelined, + ::Pipeline: ::capnp::capability::FromTypelessPipeline, + { + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 0, + pointers: 1, + }; + pub const TYPE_ID: u64 = 0x9783_acc1_0be0_6fce; + } + + pub mod entry { + /* Key,Value */ + #[derive(Copy, Clone)] + pub struct Owned { + _phantom: ::core::marker::PhantomData<(Key, Value)>, + } + impl<'a, Key, Value> ::capnp::traits::Owned<'a> for Owned + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + type Reader = Reader<'a, Key, Value>; + type Builder = Builder<'a, Key, Value>; + } + impl<'a, Key, Value> ::capnp::traits::OwnedStruct<'a> for Owned + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + type Reader = Reader<'a, Key, Value>; + type Builder = Builder<'a, Key, Value>; + } + impl ::capnp::traits::Pipelined for Owned + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + reader: ::capnp::private::layout::StructReader<'a>, + _phantom: ::core::marker::PhantomData<(Key, Value)>, + } + + impl<'a, Key, Value> ::capnp::traits::HasTypeId for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a, Key, Value> ::capnp::traits::FromStructReader<'a> for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a, Key, Value> { + Reader { + reader, + _phantom: ::core::marker::PhantomData, + } + } + } + + impl<'a, Key, Value> ::capnp::traits::FromPointerReader<'a> for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a, Key, Value> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a, Key, Value> ::capnp::traits::Imbue<'a> for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a, Key, Value> Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + pub fn reborrow(&self) -> Reader<'_, Key, Value> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_key(self) -> ::capnp::Result<>::Reader> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ) + } + pub fn has_key(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_value( + self, + ) -> ::capnp::Result<>::Reader> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(1), + ::core::option::Option::None, + ) + } + pub fn has_value(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } + } + + pub struct Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + builder: ::capnp::private::layout::StructBuilder<'a>, + _phantom: ::core::marker::PhantomData<(Key, Value)>, + } + impl<'a, Key, Value> ::capnp::traits::HasStructSize for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a, Key, Value> ::capnp::traits::HasTypeId for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a, Key, Value> ::capnp::traits::FromStructBuilder<'a> for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn new( + builder: ::capnp::private::layout::StructBuilder<'a>, + ) -> Builder<'a, Key, Value> { + Builder { + builder, + _phantom: ::core::marker::PhantomData, + } + } + } + + impl<'a, Key, Value> ::capnp::traits::ImbueMut<'a> for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a, Key, Value> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a, Key, Value> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a, Key, Value> ::capnp::traits::SetPointerBuilder for Reader<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a, Key, Value>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a, Key, Value> Builder<'a, Key, Value> + where + Key: for<'c> ::capnp::traits::Owned<'c>, + Value: for<'c> ::capnp::traits::Owned<'c>, + { + pub fn into_reader(self) -> Reader<'a, Key, Value> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_, Key, Value> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_, Key, Value> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_key(self) -> ::capnp::Result<>::Builder> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ) + } + #[inline] + pub fn initn_key(self, length: u32) -> >::Builder { + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)) + .initn_as(length) + } + #[inline] + pub fn set_key( + &mut self, + value: >::Reader, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_key(self) -> >::Builder { + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).init_as() + } + pub fn has_key(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_value( + self, + ) -> ::capnp::Result<>::Builder> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(1), + ::core::option::Option::None, + ) + } + #[inline] + pub fn initn_value( + self, + length: u32, + ) -> >::Builder { + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(1)) + .initn_as(length) + } + #[inline] + pub fn set_value( + &mut self, + value: >::Reader, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(1), + value, + false, + ) + } + #[inline] + pub fn init_value(self) -> >::Builder { + ::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(1)).init_as() + } + pub fn has_value(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + _phantom: ::core::marker::PhantomData<(Key, Value)>, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + _phantom: ::core::marker::PhantomData, + } + } + } + impl Pipeline + where + Key: ::capnp::traits::Pipelined, + ::Pipeline: + ::capnp::capability::FromTypelessPipeline, + Value: ::capnp::traits::Pipelined, + ::Pipeline: + ::capnp::capability::FromTypelessPipeline, + { + pub fn get_key(&self) -> ::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(0)) + } + pub fn get_value(&self) -> ::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(1)) + } + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 0, + pointers: 2, + }; + pub const TYPE_ID: u64 = 0xde4c_62ad_0c9f_67c3; + } + } +} + +pub mod span { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_start(self) -> u64 { + self.reader.get_data_field::(0) + } + #[inline] + pub fn get_end(self) -> u64 { + self.reader.get_data_field::(1) + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_start(self) -> u64 { + self.builder.get_data_field::(0) + } + #[inline] + pub fn set_start(&mut self, value: u64) { + self.builder.set_data_field::(0, value); + } + #[inline] + pub fn get_end(self) -> u64 { + self.builder.get_data_field::(1) + } + #[inline] + pub fn set_end(&mut self, value: u64) { + self.builder.set_data_field::(1, value); + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline {} + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 2, + pointers: 0, + }; + pub const TYPE_ID: u64 = 0xe8b6_78b5_d953_4593; + } +} + +pub mod value { + pub use self::Which::{Bool, Float, Int, List, String, Void}; + + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_span(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ) + } + pub fn has_span(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + pub fn has_string(&self) -> bool { + if self.reader.get_data_field::(0) != 4 { + return false; + } + !self.reader.get_pointer_field(1).is_null() + } + pub fn has_list(&self) -> bool { + if self.reader.get_data_field::(0) != 5 { + return false; + } + !self.reader.get_pointer_field(1).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.reader.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Void(())), + 1 => ::core::result::Result::Ok(Bool(self.reader.get_bool_field(16))), + 2 => ::core::result::Result::Ok(Int(self.reader.get_data_field::(1))), + 3 => ::core::result::Result::Ok(Float(self.reader.get_data_field::(1))), + 4 => ::core::result::Result::Ok(String( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(1), + ::core::option::Option::None, + ), + )), + 5 => ::core::result::Result::Ok(List( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(1), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_span(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_span( + &mut self, + value: crate::plugin_capnp::span::Reader<'_>, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_span(self) -> crate::plugin_capnp::span::Builder<'a> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(0), 0) + } + pub fn has_span(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn set_void(&mut self, _value: ()) { + self.builder.set_data_field::(0, 0); + } + #[inline] + pub fn set_bool(&mut self, value: bool) { + self.builder.set_data_field::(0, 1); + self.builder.set_bool_field(16, value); + } + #[inline] + pub fn set_int(&mut self, value: i64) { + self.builder.set_data_field::(0, 2); + self.builder.set_data_field::(1, value); + } + #[inline] + pub fn set_float(&mut self, value: f64) { + self.builder.set_data_field::(0, 3); + self.builder.set_data_field::(1, value); + } + #[inline] + pub fn set_string(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.set_data_field::(0, 4); + self.builder.get_pointer_field(1).set_text(value); + } + #[inline] + pub fn init_string(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.set_data_field::(0, 4); + self.builder.get_pointer_field(1).init_text(size) + } + pub fn has_string(&self) -> bool { + if self.builder.get_data_field::(0) != 4 { + return false; + } + !self.builder.get_pointer_field(1).is_null() + } + #[inline] + pub fn set_list( + &mut self, + value: ::capnp::struct_list::Reader<'a, crate::plugin_capnp::value::Owned>, + ) -> ::capnp::Result<()> { + self.builder.set_data_field::(0, 5); + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(1), + value, + false, + ) + } + #[inline] + pub fn init_list( + self, + size: u32, + ) -> ::capnp::struct_list::Builder<'a, crate::plugin_capnp::value::Owned> { + self.builder.set_data_field::(0, 5); + ::capnp::traits::FromPointerBuilder::init_pointer( + self.builder.get_pointer_field(1), + size, + ) + } + pub fn has_list(&self) -> bool { + if self.builder.get_data_field::(0) != 5 { + return false; + } + !self.builder.get_pointer_field(1).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.builder.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Void(())), + 1 => ::core::result::Result::Ok(Bool(self.builder.get_bool_field(16))), + 2 => ::core::result::Result::Ok(Int(self.builder.get_data_field::(1))), + 3 => ::core::result::Result::Ok(Float(self.builder.get_data_field::(1))), + 4 => ::core::result::Result::Ok(String( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(1), + ::core::option::Option::None, + ), + )), + 5 => ::core::result::Result::Ok(List( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(1), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline { + pub fn get_span(&self) -> crate::plugin_capnp::span::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(0)) + } + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 2, + pointers: 2, + }; + pub const TYPE_ID: u64 = 0x92a0_59fb_5627_86a8; + } + pub enum Which { + Void(()), + Bool(bool), + Int(i64), + Float(f64), + String(A0), + List(A1), + } + pub type WhichReader<'a> = Which< + ::capnp::Result<::capnp::text::Reader<'a>>, + ::capnp::Result<::capnp::struct_list::Reader<'a, crate::plugin_capnp::value::Owned>>, + >; + pub type WhichBuilder<'a> = Which< + ::capnp::Result<::capnp::text::Builder<'a>>, + ::capnp::Result<::capnp::struct_list::Builder<'a, crate::plugin_capnp::value::Owned>>, + >; +} + +pub mod signature { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_name(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ) + } + pub fn has_name(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_usage(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(1), + ::core::option::Option::None, + ) + } + pub fn has_usage(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_extra_usage(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(2), + ::core::option::Option::None, + ) + } + pub fn has_extra_usage(&self) -> bool { + !self.reader.get_pointer_field(2).is_null() + } + #[inline] + pub fn get_required_positional( + self, + ) -> ::capnp::Result<::capnp::struct_list::Reader<'a, crate::plugin_capnp::argument::Owned>> + { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(3), + ::core::option::Option::None, + ) + } + pub fn has_required_positional(&self) -> bool { + !self.reader.get_pointer_field(3).is_null() + } + #[inline] + pub fn get_optional_positional( + self, + ) -> ::capnp::Result<::capnp::struct_list::Reader<'a, crate::plugin_capnp::argument::Owned>> + { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(4), + ::core::option::Option::None, + ) + } + pub fn has_optional_positional(&self) -> bool { + !self.reader.get_pointer_field(4).is_null() + } + #[inline] + pub fn get_rest( + self, + ) -> ::capnp::Result< + crate::plugin_capnp::option::Reader<'a, crate::plugin_capnp::argument::Owned>, + > { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(5), + ::core::option::Option::None, + ) + } + pub fn has_rest(&self) -> bool { + !self.reader.get_pointer_field(5).is_null() + } + #[inline] + pub fn get_named( + self, + ) -> ::capnp::Result<::capnp::struct_list::Reader<'a, crate::plugin_capnp::flag::Owned>> + { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(6), + ::core::option::Option::None, + ) + } + pub fn has_named(&self) -> bool { + !self.reader.get_pointer_field(6).is_null() + } + #[inline] + pub fn get_is_filter(self) -> bool { + self.reader.get_bool_field(0) + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_name(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_name(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(0).set_text(value); + } + #[inline] + pub fn init_name(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(0).init_text(size) + } + pub fn has_name(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_usage(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(1), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_usage(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(1).set_text(value); + } + #[inline] + pub fn init_usage(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(1).init_text(size) + } + pub fn has_usage(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_extra_usage(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(2), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_extra_usage(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(2).set_text(value); + } + #[inline] + pub fn init_extra_usage(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(2).init_text(size) + } + pub fn has_extra_usage(&self) -> bool { + !self.builder.get_pointer_field(2).is_null() + } + #[inline] + pub fn get_required_positional( + self, + ) -> ::capnp::Result<::capnp::struct_list::Builder<'a, crate::plugin_capnp::argument::Owned>> + { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(3), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_required_positional( + &mut self, + value: ::capnp::struct_list::Reader<'a, crate::plugin_capnp::argument::Owned>, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(3), + value, + false, + ) + } + #[inline] + pub fn init_required_positional( + self, + size: u32, + ) -> ::capnp::struct_list::Builder<'a, crate::plugin_capnp::argument::Owned> { + ::capnp::traits::FromPointerBuilder::init_pointer( + self.builder.get_pointer_field(3), + size, + ) + } + pub fn has_required_positional(&self) -> bool { + !self.builder.get_pointer_field(3).is_null() + } + #[inline] + pub fn get_optional_positional( + self, + ) -> ::capnp::Result<::capnp::struct_list::Builder<'a, crate::plugin_capnp::argument::Owned>> + { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(4), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_optional_positional( + &mut self, + value: ::capnp::struct_list::Reader<'a, crate::plugin_capnp::argument::Owned>, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(4), + value, + false, + ) + } + #[inline] + pub fn init_optional_positional( + self, + size: u32, + ) -> ::capnp::struct_list::Builder<'a, crate::plugin_capnp::argument::Owned> { + ::capnp::traits::FromPointerBuilder::init_pointer( + self.builder.get_pointer_field(4), + size, + ) + } + pub fn has_optional_positional(&self) -> bool { + !self.builder.get_pointer_field(4).is_null() + } + #[inline] + pub fn get_rest( + self, + ) -> ::capnp::Result< + crate::plugin_capnp::option::Builder<'a, crate::plugin_capnp::argument::Owned>, + > { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(5), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_rest( + &mut self, + value: crate::plugin_capnp::option::Reader<'_, crate::plugin_capnp::argument::Owned>, + ) -> ::capnp::Result<()> { + as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(self.builder.get_pointer_field(5), value, false) + } + #[inline] + pub fn init_rest( + self, + ) -> crate::plugin_capnp::option::Builder<'a, crate::plugin_capnp::argument::Owned> + { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(5), 0) + } + pub fn has_rest(&self) -> bool { + !self.builder.get_pointer_field(5).is_null() + } + #[inline] + pub fn get_named( + self, + ) -> ::capnp::Result<::capnp::struct_list::Builder<'a, crate::plugin_capnp::flag::Owned>> + { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(6), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_named( + &mut self, + value: ::capnp::struct_list::Reader<'a, crate::plugin_capnp::flag::Owned>, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(6), + value, + false, + ) + } + #[inline] + pub fn init_named( + self, + size: u32, + ) -> ::capnp::struct_list::Builder<'a, crate::plugin_capnp::flag::Owned> { + ::capnp::traits::FromPointerBuilder::init_pointer( + self.builder.get_pointer_field(6), + size, + ) + } + pub fn has_named(&self) -> bool { + !self.builder.get_pointer_field(6).is_null() + } + #[inline] + pub fn get_is_filter(self) -> bool { + self.builder.get_bool_field(0) + } + #[inline] + pub fn set_is_filter(&mut self, value: bool) { + self.builder.set_bool_field(0, value); + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline { + pub fn get_rest( + &self, + ) -> crate::plugin_capnp::option::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(5)) + } + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 1, + pointers: 7, + }; + pub const TYPE_ID: u64 = 0xec96_eeb4_8cb7_90fa; + } +} + +pub mod flag { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_long(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ) + } + pub fn has_long(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_short( + self, + ) -> ::capnp::Result> + { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(1), + ::core::option::Option::None, + ) + } + pub fn has_short(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_arg( + self, + ) -> ::core::result::Result { + ::capnp::traits::FromU16::from_u16(self.reader.get_data_field::(0)) + } + #[inline] + pub fn get_required(self) -> bool { + self.reader.get_bool_field(16) + } + #[inline] + pub fn get_desc(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(2), + ::core::option::Option::None, + ) + } + pub fn has_desc(&self) -> bool { + !self.reader.get_pointer_field(2).is_null() + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_long(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_long(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(0).set_text(value); + } + #[inline] + pub fn init_long(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(0).init_text(size) + } + pub fn has_long(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_short( + self, + ) -> ::capnp::Result> + { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(1), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_short( + &mut self, + value: crate::plugin_capnp::option::Reader<'_, ::capnp::text::Owned>, + ) -> ::capnp::Result<()> { + as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(self.builder.get_pointer_field(1), value, false) + } + #[inline] + pub fn init_short(self) -> crate::plugin_capnp::option::Builder<'a, ::capnp::text::Owned> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(1), 0) + } + pub fn has_short(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_arg( + self, + ) -> ::core::result::Result { + ::capnp::traits::FromU16::from_u16(self.builder.get_data_field::(0)) + } + #[inline] + pub fn set_arg(&mut self, value: crate::plugin_capnp::Shape) { + self.builder.set_data_field::(0, value as u16) + } + #[inline] + pub fn get_required(self) -> bool { + self.builder.get_bool_field(16) + } + #[inline] + pub fn set_required(&mut self, value: bool) { + self.builder.set_bool_field(16, value); + } + #[inline] + pub fn get_desc(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(2), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_desc(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(2).set_text(value); + } + #[inline] + pub fn init_desc(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(2).init_text(size) + } + pub fn has_desc(&self) -> bool { + !self.builder.get_pointer_field(2).is_null() + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline { + pub fn get_short(&self) -> crate::plugin_capnp::option::Pipeline<::capnp::text::Owned> { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(1)) + } + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 1, + pointers: 3, + }; + pub const TYPE_ID: u64 = 0xc3e5_b612_6800_e050; + } +} + +pub mod argument { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_name(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ) + } + pub fn has_name(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_desc(self) -> ::capnp::Result<::capnp::text::Reader<'a>> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(1), + ::core::option::Option::None, + ) + } + pub fn has_desc(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_shape( + self, + ) -> ::core::result::Result { + ::capnp::traits::FromU16::from_u16(self.reader.get_data_field::(0)) + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_name(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_name(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(0).set_text(value); + } + #[inline] + pub fn init_name(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(0).init_text(size) + } + pub fn has_name(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_desc(self) -> ::capnp::Result<::capnp::text::Builder<'a>> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(1), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_desc(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.get_pointer_field(1).set_text(value); + } + #[inline] + pub fn init_desc(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.get_pointer_field(1).init_text(size) + } + pub fn has_desc(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_shape( + self, + ) -> ::core::result::Result { + ::capnp::traits::FromU16::from_u16(self.builder.get_data_field::(0)) + } + #[inline] + pub fn set_shape(&mut self, value: crate::plugin_capnp::Shape) { + self.builder.set_data_field::(0, value as u16) + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline {} + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 1, + pointers: 2, + }; + pub const TYPE_ID: u64 = 0xe49c_3d71_859d_47e9; + } +} + +#[repr(u16)] +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Shape { + None = 0, + Any = 1, + String = 2, + Number = 3, + Int = 4, + Boolean = 5, +} +impl ::capnp::traits::FromU16 for Shape { + #[inline] + fn from_u16(value: u16) -> ::core::result::Result { + match value { + 0 => ::core::result::Result::Ok(Shape::None), + 1 => ::core::result::Result::Ok(Shape::Any), + 2 => ::core::result::Result::Ok(Shape::String), + 3 => ::core::result::Result::Ok(Shape::Number), + 4 => ::core::result::Result::Ok(Shape::Int), + 5 => ::core::result::Result::Ok(Shape::Boolean), + n => ::core::result::Result::Err(::capnp::NotInSchema(n)), + } + } +} +impl ::capnp::traits::ToU16 for Shape { + #[inline] + fn to_u16(self) -> u16 { + self as u16 + } +} +impl ::capnp::traits::HasTypeId for Shape { + #[inline] + fn type_id() -> u64 { + 0xaa46_1154_9e24_a910u64 + } +} + +pub mod expression { + pub use self::Which::{Bool, Float, Garbage, Int, List, String}; + + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + pub fn has_string(&self) -> bool { + if self.reader.get_data_field::(0) != 4 { + return false; + } + !self.reader.get_pointer_field(0).is_null() + } + pub fn has_list(&self) -> bool { + if self.reader.get_data_field::(0) != 5 { + return false; + } + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.reader.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Garbage(())), + 1 => ::core::result::Result::Ok(Bool(self.reader.get_bool_field(16))), + 2 => ::core::result::Result::Ok(Int(self.reader.get_data_field::(1))), + 3 => ::core::result::Result::Ok(Float(self.reader.get_data_field::(1))), + 4 => ::core::result::Result::Ok(String( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + 5 => ::core::result::Result::Ok(List( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn set_garbage(&mut self, _value: ()) { + self.builder.set_data_field::(0, 0); + } + #[inline] + pub fn set_bool(&mut self, value: bool) { + self.builder.set_data_field::(0, 1); + self.builder.set_bool_field(16, value); + } + #[inline] + pub fn set_int(&mut self, value: i64) { + self.builder.set_data_field::(0, 2); + self.builder.set_data_field::(1, value); + } + #[inline] + pub fn set_float(&mut self, value: f64) { + self.builder.set_data_field::(0, 3); + self.builder.set_data_field::(1, value); + } + #[inline] + pub fn set_string(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.set_data_field::(0, 4); + self.builder.get_pointer_field(0).set_text(value); + } + #[inline] + pub fn init_string(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.set_data_field::(0, 4); + self.builder.get_pointer_field(0).init_text(size) + } + pub fn has_string(&self) -> bool { + if self.builder.get_data_field::(0) != 4 { + return false; + } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn set_list( + &mut self, + value: ::capnp::struct_list::Reader<'a, crate::plugin_capnp::expression::Owned>, + ) -> ::capnp::Result<()> { + self.builder.set_data_field::(0, 5); + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_list( + self, + size: u32, + ) -> ::capnp::struct_list::Builder<'a, crate::plugin_capnp::expression::Owned> { + self.builder.set_data_field::(0, 5); + ::capnp::traits::FromPointerBuilder::init_pointer( + self.builder.get_pointer_field(0), + size, + ) + } + pub fn has_list(&self) -> bool { + if self.builder.get_data_field::(0) != 5 { + return false; + } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.builder.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Garbage(())), + 1 => ::core::result::Result::Ok(Bool(self.builder.get_bool_field(16))), + 2 => ::core::result::Result::Ok(Int(self.builder.get_data_field::(1))), + 3 => ::core::result::Result::Ok(Float(self.builder.get_data_field::(1))), + 4 => ::core::result::Result::Ok(String( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + 5 => ::core::result::Result::Ok(List( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline {} + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 2, + pointers: 1, + }; + pub const TYPE_ID: u64 = 0xb831_c4c2_80ed_4dbb; + } + pub enum Which { + Garbage(()), + Bool(bool), + Int(i64), + Float(f64), + String(A0), + List(A1), + } + pub type WhichReader<'a> = Which< + ::capnp::Result<::capnp::text::Reader<'a>>, + ::capnp::Result<::capnp::struct_list::Reader<'a, crate::plugin_capnp::expression::Owned>>, + >; + pub type WhichBuilder<'a> = Which< + ::capnp::Result<::capnp::text::Builder<'a>>, + ::capnp::Result<::capnp::struct_list::Builder<'a, crate::plugin_capnp::expression::Owned>>, + >; +} + +pub mod call { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_head(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ) + } + pub fn has_head(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_positional( + self, + ) -> ::capnp::Result<::capnp::struct_list::Reader<'a, crate::plugin_capnp::expression::Owned>> + { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(1), + ::core::option::Option::None, + ) + } + pub fn has_positional(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_named( + self, + ) -> ::capnp::Result< + crate::plugin_capnp::map::Reader< + 'a, + ::capnp::text::Owned, + crate::plugin_capnp::option::Owned, + >, + > { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(2), + ::core::option::Option::None, + ) + } + pub fn has_named(&self) -> bool { + !self.reader.get_pointer_field(2).is_null() + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_head(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_head( + &mut self, + value: crate::plugin_capnp::span::Reader<'_>, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_head(self) -> crate::plugin_capnp::span::Builder<'a> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(0), 0) + } + pub fn has_head(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_positional( + self, + ) -> ::capnp::Result< + ::capnp::struct_list::Builder<'a, crate::plugin_capnp::expression::Owned>, + > { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(1), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_positional( + &mut self, + value: ::capnp::struct_list::Reader<'a, crate::plugin_capnp::expression::Owned>, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(1), + value, + false, + ) + } + #[inline] + pub fn init_positional( + self, + size: u32, + ) -> ::capnp::struct_list::Builder<'a, crate::plugin_capnp::expression::Owned> { + ::capnp::traits::FromPointerBuilder::init_pointer( + self.builder.get_pointer_field(1), + size, + ) + } + pub fn has_positional(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } + #[inline] + pub fn get_named( + self, + ) -> ::capnp::Result< + crate::plugin_capnp::map::Builder< + 'a, + ::capnp::text::Owned, + crate::plugin_capnp::option::Owned, + >, + > { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(2), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_named( + &mut self, + value: crate::plugin_capnp::map::Reader< + '_, + ::capnp::text::Owned, + crate::plugin_capnp::option::Owned, + >, + ) -> ::capnp::Result<()> { + , + > as ::capnp::traits::SetPointerBuilder>::set_pointer_builder( + self.builder.get_pointer_field(2), + value, + false, + ) + } + #[inline] + pub fn init_named( + self, + ) -> crate::plugin_capnp::map::Builder< + 'a, + ::capnp::text::Owned, + crate::plugin_capnp::option::Owned, + > { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(2), 0) + } + pub fn has_named(&self) -> bool { + !self.builder.get_pointer_field(2).is_null() + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline { + pub fn get_head(&self) -> crate::plugin_capnp::span::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(0)) + } + pub fn get_named( + &self, + ) -> crate::plugin_capnp::map::Pipeline< + ::capnp::text::Owned, + crate::plugin_capnp::option::Owned, + > { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(2)) + } + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 0, + pointers: 3, + }; + pub const TYPE_ID: u64 = 0xf5e6_e69c_460f_37d8; + } +} + +pub mod call_info { + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + #[inline] + pub fn get_call(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ) + } + pub fn has_call(&self) -> bool { + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_input(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(1), + ::core::option::Option::None, + ) + } + pub fn has_input(&self) -> bool { + !self.reader.get_pointer_field(1).is_null() + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn get_call(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_call( + &mut self, + value: crate::plugin_capnp::call::Reader<'_>, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_call(self) -> crate::plugin_capnp::call::Builder<'a> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(0), 0) + } + pub fn has_call(&self) -> bool { + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn get_input(self) -> ::capnp::Result> { + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(1), + ::core::option::Option::None, + ) + } + #[inline] + pub fn set_input( + &mut self, + value: crate::plugin_capnp::value::Reader<'_>, + ) -> ::capnp::Result<()> { + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(1), + value, + false, + ) + } + #[inline] + pub fn init_input(self) -> crate::plugin_capnp::value::Builder<'a> { + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(1), 0) + } + pub fn has_input(&self) -> bool { + !self.builder.get_pointer_field(1).is_null() + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline { + pub fn get_call(&self) -> crate::plugin_capnp::call::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(0)) + } + pub fn get_input(&self) -> crate::plugin_capnp::value::Pipeline { + ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(1)) + } + } + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 0, + pointers: 2, + }; + pub const TYPE_ID: u64 = 0x8e03_127e_9170_7d6a; + } +} + +pub mod plugin_call { + pub use self::Which::{CallInfo, Signature}; + + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + pub fn has_call_info(&self) -> bool { + if self.reader.get_data_field::(0) != 1 { + return false; + } + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.reader.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Signature(())), + 1 => ::core::result::Result::Ok(CallInfo( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn set_signature(&mut self, _value: ()) { + self.builder.set_data_field::(0, 0); + } + #[inline] + pub fn set_call_info( + &mut self, + value: crate::plugin_capnp::call_info::Reader<'_>, + ) -> ::capnp::Result<()> { + self.builder.set_data_field::(0, 1); + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_call_info(self) -> crate::plugin_capnp::call_info::Builder<'a> { + self.builder.set_data_field::(0, 1); + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(0), 0) + } + pub fn has_call_info(&self) -> bool { + if self.builder.get_data_field::(0) != 1 { + return false; + } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.builder.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Signature(())), + 1 => ::core::result::Result::Ok(CallInfo( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline {} + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 1, + pointers: 1, + }; + pub const TYPE_ID: u64 = 0xde86_64b2_7f80_4db1; + } + pub enum Which { + Signature(()), + CallInfo(A0), + } + pub type WhichReader<'a> = Which<::capnp::Result>>; + pub type WhichBuilder<'a> = Which<::capnp::Result>>; +} + +pub mod plugin_response { + pub use self::Which::{Error, Signature, Value}; + + #[derive(Copy, Clone)] + pub struct Owned(()); + impl<'a> ::capnp::traits::Owned<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl<'a> ::capnp::traits::OwnedStruct<'a> for Owned { + type Reader = Reader<'a>; + type Builder = Builder<'a>; + } + impl ::capnp::traits::Pipelined for Owned { + type Pipeline = Pipeline; + } + + #[derive(Clone, Copy)] + pub struct Reader<'a> { + reader: ::capnp::private::layout::StructReader<'a>, + } + + impl<'a> ::capnp::traits::HasTypeId for Reader<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructReader<'a> for Reader<'a> { + fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a> { + Reader { reader } + } + } + + impl<'a> ::capnp::traits::FromPointerReader<'a> for Reader<'a> { + fn get_from_pointer( + reader: &::capnp::private::layout::PointerReader<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructReader::new( + reader.get_struct(default)?, + )) + } + } + + impl<'a> ::capnp::traits::IntoInternalStructReader<'a> for Reader<'a> { + fn into_internal_struct_reader(self) -> ::capnp::private::layout::StructReader<'a> { + self.reader + } + } + + impl<'a> ::capnp::traits::Imbue<'a> for Reader<'a> { + fn imbue(&mut self, cap_table: &'a ::capnp::private::layout::CapTable) { + self.reader + .imbue(::capnp::private::layout::CapTableReader::Plain(cap_table)) + } + } + + impl<'a> Reader<'a> { + pub fn reborrow(&self) -> Reader<'_> { + Reader { ..*self } + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.reader.total_size() + } + pub fn has_error(&self) -> bool { + if self.reader.get_data_field::(0) != 0 { + return false; + } + !self.reader.get_pointer_field(0).is_null() + } + pub fn has_signature(&self) -> bool { + if self.reader.get_data_field::(0) != 1 { + return false; + } + !self.reader.get_pointer_field(0).is_null() + } + pub fn has_value(&self) -> bool { + if self.reader.get_data_field::(0) != 2 { + return false; + } + !self.reader.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.reader.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Error( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + 1 => ::core::result::Result::Ok(Signature( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + 2 => ::core::result::Result::Ok(Value( + ::capnp::traits::FromPointerReader::get_from_pointer( + &self.reader.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Builder<'a> { + builder: ::capnp::private::layout::StructBuilder<'a>, + } + impl<'a> ::capnp::traits::HasStructSize for Builder<'a> { + #[inline] + fn struct_size() -> ::capnp::private::layout::StructSize { + _private::STRUCT_SIZE + } + } + impl<'a> ::capnp::traits::HasTypeId for Builder<'a> { + #[inline] + fn type_id() -> u64 { + _private::TYPE_ID + } + } + impl<'a> ::capnp::traits::FromStructBuilder<'a> for Builder<'a> { + fn new(builder: ::capnp::private::layout::StructBuilder<'a>) -> Builder<'a> { + Builder { builder } + } + } + + impl<'a> ::capnp::traits::ImbueMut<'a> for Builder<'a> { + fn imbue_mut(&mut self, cap_table: &'a mut ::capnp::private::layout::CapTable) { + self.builder + .imbue(::capnp::private::layout::CapTableBuilder::Plain(cap_table)) + } + } + + impl<'a> ::capnp::traits::FromPointerBuilder<'a> for Builder<'a> { + fn init_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + _size: u32, + ) -> Builder<'a> { + ::capnp::traits::FromStructBuilder::new(builder.init_struct(_private::STRUCT_SIZE)) + } + fn get_from_pointer( + builder: ::capnp::private::layout::PointerBuilder<'a>, + default: ::core::option::Option<&'a [capnp::Word]>, + ) -> ::capnp::Result> { + ::core::result::Result::Ok(::capnp::traits::FromStructBuilder::new( + builder.get_struct(_private::STRUCT_SIZE, default)?, + )) + } + } + + impl<'a> ::capnp::traits::SetPointerBuilder for Reader<'a> { + fn set_pointer_builder<'b>( + pointer: ::capnp::private::layout::PointerBuilder<'b>, + value: Reader<'a>, + canonicalize: bool, + ) -> ::capnp::Result<()> { + pointer.set_struct(&value.reader, canonicalize) + } + } + + impl<'a> Builder<'a> { + pub fn into_reader(self) -> Reader<'a> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + pub fn reborrow(&mut self) -> Builder<'_> { + Builder { ..*self } + } + pub fn reborrow_as_reader(&self) -> Reader<'_> { + ::capnp::traits::FromStructReader::new(self.builder.into_reader()) + } + + pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> { + self.builder.into_reader().total_size() + } + #[inline] + pub fn set_error(&mut self, value: ::capnp::text::Reader<'_>) { + self.builder.set_data_field::(0, 0); + self.builder.get_pointer_field(0).set_text(value); + } + #[inline] + pub fn init_error(self, size: u32) -> ::capnp::text::Builder<'a> { + self.builder.set_data_field::(0, 0); + self.builder.get_pointer_field(0).init_text(size) + } + pub fn has_error(&self) -> bool { + if self.builder.get_data_field::(0) != 0 { + return false; + } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn set_signature( + &mut self, + value: crate::plugin_capnp::signature::Reader<'_>, + ) -> ::capnp::Result<()> { + self.builder.set_data_field::(0, 1); + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_signature(self) -> crate::plugin_capnp::signature::Builder<'a> { + self.builder.set_data_field::(0, 1); + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(0), 0) + } + pub fn has_signature(&self) -> bool { + if self.builder.get_data_field::(0) != 1 { + return false; + } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn set_value( + &mut self, + value: crate::plugin_capnp::value::Reader<'_>, + ) -> ::capnp::Result<()> { + self.builder.set_data_field::(0, 2); + ::capnp::traits::SetPointerBuilder::set_pointer_builder( + self.builder.get_pointer_field(0), + value, + false, + ) + } + #[inline] + pub fn init_value(self) -> crate::plugin_capnp::value::Builder<'a> { + self.builder.set_data_field::(0, 2); + ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(0), 0) + } + pub fn has_value(&self) -> bool { + if self.builder.get_data_field::(0) != 2 { + return false; + } + !self.builder.get_pointer_field(0).is_null() + } + #[inline] + pub fn which(self) -> ::core::result::Result, ::capnp::NotInSchema> { + match self.builder.get_data_field::(0) { + 0 => ::core::result::Result::Ok(Error( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + 1 => ::core::result::Result::Ok(Signature( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + 2 => ::core::result::Result::Ok(Value( + ::capnp::traits::FromPointerBuilder::get_from_pointer( + self.builder.get_pointer_field(0), + ::core::option::Option::None, + ), + )), + x => ::core::result::Result::Err(::capnp::NotInSchema(x)), + } + } + } + + pub struct Pipeline { + _typeless: ::capnp::any_pointer::Pipeline, + } + impl ::capnp::capability::FromTypelessPipeline for Pipeline { + fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline { + Pipeline { + _typeless: typeless, + } + } + } + impl Pipeline {} + mod _private { + use capnp::private::layout; + pub const STRUCT_SIZE: layout::StructSize = layout::StructSize { + data: 1, + pointers: 1, + }; + pub const TYPE_ID: u64 = 0xb9ba_b3c7_9388_b7db; + } + pub enum Which { + Error(A0), + Signature(A1), + Value(A2), + } + pub type WhichReader<'a> = Which< + ::capnp::Result<::capnp::text::Reader<'a>>, + ::capnp::Result>, + ::capnp::Result>, + >; + pub type WhichBuilder<'a> = Which< + ::capnp::Result<::capnp::text::Builder<'a>>, + ::capnp::Result>, + ::capnp::Result>, + >; +} diff --git a/crates/nu-plugin/src/serializers/call.rs b/crates/nu-plugin/src/serializers/call.rs new file mode 100644 index 0000000000..305b29e850 --- /dev/null +++ b/crates/nu-plugin/src/serializers/call.rs @@ -0,0 +1,296 @@ +use crate::plugin::PluginError; +use crate::plugin_capnp::{call, expression, option}; +use nu_protocol::{ + ast::{Call, Expr, Expression}, + Span, Spanned, Type, +}; + +pub(crate) fn serialize_call(call: &Call, mut builder: call::Builder) -> Result<(), PluginError> { + let mut head = builder.reborrow().init_head(); + head.set_start(call.head.start as u64); + head.set_end(call.head.end as u64); + + serialize_positional(&call.positional, builder.reborrow()); + serialize_named(&call.named, builder)?; + + Ok(()) +} + +fn serialize_positional(positional: &[Expression], mut builder: call::Builder) { + let mut positional_builder = builder.reborrow().init_positional(positional.len() as u32); + + for (index, expression) in positional.iter().enumerate() { + serialize_expression(expression, positional_builder.reborrow().get(index as u32)) + } +} + +fn serialize_named( + named: &[(Spanned, Option)], + mut builder: call::Builder, +) -> Result<(), PluginError> { + let mut named_builder = builder + .reborrow() + .init_named() + .init_entries(named.len() as u32); + + for (index, (key, expression)) in named.iter().enumerate() { + let mut entry_builder = named_builder.reborrow().get(index as u32); + entry_builder + .reborrow() + .set_key(key.item.as_str()) + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let mut value_builder = entry_builder.init_value(); + match expression { + None => value_builder.set_none(()), + Some(expr) => { + let expression_builder = value_builder.init_some(); + serialize_expression(expr, expression_builder); + } + } + } + + Ok(()) +} + +fn serialize_expression(expression: &Expression, mut builder: expression::Builder) { + match &expression.expr { + Expr::Garbage => builder.set_garbage(()), + Expr::Bool(val) => builder.set_bool(*val), + Expr::Int(val) => builder.set_int(*val), + Expr::Float(val) => builder.set_float(*val), + Expr::String(val) => builder.set_string(val), + Expr::List(values) => { + let mut list_builder = builder.reborrow().init_list(values.len() as u32); + for (index, expression) in values.iter().enumerate() { + let inner_builder = list_builder.reborrow().get(index as u32); + serialize_expression(expression, inner_builder) + } + } + _ => { + // If there is the need to pass other type of argument to the plugin + // we have to define the encoding for that parameter in this match + } + } +} + +pub(crate) fn deserialize_call(reader: call::Reader) -> Result { + let head_reader = reader + .get_head() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let head = Span { + start: head_reader.get_start() as usize, + end: head_reader.get_end() as usize, + }; + + let positional = deserialize_positionals(head, reader)?; + let named = deserialize_named(head, reader)?; + + Ok(Call { + decl_id: 0, + head, + positional, + named, + }) +} + +fn deserialize_positionals( + span: Span, + reader: call::Reader, +) -> Result, PluginError> { + let positional_reader = reader + .get_positional() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + positional_reader + .iter() + .map(|expression_reader| deserialize_expression(span, expression_reader)) + .collect() +} + +type NamedList = Vec<(Spanned, Option)>; + +fn deserialize_named(span: Span, reader: call::Reader) -> Result { + let named_reader = reader + .get_named() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let entries_list = named_reader + .get_entries() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let mut entries: Vec<(Spanned, Option)> = + Vec::with_capacity(entries_list.len() as usize); + + for entry_reader in entries_list { + let item = entry_reader + .get_key() + .map_err(|e| PluginError::DecodingError(e.to_string()))? + .to_string(); + + let value_reader = entry_reader + .get_value() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let value = match value_reader.which() { + Ok(option::None(())) => None, + Ok(option::Some(expression_reader)) => { + let expression_reader = + expression_reader.map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let expression = deserialize_expression(span, expression_reader) + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + Some(expression) + } + Err(capnp::NotInSchema(_)) => None, + }; + + let key = Spanned { item, span }; + + entries.push((key, value)) + } + + Ok(entries) +} + +fn deserialize_expression( + span: Span, + reader: expression::Reader, +) -> Result { + let expr = match reader.which() { + Ok(expression::Garbage(())) => Expr::Garbage, + Ok(expression::Bool(val)) => Expr::Bool(val), + Ok(expression::Int(val)) => Expr::Int(val), + Ok(expression::Float(val)) => Expr::Float(val), + Ok(expression::String(val)) => { + let string = val + .map_err(|e| PluginError::DecodingError(e.to_string()))? + .to_string(); + + Expr::String(string) + } + Ok(expression::List(values)) => { + let values = values.map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let values_list = values + .iter() + .map(|inner_reader| deserialize_expression(span, inner_reader)) + .collect::, PluginError>>()?; + + Expr::List(values_list) + } + Err(capnp::NotInSchema(_)) => Expr::Garbage, + }; + + Ok(Expression { + expr, + span, + ty: Type::Unknown, + custom_completion: None, + }) +} + +#[cfg(test)] +mod tests { + use capnp::serialize_packed; + use core::panic; + + use super::*; + use nu_protocol::{ + ast::{Call, Expr, Expression}, + Span, Spanned, + }; + + fn write_buffer(call: &Call, writer: &mut impl std::io::Write) -> Result<(), PluginError> { + let mut message = ::capnp::message::Builder::new_default(); + + let builder = message.init_root::(); + serialize_call(call, builder)?; + + serialize_packed::write_message(writer, &message) + .map_err(|e| PluginError::EncodingError(e.to_string())) + } + + fn read_buffer(reader: &mut impl std::io::BufRead) -> Result { + let message_reader = + serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap(); + + let reader = message_reader + .get_root::() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + deserialize_call(reader) + } + + fn compare_expressions(lhs: &Expression, rhs: &Expression) { + match (&lhs.expr, &rhs.expr) { + (Expr::Bool(a), Expr::Bool(b)) => assert_eq!(a, b), + (Expr::Int(a), Expr::Int(b)) => assert_eq!(a, b), + (Expr::Float(a), Expr::Float(b)) => assert_eq!(a, b), + (Expr::String(a), Expr::String(b)) => assert_eq!(a, b), + _ => panic!("not matching values"), + } + } + + #[test] + fn call_round_trip() { + let call = Call { + decl_id: 1, + head: Span { start: 0, end: 10 }, + positional: vec![ + Expression { + expr: Expr::Float(1.0), + span: Span { start: 0, end: 10 }, + ty: nu_protocol::Type::Float, + custom_completion: None, + }, + Expression { + expr: Expr::String("something".into()), + span: Span { start: 0, end: 10 }, + ty: nu_protocol::Type::Float, + custom_completion: None, + }, + ], + named: vec![( + Spanned { + item: "name".to_string(), + span: Span { start: 0, end: 10 }, + }, + Some(Expression { + expr: Expr::Float(1.0), + span: Span { start: 0, end: 10 }, + ty: nu_protocol::Type::Float, + custom_completion: None, + }), + )], + }; + + let mut buffer: Vec = Vec::new(); + write_buffer(&call, &mut buffer).expect("unable to serialize message"); + let returned_call = read_buffer(&mut buffer.as_slice()).expect("unable to read buffer"); + + assert_eq!(call.head, returned_call.head); + assert_eq!(call.positional.len(), returned_call.positional.len()); + + call.positional + .iter() + .zip(returned_call.positional.iter()) + .for_each(|(lhs, rhs)| compare_expressions(lhs, rhs)); + + call.named + .iter() + .zip(returned_call.named.iter()) + .for_each(|(lhs, rhs)| { + // Comparing the keys + assert_eq!(lhs.0.item, rhs.0.item); + + match (&lhs.1, &rhs.1) { + (None, None) => {} + (Some(a), Some(b)) => compare_expressions(a, b), + _ => panic!("not matching values"), + } + }); + } +} diff --git a/crates/nu-plugin/src/serializers/mod.rs b/crates/nu-plugin/src/serializers/mod.rs new file mode 100644 index 0000000000..9f96435fc9 --- /dev/null +++ b/crates/nu-plugin/src/serializers/mod.rs @@ -0,0 +1,3 @@ +pub mod call; +pub mod signature; +pub mod value; diff --git a/crates/nu-plugin/src/serializers/signature.rs b/crates/nu-plugin/src/serializers/signature.rs new file mode 100644 index 0000000000..7b98281a0d --- /dev/null +++ b/crates/nu-plugin/src/serializers/signature.rs @@ -0,0 +1,313 @@ +use crate::plugin::PluginError; +use crate::plugin_capnp::{argument, flag, option, signature, Shape}; +use nu_protocol::{Flag, PositionalArg, Signature, SyntaxShape}; + +pub(crate) fn serialize_signature(signature: &Signature, mut builder: signature::Builder) { + builder.set_name(signature.name.as_str()); + builder.set_usage(signature.usage.as_str()); + builder.set_extra_usage(signature.extra_usage.as_str()); + builder.set_is_filter(signature.is_filter); + + // Serializing list of required arguments + let mut required_list = builder + .reborrow() + .init_required_positional(signature.required_positional.len() as u32); + + for (index, arg) in signature.required_positional.iter().enumerate() { + let inner_builder = required_list.reborrow().get(index as u32); + serialize_argument(arg, inner_builder) + } + + // Serializing list of optional arguments + let mut optional_list = builder + .reborrow() + .init_optional_positional(signature.optional_positional.len() as u32); + + for (index, arg) in signature.optional_positional.iter().enumerate() { + let inner_builder = optional_list.reborrow().get(index as u32); + serialize_argument(arg, inner_builder) + } + + // Serializing rest argument + let mut rest_argument = builder.reborrow().init_rest(); + match &signature.rest_positional { + None => rest_argument.set_none(()), + Some(arg) => { + let inner_builder = rest_argument.init_some(); + serialize_argument(arg, inner_builder) + } + } + + // Serializing the named arguments + let mut named_list = builder.reborrow().init_named(signature.named.len() as u32); + + for (index, arg) in signature.named.iter().enumerate() { + let inner_builder = named_list.reborrow().get(index as u32); + serialize_flag(arg, inner_builder) + } +} + +fn serialize_argument(arg: &PositionalArg, mut builder: argument::Builder) { + builder.set_name(arg.name.as_str()); + builder.set_desc(arg.desc.as_str()); + + match arg.shape { + SyntaxShape::Boolean => builder.set_shape(Shape::Boolean), + SyntaxShape::String => builder.set_shape(Shape::String), + SyntaxShape::Int => builder.set_shape(Shape::Int), + SyntaxShape::Number => builder.set_shape(Shape::Number), + _ => builder.set_shape(Shape::Any), + } +} + +fn serialize_flag(arg: &Flag, mut builder: flag::Builder) { + builder.set_long(arg.long.as_str()); + builder.set_required(arg.required); + builder.set_desc(arg.desc.as_str()); + + let mut short_builder = builder.reborrow().init_short(); + match arg.short { + None => short_builder.set_none(()), + Some(val) => { + let mut inner_builder = short_builder.reborrow().initn_some(1); + inner_builder.push_str(format!("{}", val).as_str()); + } + } + + match &arg.arg { + None => builder.set_arg(Shape::None), + Some(shape) => match shape { + SyntaxShape::Boolean => builder.set_arg(Shape::Boolean), + SyntaxShape::String => builder.set_arg(Shape::String), + SyntaxShape::Int => builder.set_arg(Shape::Int), + SyntaxShape::Number => builder.set_arg(Shape::Number), + _ => builder.set_arg(Shape::Any), + }, + } +} + +pub(crate) fn deserialize_signature(reader: signature::Reader) -> Result { + let name = reader + .get_name() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + let usage = reader + .get_usage() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + let extra_usage = reader + .get_extra_usage() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + let is_filter = reader.get_is_filter(); + + // Deserializing required arguments + let required_list = reader + .get_required_positional() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let required_positional = required_list + .iter() + .map(deserialize_argument) + .collect::, PluginError>>()?; + + // Deserializing optional arguments + let optional_list = reader + .get_optional_positional() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let optional_positional = optional_list + .iter() + .map(deserialize_argument) + .collect::, PluginError>>()?; + + // Deserializing rest arguments + let rest_option = reader + .get_rest() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let rest_positional = match rest_option.which() { + Err(capnp::NotInSchema(_)) => None, + Ok(option::None(())) => None, + Ok(option::Some(rest_reader)) => { + let rest_reader = rest_reader.map_err(|e| PluginError::EncodingError(e.to_string()))?; + Some(deserialize_argument(rest_reader)?) + } + }; + + // Deserializing named arguments + let named_list = reader + .get_named() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let named = named_list + .iter() + .map(deserialize_flag) + .collect::, PluginError>>()?; + + Ok(Signature { + name: name.to_string(), + usage: usage.to_string(), + extra_usage: extra_usage.to_string(), + required_positional, + optional_positional, + rest_positional, + named, + is_filter, + creates_scope: false, + }) +} + +fn deserialize_argument(reader: argument::Reader) -> Result { + let name = reader + .get_name() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let desc = reader + .get_desc() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let shape = reader + .get_shape() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let shape = match shape { + Shape::String => SyntaxShape::String, + Shape::Int => SyntaxShape::Int, + Shape::Number => SyntaxShape::Number, + Shape::Boolean => SyntaxShape::Boolean, + Shape::Any => SyntaxShape::Any, + Shape::None => SyntaxShape::Any, + }; + + Ok(PositionalArg { + name: name.to_string(), + desc: desc.to_string(), + shape, + var_id: None, + }) +} + +fn deserialize_flag(reader: flag::Reader) -> Result { + let long = reader + .get_long() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let desc = reader + .get_desc() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let required = reader.get_required(); + + let short = reader + .get_short() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let short = match short.which() { + Err(capnp::NotInSchema(_)) => None, + Ok(option::None(())) => None, + Ok(option::Some(reader)) => { + let reader = reader.map_err(|e| PluginError::EncodingError(e.to_string()))?; + reader.chars().next() + } + }; + + let arg = reader + .get_arg() + .map_err(|e| PluginError::EncodingError(e.to_string()))?; + + let arg = match arg { + Shape::None => None, + Shape::Any => Some(SyntaxShape::Any), + Shape::String => Some(SyntaxShape::String), + Shape::Int => Some(SyntaxShape::Int), + Shape::Number => Some(SyntaxShape::Number), + Shape::Boolean => Some(SyntaxShape::Boolean), + }; + + Ok(Flag { + long: long.to_string(), + short, + arg, + required, + desc: desc.to_string(), + var_id: None, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + use capnp::serialize_packed; + use nu_protocol::{Signature, SyntaxShape}; + + pub fn write_buffer( + signature: &Signature, + writer: &mut impl std::io::Write, + ) -> Result<(), PluginError> { + let mut message = ::capnp::message::Builder::new_default(); + + let builder = message.init_root::(); + + serialize_signature(signature, builder); + + serialize_packed::write_message(writer, &message) + .map_err(|e| PluginError::EncodingError(e.to_string())) + } + + pub fn read_buffer(reader: &mut impl std::io::BufRead) -> Result { + let message_reader = + serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap(); + + let reader = message_reader + .get_root::() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + deserialize_signature(reader) + } + + #[test] + fn value_round_trip() { + let signature = Signature::build("nu-plugin") + .required("first", SyntaxShape::String, "first required") + .required("second", SyntaxShape::Int, "second required") + .required_named("first_named", SyntaxShape::String, "first named", Some('f')) + .required_named( + "second_named", + SyntaxShape::String, + "second named", + Some('s'), + ) + .rest("remaining", SyntaxShape::Int, "remaining"); + + let mut buffer: Vec = Vec::new(); + write_buffer(&signature, &mut buffer).expect("unable to serialize message"); + let returned_signature = + read_buffer(&mut buffer.as_slice()).expect("unable to deserialize message"); + + assert_eq!(signature.name, returned_signature.name); + assert_eq!(signature.usage, returned_signature.usage); + assert_eq!(signature.extra_usage, returned_signature.extra_usage); + assert_eq!(signature.is_filter, returned_signature.is_filter); + + signature + .required_positional + .iter() + .zip(returned_signature.required_positional.iter()) + .for_each(|(lhs, rhs)| assert_eq!(lhs, rhs)); + + signature + .optional_positional + .iter() + .zip(returned_signature.optional_positional.iter()) + .for_each(|(lhs, rhs)| assert_eq!(lhs, rhs)); + + signature + .named + .iter() + .zip(returned_signature.named.iter()) + .for_each(|(lhs, rhs)| assert_eq!(lhs, rhs)); + + assert_eq!( + signature.rest_positional, + returned_signature.rest_positional, + ); + } +} diff --git a/crates/nu-plugin/src/serializers/value.rs b/crates/nu-plugin/src/serializers/value.rs new file mode 100644 index 0000000000..d5e1bef7d9 --- /dev/null +++ b/crates/nu-plugin/src/serializers/value.rs @@ -0,0 +1,265 @@ +use crate::plugin::PluginError; +use crate::plugin_capnp::value; +use nu_protocol::{Span, Value}; + +pub(crate) fn serialize_value(value: &Value, mut builder: value::Builder) { + let value_span = match value { + Value::Nothing { span } => { + builder.set_void(()); + *span + } + Value::Bool { val, span } => { + builder.set_bool(*val); + *span + } + Value::Int { val, span } => { + builder.set_int(*val); + *span + } + Value::Float { val, span } => { + builder.set_float(*val); + *span + } + Value::String { val, span } => { + builder.set_string(val); + *span + } + Value::List { vals, span } => { + let mut list_builder = builder.reborrow().init_list(vals.len() as u32); + for (index, value) in vals.iter().enumerate() { + let inner_builder = list_builder.reborrow().get(index as u32); + serialize_value(value, inner_builder); + } + + *span + } + _ => { + // If there is the need to pass other type of value to the plugin + // we have to define the encoding for that object in this match + Span::unknown() + } + }; + + let mut span = builder.reborrow().init_span(); + span.set_start(value_span.start as u64); + span.set_end(value_span.end as u64); +} + +pub(crate) fn deserialize_value(reader: value::Reader) -> Result { + let span_reader = reader + .get_span() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let span = Span { + start: span_reader.get_start() as usize, + end: span_reader.get_end() as usize, + }; + + match reader.which() { + Ok(value::Void(())) => Ok(Value::Nothing { span }), + Ok(value::Bool(val)) => Ok(Value::Bool { val, span }), + Ok(value::Int(val)) => Ok(Value::Int { val, span }), + Ok(value::Float(val)) => Ok(Value::Float { val, span }), + Ok(value::String(val)) => { + let string = val + .map_err(|e| PluginError::DecodingError(e.to_string()))? + .to_string(); + Ok(Value::String { val: string, span }) + } + Ok(value::List(vals)) => { + let values = vals.map_err(|e| PluginError::DecodingError(e.to_string()))?; + + let values_list = values + .iter() + .map(deserialize_value) + .collect::, PluginError>>()?; + + Ok(Value::List { + vals: values_list, + span, + }) + } + Err(capnp::NotInSchema(_)) => Ok(Value::Nothing { + span: Span::unknown(), + }), + } +} + +#[cfg(test)] +mod tests { + use super::*; + use capnp::serialize_packed; + use nu_protocol::{Span, Value}; + + pub fn write_buffer( + value: &Value, + writer: &mut impl std::io::Write, + ) -> Result<(), PluginError> { + let mut message = ::capnp::message::Builder::new_default(); + + let mut builder = message.init_root::(); + + serialize_value(value, builder.reborrow()); + + serialize_packed::write_message(writer, &message) + .map_err(|e| PluginError::EncodingError(e.to_string())) + } + + pub fn read_buffer(reader: &mut impl std::io::BufRead) -> Result { + let message_reader = + serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap(); + + let reader = message_reader + .get_root::() + .map_err(|e| PluginError::DecodingError(e.to_string()))?; + + deserialize_value(reader.reborrow()) + } + + #[test] + fn value_round_trip() { + let values = [ + Value::Bool { + val: false, + span: Span { start: 1, end: 20 }, + }, + Value::Int { + val: 10, + span: Span { start: 2, end: 30 }, + }, + Value::Float { + val: 10.0, + span: Span { start: 3, end: 40 }, + }, + Value::String { + val: "a string".into(), + span: Span { start: 4, end: 50 }, + }, + ]; + + for value in values { + let mut buffer: Vec = Vec::new(); + write_buffer(&value, &mut buffer).expect("unable to serialize message"); + let returned_value = + read_buffer(&mut buffer.as_slice()).expect("unable to deserialize message"); + + assert_eq!(value, returned_value) + } + } + + #[test] + fn value_nothing_round_trip() { + // Since nothing doesn't implement PartialOrd, we only compare that the + // encoded and decoded spans are correct + let value = Value::Nothing { + span: Span { start: 0, end: 10 }, + }; + + let mut buffer: Vec = Vec::new(); + write_buffer(&value, &mut buffer).expect("unable to serialize message"); + let returned_value = + read_buffer(&mut buffer.as_slice()).expect("unable to deserialize message"); + + assert_eq!( + value.span().expect("span"), + returned_value.span().expect("span") + ) + } + + #[test] + fn list_round_trip() { + let values = vec![ + Value::Bool { + val: false, + span: Span { start: 1, end: 20 }, + }, + Value::Int { + val: 10, + span: Span { start: 2, end: 30 }, + }, + Value::Float { + val: 10.0, + span: Span { start: 3, end: 40 }, + }, + Value::String { + val: "a string".into(), + span: Span { start: 4, end: 50 }, + }, + ]; + + let value = Value::List { + vals: values, + span: Span { start: 1, end: 10 }, + }; + + let mut buffer: Vec = Vec::new(); + write_buffer(&value, &mut buffer).expect("unable to serialize message"); + let returned_value = + read_buffer(&mut buffer.as_slice()).expect("unable to deserialize message"); + + assert_eq!( + value.span().expect("span"), + returned_value.span().expect("span") + ) + } + + #[test] + fn nested_list_round_trip() { + let inner_values = vec![ + Value::Bool { + val: false, + span: Span { start: 1, end: 20 }, + }, + Value::Int { + val: 10, + span: Span { start: 2, end: 30 }, + }, + Value::Float { + val: 10.0, + span: Span { start: 3, end: 40 }, + }, + Value::String { + val: "inner string".into(), + span: Span { start: 4, end: 50 }, + }, + ]; + + let values = vec![ + Value::Bool { + val: true, + span: Span { start: 1, end: 20 }, + }, + Value::Int { + val: 66, + span: Span { start: 2, end: 30 }, + }, + Value::Float { + val: 66.6, + span: Span { start: 3, end: 40 }, + }, + Value::String { + val: "a string".into(), + span: Span { start: 4, end: 50 }, + }, + Value::List { + vals: inner_values, + span: Span { start: 5, end: 60 }, + }, + ]; + + let value = Value::List { + vals: values, + span: Span { start: 1, end: 10 }, + }; + + let mut buffer: Vec = Vec::new(); + write_buffer(&value, &mut buffer).expect("unable to serialize message"); + let returned_value = + read_buffer(&mut buffer.as_slice()).expect("unable to deserialize message"); + + assert_eq!( + value.span().expect("span"), + returned_value.span().expect("span") + ) + } +} diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index befcd029f3..425fec37b6 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -169,6 +169,9 @@ pub enum ShellError { NoFileToBeMoved(), #[error("No file to be copied")] NoFileToBeCopied(), + + #[error("Plugin error")] + PluginError(String), } impl From for ShellError {