mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
capnp proto change schema (#304)
* capnp proto change schema * format schema file
This commit is contained in:
parent
cfd40ffaf5
commit
dd6452dfaa
7 changed files with 184 additions and 533 deletions
|
@ -9,14 +9,6 @@
|
||||||
# rust file and place that file into the main nu-plugin folder.
|
# 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
|
# 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) {
|
struct Err(T) {
|
||||||
union {
|
union {
|
||||||
err @0 :Text;
|
err @0 :Text;
|
||||||
|
@ -59,14 +51,14 @@ struct Signature {
|
||||||
extraUsage @2 :Text;
|
extraUsage @2 :Text;
|
||||||
requiredPositional @3 :List(Argument);
|
requiredPositional @3 :List(Argument);
|
||||||
optionalPositional @4 :List(Argument);
|
optionalPositional @4 :List(Argument);
|
||||||
rest @5 :Option(Argument);
|
rest @5 :Argument; # Optional value. Check for existence when deserializing
|
||||||
named @6 :List(Flag);
|
named @6 :List(Flag);
|
||||||
isFilter @7 :Bool;
|
isFilter @7 :Bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Flag {
|
struct Flag {
|
||||||
long @0 :Text;
|
long @0 :Text;
|
||||||
short @1 :Option(Text);
|
short @1 :Text; # Optional value. Check for existence when deserializing
|
||||||
arg @2 :Shape;
|
arg @2 :Shape;
|
||||||
required @3 :Bool;
|
required @3 :Bool;
|
||||||
desc @4 :Text;
|
desc @4 :Text;
|
||||||
|
@ -107,7 +99,9 @@ struct Expression {
|
||||||
struct Call {
|
struct Call {
|
||||||
head @0: Span;
|
head @0: Span;
|
||||||
positional @1 :List(Expression);
|
positional @1 :List(Expression);
|
||||||
named @2 :Map(Text, Option(Expression));
|
# The expression in the map can be optional
|
||||||
|
# Check for existence when deserializing
|
||||||
|
named @2 :Map(Text, Expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CallInfo {
|
struct CallInfo {
|
||||||
|
|
|
@ -65,47 +65,42 @@ impl Display for PluginError {
|
||||||
pub fn get_signature(path: &Path) -> Result<Vec<Signature>, PluginError> {
|
pub fn get_signature(path: &Path) -> Result<Vec<Signature>, PluginError> {
|
||||||
let mut plugin_cmd = create_command(path);
|
let mut plugin_cmd = create_command(path);
|
||||||
|
|
||||||
// Both stdout and stdin are piped so we can get the information from the plugin
|
let mut child = plugin_cmd
|
||||||
plugin_cmd.stdout(Stdio::piped());
|
.spawn()
|
||||||
plugin_cmd.stdin(Stdio::piped());
|
.map_err(|err| PluginError::UnableToSpawn(format!("{}", err)))?;
|
||||||
|
|
||||||
match plugin_cmd.spawn() {
|
// Create message to plugin to indicate that signature is required and
|
||||||
Err(err) => Err(PluginError::UnableToSpawn(format!("{}", err))),
|
// send call to plugin asking for signature
|
||||||
Ok(mut child) => {
|
if let Some(stdin_writer) = &mut child.stdin {
|
||||||
// Create message to plugin to indicate that signature is required and
|
let mut writer = stdin_writer;
|
||||||
// send call to plugin asking for signature
|
plugin_call::encode_call(&PluginCall::Signature, &mut writer)?
|
||||||
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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deserialize response from plugin to extract the signature
|
||||||
|
let signature = if let Some(stdout_reader) = &mut child.stdout {
|
||||||
|
let reader = stdout_reader;
|
||||||
|
let mut buf_read = BufReader::with_capacity(OUTPUT_BUFFER_SIZE, 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)
|
||||||
|
}?;
|
||||||
|
|
||||||
|
// There is no need to wait for the child process to finish since the
|
||||||
|
// signature has being collected
|
||||||
|
Ok(signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_command(path: &Path) -> CommandSys {
|
fn create_command(path: &Path) -> CommandSys {
|
||||||
//TODO. The selection of shell could be modifiable from the config file.
|
//TODO. The selection of shell could be modifiable from the config file.
|
||||||
if cfg!(windows) {
|
let mut process = if cfg!(windows) {
|
||||||
let mut process = CommandSys::new("cmd");
|
let mut process = CommandSys::new("cmd");
|
||||||
process.arg("/c");
|
process.arg("/c").arg(path);
|
||||||
process.arg(path);
|
|
||||||
|
|
||||||
process
|
process
|
||||||
} else {
|
} else {
|
||||||
|
@ -113,7 +108,12 @@ fn create_command(path: &Path) -> CommandSys {
|
||||||
process.arg("-c").arg(path);
|
process.arg("-c").arg(path);
|
||||||
|
|
||||||
process
|
process
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// Both stdout and stdin are piped so we can receive information from the plugin
|
||||||
|
process.stdout(Stdio::piped()).stdin(Stdio::piped());
|
||||||
|
|
||||||
|
process
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -159,65 +159,60 @@ impl Command for PluginDeclaration {
|
||||||
let source_file = Path::new(&self.filename);
|
let source_file = Path::new(&self.filename);
|
||||||
let mut plugin_cmd = create_command(source_file);
|
let mut plugin_cmd = create_command(source_file);
|
||||||
|
|
||||||
// Both stdout and stdin are piped so we can get the information from the plugin
|
let mut child = plugin_cmd
|
||||||
plugin_cmd.stdout(Stdio::piped());
|
.spawn()
|
||||||
plugin_cmd.stdin(Stdio::piped());
|
.map_err(|err| ShellError::PluginError(format!("{}", err)))?;
|
||||||
|
|
||||||
match plugin_cmd.spawn() {
|
let input = match input {
|
||||||
Err(err) => Err(ShellError::PluginError(format!("{}", err))),
|
PipelineData::Value(value) => value,
|
||||||
Ok(mut child) => {
|
PipelineData::Stream(stream) => {
|
||||||
let input = match input {
|
let values = stream.collect::<Vec<Value>>();
|
||||||
PipelineData::Value(value) => value,
|
|
||||||
PipelineData::Stream(stream) => {
|
|
||||||
let values = stream.collect::<Vec<Value>>();
|
|
||||||
|
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: values,
|
vals: values,
|
||||||
span: call.head,
|
span: call.head,
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// PluginCall information
|
|
||||||
let plugin_call = PluginCall::CallInfo(Box::new(CallInfo {
|
|
||||||
name: self.name.clone(),
|
|
||||||
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),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create message to plugin to indicate that signature is required and
|
||||||
|
// send call to plugin asking for signature
|
||||||
|
if let Some(stdin_writer) = &mut child.stdin {
|
||||||
|
// PluginCall information
|
||||||
|
let plugin_call = PluginCall::CallInfo(Box::new(CallInfo {
|
||||||
|
name: self.name.clone(),
|
||||||
|
call: call.clone(),
|
||||||
|
input,
|
||||||
|
}));
|
||||||
|
|
||||||
|
let mut writer = stdin_writer;
|
||||||
|
|
||||||
|
plugin_call::encode_call(&plugin_call, &mut 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) = &mut child.stdout {
|
||||||
|
let reader = stdout_reader;
|
||||||
|
let mut buf_read = BufReader::with_capacity(OUTPUT_BUFFER_SIZE, 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()))?;
|
||||||
|
|
||||||
|
// There is no need to wait for the child process to finish
|
||||||
|
// The response has been collected from the plugin call
|
||||||
|
Ok(pipeline_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_plugin(&self) -> bool {
|
fn is_plugin(&self) -> bool {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::plugin::{CallInfo, PluginCall, PluginError, PluginResponse};
|
||||||
use crate::plugin_capnp::{plugin_call, plugin_response};
|
use crate::plugin_capnp::{plugin_call, plugin_response};
|
||||||
use crate::serializers::signature::deserialize_signature;
|
use crate::serializers::signature::deserialize_signature;
|
||||||
use crate::serializers::{call, signature, value};
|
use crate::serializers::{call, signature, value};
|
||||||
use capnp::serialize_packed;
|
use capnp::serialize;
|
||||||
use nu_protocol::Signature;
|
use nu_protocol::Signature;
|
||||||
|
|
||||||
pub fn encode_call(
|
pub fn encode_call(
|
||||||
|
@ -40,13 +40,13 @@ pub fn encode_call(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
serialize_packed::write_message(writer, &message)
|
serialize::write_message(writer, &message)
|
||||||
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode_call(reader: &mut impl std::io::BufRead) -> Result<PluginCall, PluginError> {
|
pub fn decode_call(reader: &mut impl std::io::BufRead) -> Result<PluginCall, PluginError> {
|
||||||
let message_reader =
|
let message_reader = serialize::read_message(reader, ::capnp::message::ReaderOptions::new())
|
||||||
serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap();
|
.map_err(|e| PluginError::DecodingError(e.to_string()))?;
|
||||||
|
|
||||||
let reader = message_reader
|
let reader = message_reader
|
||||||
.get_root::<plugin_call::Reader>()
|
.get_root::<plugin_call::Reader>()
|
||||||
|
@ -110,13 +110,13 @@ pub fn encode_response(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
serialize_packed::write_message(writer, &message)
|
serialize::write_message(writer, &message)
|
||||||
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode_response(reader: &mut impl std::io::BufRead) -> Result<PluginResponse, PluginError> {
|
pub fn decode_response(reader: &mut impl std::io::BufRead) -> Result<PluginResponse, PluginError> {
|
||||||
let message_reader =
|
let message_reader = serialize::read_message(reader, ::capnp::message::ReaderOptions::new())
|
||||||
serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap();
|
.map_err(|e| PluginError::DecodingError(e.to_string()))?;
|
||||||
|
|
||||||
let reader = message_reader
|
let reader = message_reader
|
||||||
.get_root::<plugin_response::Reader>()
|
.get_root::<plugin_response::Reader>()
|
||||||
|
|
|
@ -2,309 +2,6 @@
|
||||||
// DO NOT EDIT.
|
// DO NOT EDIT.
|
||||||
// source: plugin.capnp
|
// source: plugin.capnp
|
||||||
|
|
||||||
pub mod option {
|
|
||||||
/* T */
|
|
||||||
pub use self::Which::{None, Some};
|
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub struct Owned<T> {
|
|
||||||
_phantom: ::core::marker::PhantomData<T>,
|
|
||||||
}
|
|
||||||
impl<'a, T> ::capnp::traits::Owned<'a> for Owned<T>
|
|
||||||
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<T>
|
|
||||||
where
|
|
||||||
T: for<'c> ::capnp::traits::Owned<'c>,
|
|
||||||
{
|
|
||||||
type Reader = Reader<'a, T>;
|
|
||||||
type Builder = Builder<'a, T>;
|
|
||||||
}
|
|
||||||
impl<T> ::capnp::traits::Pipelined for Owned<T>
|
|
||||||
where
|
|
||||||
T: for<'c> ::capnp::traits::Owned<'c>,
|
|
||||||
{
|
|
||||||
type Pipeline = Pipeline<T>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
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<Reader<'a, T>> {
|
|
||||||
::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::<u16>(0) != 1 {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
!self.reader.get_pointer_field(0).is_null()
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
pub fn which(self) -> ::core::result::Result<WhichReader<'a, T>, ::capnp::NotInSchema> {
|
|
||||||
match self.reader.get_data_field::<u16>(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<T>,
|
|
||||||
}
|
|
||||||
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<Builder<'a, T>> {
|
|
||||||
::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::<u16>(0, 0);
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
pub fn initn_some(self, length: u32) -> <T as ::capnp::traits::Owned<'a>>::Builder {
|
|
||||||
self.builder.set_data_field::<u16>(0, 1);
|
|
||||||
::capnp::any_pointer::Builder::new(self.builder.get_pointer_field(0)).initn_as(length)
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
pub fn set_some(
|
|
||||||
&mut self,
|
|
||||||
value: <T as ::capnp::traits::Owned<'_>>::Reader,
|
|
||||||
) -> ::capnp::Result<()> {
|
|
||||||
self.builder.set_data_field::<u16>(0, 1);
|
|
||||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(
|
|
||||||
self.builder.get_pointer_field(0),
|
|
||||||
value,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
pub fn init_some(self) -> <T as ::capnp::traits::Owned<'a>>::Builder {
|
|
||||||
self.builder.set_data_field::<u16>(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::<u16>(0) != 1 {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
!self.builder.get_pointer_field(0).is_null()
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
pub fn which(self) -> ::core::result::Result<WhichBuilder<'a, T>, ::capnp::NotInSchema> {
|
|
||||||
match self.builder.get_data_field::<u16>(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<T> {
|
|
||||||
_typeless: ::capnp::any_pointer::Pipeline,
|
|
||||||
_phantom: ::core::marker::PhantomData<T>,
|
|
||||||
}
|
|
||||||
impl<T> ::capnp::capability::FromTypelessPipeline for Pipeline<T> {
|
|
||||||
fn new(typeless: ::capnp::any_pointer::Pipeline) -> Pipeline<T> {
|
|
||||||
Pipeline {
|
|
||||||
_typeless: typeless,
|
|
||||||
_phantom: ::core::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<T> Pipeline<T>
|
|
||||||
where
|
|
||||||
T: ::capnp::traits::Pipelined,
|
|
||||||
<T as ::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<A0> {
|
|
||||||
None(()),
|
|
||||||
Some(A0),
|
|
||||||
}
|
|
||||||
pub type WhichReader<'a, T> = Which<::capnp::Result<<T as ::capnp::traits::Owned<'a>>::Reader>>;
|
|
||||||
pub type WhichBuilder<'a, T> =
|
|
||||||
Which<::capnp::Result<<T as ::capnp::traits::Owned<'a>>::Builder>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod err {
|
pub mod err {
|
||||||
/* T */
|
/* T */
|
||||||
pub use self::Which::{Err, Ok};
|
pub use self::Which::{Err, Ok};
|
||||||
|
@ -1929,11 +1626,7 @@ pub mod signature {
|
||||||
!self.reader.get_pointer_field(4).is_null()
|
!self.reader.get_pointer_field(4).is_null()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_rest(
|
pub fn get_rest(self) -> ::capnp::Result<crate::plugin_capnp::argument::Reader<'a>> {
|
||||||
self,
|
|
||||||
) -> ::capnp::Result<
|
|
||||||
crate::plugin_capnp::option::Reader<'a, crate::plugin_capnp::argument::Owned>,
|
|
||||||
> {
|
|
||||||
::capnp::traits::FromPointerReader::get_from_pointer(
|
::capnp::traits::FromPointerReader::get_from_pointer(
|
||||||
&self.reader.get_pointer_field(5),
|
&self.reader.get_pointer_field(5),
|
||||||
::core::option::Option::None,
|
::core::option::Option::None,
|
||||||
|
@ -2153,11 +1846,7 @@ pub mod signature {
|
||||||
!self.builder.get_pointer_field(4).is_null()
|
!self.builder.get_pointer_field(4).is_null()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_rest(
|
pub fn get_rest(self) -> ::capnp::Result<crate::plugin_capnp::argument::Builder<'a>> {
|
||||||
self,
|
|
||||||
) -> ::capnp::Result<
|
|
||||||
crate::plugin_capnp::option::Builder<'a, crate::plugin_capnp::argument::Owned>,
|
|
||||||
> {
|
|
||||||
::capnp::traits::FromPointerBuilder::get_from_pointer(
|
::capnp::traits::FromPointerBuilder::get_from_pointer(
|
||||||
self.builder.get_pointer_field(5),
|
self.builder.get_pointer_field(5),
|
||||||
::core::option::Option::None,
|
::core::option::Option::None,
|
||||||
|
@ -2166,15 +1855,16 @@ pub mod signature {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_rest(
|
pub fn set_rest(
|
||||||
&mut self,
|
&mut self,
|
||||||
value: crate::plugin_capnp::option::Reader<'_, crate::plugin_capnp::argument::Owned>,
|
value: crate::plugin_capnp::argument::Reader<'_>,
|
||||||
) -> ::capnp::Result<()> {
|
) -> ::capnp::Result<()> {
|
||||||
<crate::plugin_capnp::option::Reader<'_,crate::plugin_capnp::argument::Owned> as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(self.builder.get_pointer_field(5), value, false)
|
::capnp::traits::SetPointerBuilder::set_pointer_builder(
|
||||||
|
self.builder.get_pointer_field(5),
|
||||||
|
value,
|
||||||
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn init_rest(
|
pub fn init_rest(self) -> crate::plugin_capnp::argument::Builder<'a> {
|
||||||
self,
|
|
||||||
) -> crate::plugin_capnp::option::Builder<'a, crate::plugin_capnp::argument::Owned>
|
|
||||||
{
|
|
||||||
::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(5), 0)
|
::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(5), 0)
|
||||||
}
|
}
|
||||||
pub fn has_rest(&self) -> bool {
|
pub fn has_rest(&self) -> bool {
|
||||||
|
@ -2235,9 +1925,7 @@ pub mod signature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Pipeline {
|
impl Pipeline {
|
||||||
pub fn get_rest(
|
pub fn get_rest(&self) -> crate::plugin_capnp::argument::Pipeline {
|
||||||
&self,
|
|
||||||
) -> crate::plugin_capnp::option::Pipeline<crate::plugin_capnp::argument::Owned> {
|
|
||||||
::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(5))
|
::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(5))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2326,10 +2014,7 @@ pub mod flag {
|
||||||
!self.reader.get_pointer_field(0).is_null()
|
!self.reader.get_pointer_field(0).is_null()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_short(
|
pub fn get_short(self) -> ::capnp::Result<::capnp::text::Reader<'a>> {
|
||||||
self,
|
|
||||||
) -> ::capnp::Result<crate::plugin_capnp::option::Reader<'a, ::capnp::text::Owned>>
|
|
||||||
{
|
|
||||||
::capnp::traits::FromPointerReader::get_from_pointer(
|
::capnp::traits::FromPointerReader::get_from_pointer(
|
||||||
&self.reader.get_pointer_field(1),
|
&self.reader.get_pointer_field(1),
|
||||||
::core::option::Option::None,
|
::core::option::Option::None,
|
||||||
|
@ -2448,25 +2133,19 @@ pub mod flag {
|
||||||
!self.builder.get_pointer_field(0).is_null()
|
!self.builder.get_pointer_field(0).is_null()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_short(
|
pub fn get_short(self) -> ::capnp::Result<::capnp::text::Builder<'a>> {
|
||||||
self,
|
|
||||||
) -> ::capnp::Result<crate::plugin_capnp::option::Builder<'a, ::capnp::text::Owned>>
|
|
||||||
{
|
|
||||||
::capnp::traits::FromPointerBuilder::get_from_pointer(
|
::capnp::traits::FromPointerBuilder::get_from_pointer(
|
||||||
self.builder.get_pointer_field(1),
|
self.builder.get_pointer_field(1),
|
||||||
::core::option::Option::None,
|
::core::option::Option::None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_short(
|
pub fn set_short(&mut self, value: ::capnp::text::Reader<'_>) {
|
||||||
&mut self,
|
self.builder.get_pointer_field(1).set_text(value);
|
||||||
value: crate::plugin_capnp::option::Reader<'_, ::capnp::text::Owned>,
|
|
||||||
) -> ::capnp::Result<()> {
|
|
||||||
<crate::plugin_capnp::option::Reader<'_,::capnp::text::Owned> as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(self.builder.get_pointer_field(1), value, false)
|
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn init_short(self) -> crate::plugin_capnp::option::Builder<'a, ::capnp::text::Owned> {
|
pub fn init_short(self, size: u32) -> ::capnp::text::Builder<'a> {
|
||||||
::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(1), 0)
|
self.builder.get_pointer_field(1).init_text(size)
|
||||||
}
|
}
|
||||||
pub fn has_short(&self) -> bool {
|
pub fn has_short(&self) -> bool {
|
||||||
!self.builder.get_pointer_field(1).is_null()
|
!self.builder.get_pointer_field(1).is_null()
|
||||||
|
@ -2519,11 +2198,7 @@ pub mod flag {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Pipeline {
|
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 {
|
mod _private {
|
||||||
use capnp::private::layout;
|
use capnp::private::layout;
|
||||||
pub const STRUCT_SIZE: layout::StructSize = layout::StructSize {
|
pub const STRUCT_SIZE: layout::StructSize = layout::StructSize {
|
||||||
|
@ -3191,7 +2866,7 @@ pub mod call {
|
||||||
crate::plugin_capnp::map::Reader<
|
crate::plugin_capnp::map::Reader<
|
||||||
'a,
|
'a,
|
||||||
::capnp::text::Owned,
|
::capnp::text::Owned,
|
||||||
crate::plugin_capnp::option::Owned<crate::plugin_capnp::expression::Owned>,
|
crate::plugin_capnp::expression::Owned,
|
||||||
>,
|
>,
|
||||||
> {
|
> {
|
||||||
::capnp::traits::FromPointerReader::get_from_pointer(
|
::capnp::traits::FromPointerReader::get_from_pointer(
|
||||||
|
@ -3340,7 +3015,7 @@ pub mod call {
|
||||||
crate::plugin_capnp::map::Builder<
|
crate::plugin_capnp::map::Builder<
|
||||||
'a,
|
'a,
|
||||||
::capnp::text::Owned,
|
::capnp::text::Owned,
|
||||||
crate::plugin_capnp::option::Owned<crate::plugin_capnp::expression::Owned>,
|
crate::plugin_capnp::expression::Owned,
|
||||||
>,
|
>,
|
||||||
> {
|
> {
|
||||||
::capnp::traits::FromPointerBuilder::get_from_pointer(
|
::capnp::traits::FromPointerBuilder::get_from_pointer(
|
||||||
|
@ -3354,13 +3029,13 @@ pub mod call {
|
||||||
value: crate::plugin_capnp::map::Reader<
|
value: crate::plugin_capnp::map::Reader<
|
||||||
'_,
|
'_,
|
||||||
::capnp::text::Owned,
|
::capnp::text::Owned,
|
||||||
crate::plugin_capnp::option::Owned<crate::plugin_capnp::expression::Owned>,
|
crate::plugin_capnp::expression::Owned,
|
||||||
>,
|
>,
|
||||||
) -> ::capnp::Result<()> {
|
) -> ::capnp::Result<()> {
|
||||||
<crate::plugin_capnp::map::Reader<
|
<crate::plugin_capnp::map::Reader<
|
||||||
'_,
|
'_,
|
||||||
::capnp::text::Owned,
|
::capnp::text::Owned,
|
||||||
crate::plugin_capnp::option::Owned<crate::plugin_capnp::expression::Owned>,
|
crate::plugin_capnp::expression::Owned,
|
||||||
> as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(
|
> as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(
|
||||||
self.builder.get_pointer_field(2),
|
self.builder.get_pointer_field(2),
|
||||||
value,
|
value,
|
||||||
|
@ -3373,7 +3048,7 @@ pub mod call {
|
||||||
) -> crate::plugin_capnp::map::Builder<
|
) -> crate::plugin_capnp::map::Builder<
|
||||||
'a,
|
'a,
|
||||||
::capnp::text::Owned,
|
::capnp::text::Owned,
|
||||||
crate::plugin_capnp::option::Owned<crate::plugin_capnp::expression::Owned>,
|
crate::plugin_capnp::expression::Owned,
|
||||||
> {
|
> {
|
||||||
::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(2), 0)
|
::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(2), 0)
|
||||||
}
|
}
|
||||||
|
@ -3400,7 +3075,7 @@ pub mod call {
|
||||||
&self,
|
&self,
|
||||||
) -> crate::plugin_capnp::map::Pipeline<
|
) -> crate::plugin_capnp::map::Pipeline<
|
||||||
::capnp::text::Owned,
|
::capnp::text::Owned,
|
||||||
crate::plugin_capnp::option::Owned<crate::plugin_capnp::expression::Owned>,
|
crate::plugin_capnp::expression::Owned,
|
||||||
> {
|
> {
|
||||||
::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(2))
|
::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(2))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::plugin::PluginError;
|
use crate::plugin::PluginError;
|
||||||
use crate::plugin_capnp::{call, expression, option};
|
use crate::plugin_capnp::{call, expression};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{Call, Expr, Expression},
|
ast::{Call, Expr, Expression},
|
||||||
Span, Spanned, Type,
|
Span, Spanned, Type,
|
||||||
|
@ -40,13 +40,9 @@ fn serialize_named(
|
||||||
.set_key(key.item.as_str())
|
.set_key(key.item.as_str())
|
||||||
.map_err(|e| PluginError::EncodingError(e.to_string()))?;
|
.map_err(|e| PluginError::EncodingError(e.to_string()))?;
|
||||||
|
|
||||||
let mut value_builder = entry_builder.init_value();
|
if let Some(expr) = expression {
|
||||||
match expression {
|
let value_builder = entry_builder.init_value();
|
||||||
None => value_builder.set_none(()),
|
serialize_expression(expr, value_builder);
|
||||||
Some(expr) => {
|
|
||||||
let expression_builder = value_builder.init_some();
|
|
||||||
serialize_expression(expr, expression_builder);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,22 +125,17 @@ fn deserialize_named(span: Span, reader: call::Reader) -> Result<NamedList, Plug
|
||||||
.map_err(|e| PluginError::DecodingError(e.to_string()))?
|
.map_err(|e| PluginError::DecodingError(e.to_string()))?
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let value_reader = entry_reader
|
let value = if entry_reader.has_value() {
|
||||||
.get_value()
|
let value_reader = entry_reader
|
||||||
.map_err(|e| PluginError::DecodingError(e.to_string()))?;
|
.get_value()
|
||||||
|
.map_err(|e| PluginError::DecodingError(e.to_string()))?;
|
||||||
|
|
||||||
let value = match value_reader.which() {
|
let expression = deserialize_expression(span, value_reader)
|
||||||
Ok(option::None(())) => None,
|
.map_err(|e| PluginError::DecodingError(e.to_string()))?;
|
||||||
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)
|
Some(expression)
|
||||||
.map_err(|e| PluginError::DecodingError(e.to_string()))?;
|
} else {
|
||||||
|
None
|
||||||
Some(expression)
|
|
||||||
}
|
|
||||||
Err(capnp::NotInSchema(_)) => None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let key = Spanned { item, span };
|
let key = Spanned { item, span };
|
||||||
|
@ -194,7 +185,7 @@ fn deserialize_expression(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use capnp::serialize_packed;
|
use capnp::serialize;
|
||||||
use core::panic;
|
use core::panic;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -209,13 +200,13 @@ mod tests {
|
||||||
let builder = message.init_root::<call::Builder>();
|
let builder = message.init_root::<call::Builder>();
|
||||||
serialize_call(call, builder)?;
|
serialize_call(call, builder)?;
|
||||||
|
|
||||||
serialize_packed::write_message(writer, &message)
|
serialize::write_message(writer, &message)
|
||||||
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_buffer(reader: &mut impl std::io::BufRead) -> Result<Call, PluginError> {
|
fn read_buffer(reader: &mut impl std::io::BufRead) -> Result<Call, PluginError> {
|
||||||
let message_reader =
|
let message_reader =
|
||||||
serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap();
|
serialize::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap();
|
||||||
|
|
||||||
let reader = message_reader
|
let reader = message_reader
|
||||||
.get_root::<call::Reader>()
|
.get_root::<call::Reader>()
|
||||||
|
@ -253,18 +244,27 @@ mod tests {
|
||||||
custom_completion: None,
|
custom_completion: None,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
named: vec![(
|
named: vec![
|
||||||
Spanned {
|
(
|
||||||
item: "name".to_string(),
|
Spanned {
|
||||||
span: Span { start: 0, end: 10 },
|
item: "name".to_string(),
|
||||||
},
|
span: Span { start: 0, end: 10 },
|
||||||
Some(Expression {
|
},
|
||||||
expr: Expr::Float(1.0),
|
Some(Expression {
|
||||||
span: Span { start: 0, end: 10 },
|
expr: Expr::Float(1.0),
|
||||||
ty: nu_protocol::Type::Float,
|
span: Span { start: 0, end: 10 },
|
||||||
custom_completion: None,
|
ty: nu_protocol::Type::Float,
|
||||||
}),
|
custom_completion: None,
|
||||||
)],
|
}),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Spanned {
|
||||||
|
item: "flag".to_string(),
|
||||||
|
span: Span { start: 0, end: 10 },
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut buffer: Vec<u8> = Vec::new();
|
let mut buffer: Vec<u8> = Vec::new();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::plugin::PluginError;
|
use crate::plugin::PluginError;
|
||||||
use crate::plugin_capnp::{argument, flag, option, signature, Shape};
|
use crate::plugin_capnp::{argument, flag, signature, Shape};
|
||||||
use nu_protocol::{Flag, PositionalArg, Signature, SyntaxShape};
|
use nu_protocol::{Flag, PositionalArg, Signature, SyntaxShape};
|
||||||
|
|
||||||
pub(crate) fn serialize_signature(signature: &Signature, mut builder: signature::Builder) {
|
pub(crate) fn serialize_signature(signature: &Signature, mut builder: signature::Builder) {
|
||||||
|
@ -29,13 +29,9 @@ pub(crate) fn serialize_signature(signature: &Signature, mut builder: signature:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serializing rest argument
|
// Serializing rest argument
|
||||||
let mut rest_argument = builder.reborrow().init_rest();
|
let rest_argument = builder.reborrow().init_rest();
|
||||||
match &signature.rest_positional {
|
if let Some(arg) = &signature.rest_positional {
|
||||||
None => rest_argument.set_none(()),
|
serialize_argument(arg, rest_argument)
|
||||||
Some(arg) => {
|
|
||||||
let inner_builder = rest_argument.init_some();
|
|
||||||
serialize_argument(arg, inner_builder)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serializing the named arguments
|
// Serializing the named arguments
|
||||||
|
@ -65,13 +61,9 @@ fn serialize_flag(arg: &Flag, mut builder: flag::Builder) {
|
||||||
builder.set_required(arg.required);
|
builder.set_required(arg.required);
|
||||||
builder.set_desc(arg.desc.as_str());
|
builder.set_desc(arg.desc.as_str());
|
||||||
|
|
||||||
let mut short_builder = builder.reborrow().init_short();
|
if let Some(val) = arg.short {
|
||||||
match arg.short {
|
let mut inner_builder = builder.reborrow().init_short(1);
|
||||||
None => short_builder.set_none(()),
|
inner_builder.push_str(format!("{}", val).as_str());
|
||||||
Some(val) => {
|
|
||||||
let mut inner_builder = short_builder.reborrow().initn_some(1);
|
|
||||||
inner_builder.push_str(format!("{}", val).as_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match &arg.arg {
|
match &arg.arg {
|
||||||
|
@ -119,17 +111,14 @@ pub(crate) fn deserialize_signature(reader: signature::Reader) -> Result<Signatu
|
||||||
.collect::<Result<Vec<PositionalArg>, PluginError>>()?;
|
.collect::<Result<Vec<PositionalArg>, PluginError>>()?;
|
||||||
|
|
||||||
// Deserializing rest arguments
|
// Deserializing rest arguments
|
||||||
let rest_option = reader
|
let rest_positional = if reader.has_rest() {
|
||||||
.get_rest()
|
let argument_reader = reader
|
||||||
.map_err(|e| PluginError::EncodingError(e.to_string()))?;
|
.get_rest()
|
||||||
|
.map_err(|e| PluginError::EncodingError(e.to_string()))?;
|
||||||
|
|
||||||
let rest_positional = match rest_option.which() {
|
Some(deserialize_argument(argument_reader)?)
|
||||||
Err(capnp::NotInSchema(_)) => None,
|
} else {
|
||||||
Ok(option::None(())) => 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
|
// Deserializing named arguments
|
||||||
|
@ -196,17 +185,14 @@ fn deserialize_flag(reader: flag::Reader) -> Result<Flag, PluginError> {
|
||||||
|
|
||||||
let required = reader.get_required();
|
let required = reader.get_required();
|
||||||
|
|
||||||
let short = reader
|
let short = if reader.has_short() {
|
||||||
.get_short()
|
let short_reader = reader
|
||||||
.map_err(|e| PluginError::EncodingError(e.to_string()))?;
|
.get_short()
|
||||||
|
.map_err(|e| PluginError::EncodingError(e.to_string()))?;
|
||||||
|
|
||||||
let short = match short.which() {
|
short_reader.chars().next()
|
||||||
Err(capnp::NotInSchema(_)) => None,
|
} else {
|
||||||
Ok(option::None(())) => None,
|
None
|
||||||
Ok(option::Some(reader)) => {
|
|
||||||
let reader = reader.map_err(|e| PluginError::EncodingError(e.to_string()))?;
|
|
||||||
reader.chars().next()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let arg = reader
|
let arg = reader
|
||||||
|
@ -235,7 +221,7 @@ fn deserialize_flag(reader: flag::Reader) -> Result<Flag, PluginError> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use capnp::serialize_packed;
|
use capnp::serialize;
|
||||||
use nu_protocol::{Signature, SyntaxShape};
|
use nu_protocol::{Signature, SyntaxShape};
|
||||||
|
|
||||||
pub fn write_buffer(
|
pub fn write_buffer(
|
||||||
|
@ -248,13 +234,13 @@ mod tests {
|
||||||
|
|
||||||
serialize_signature(signature, builder);
|
serialize_signature(signature, builder);
|
||||||
|
|
||||||
serialize_packed::write_message(writer, &message)
|
serialize::write_message(writer, &message)
|
||||||
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_buffer(reader: &mut impl std::io::BufRead) -> Result<Signature, PluginError> {
|
pub fn read_buffer(reader: &mut impl std::io::BufRead) -> Result<Signature, PluginError> {
|
||||||
let message_reader =
|
let message_reader =
|
||||||
serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap();
|
serialize::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap();
|
||||||
|
|
||||||
let reader = message_reader
|
let reader = message_reader
|
||||||
.get_root::<signature::Reader>()
|
.get_root::<signature::Reader>()
|
||||||
|
@ -275,6 +261,7 @@ mod tests {
|
||||||
"second named",
|
"second named",
|
||||||
Some('s'),
|
Some('s'),
|
||||||
)
|
)
|
||||||
|
.switch("switch", "some switch", None)
|
||||||
.rest("remaining", SyntaxShape::Int, "remaining");
|
.rest("remaining", SyntaxShape::Int, "remaining");
|
||||||
|
|
||||||
let mut buffer: Vec<u8> = Vec::new();
|
let mut buffer: Vec<u8> = Vec::new();
|
||||||
|
|
|
@ -88,7 +88,7 @@ pub(crate) fn deserialize_value(reader: value::Reader) -> Result<Value, PluginEr
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use capnp::serialize_packed;
|
use capnp::serialize;
|
||||||
use nu_protocol::{Span, Value};
|
use nu_protocol::{Span, Value};
|
||||||
|
|
||||||
pub fn write_buffer(
|
pub fn write_buffer(
|
||||||
|
@ -101,13 +101,13 @@ mod tests {
|
||||||
|
|
||||||
serialize_value(value, builder.reborrow());
|
serialize_value(value, builder.reborrow());
|
||||||
|
|
||||||
serialize_packed::write_message(writer, &message)
|
serialize::write_message(writer, &message)
|
||||||
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
.map_err(|e| PluginError::EncodingError(e.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_buffer(reader: &mut impl std::io::BufRead) -> Result<Value, PluginError> {
|
pub fn read_buffer(reader: &mut impl std::io::BufRead) -> Result<Value, PluginError> {
|
||||||
let message_reader =
|
let message_reader =
|
||||||
serialize_packed::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap();
|
serialize::read_message(reader, ::capnp::message::ReaderOptions::new()).unwrap();
|
||||||
|
|
||||||
let reader = message_reader
|
let reader = message_reader
|
||||||
.get_root::<value::Reader>()
|
.get_root::<value::Reader>()
|
||||||
|
|
Loading…
Reference in a new issue