Skip to content

Commit

Permalink
Use workaround to make generated code CI pass
Browse files Browse the repository at this point in the history
  • Loading branch information
umgefahren committed Mar 7, 2024
1 parent bd495f9 commit 38be2b4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
6 changes: 5 additions & 1 deletion protocols/autonat/src/v2.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use libp2p_swarm::StreamProtocol;

pub mod client;
mod generated;
pub(crate) mod protocol;
pub mod server;

pub(crate) mod generated {
#![allow(unreachable_pub)]
include!("v2/generated/mod.rs");
}

pub(crate) const DIAL_REQUEST_PROTOCOL: StreamProtocol =
StreamProtocol::new("/libp2p/autonat/2/dial-request");
pub(crate) const DIAL_BACK_PROTOCOL: StreamProtocol =
Expand Down
2 changes: 1 addition & 1 deletion protocols/autonat/src/v2/generated/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Automatically generated mod.rs
pub(crate) mod structs;
pub mod structs;
55 changes: 27 additions & 28 deletions protocols/autonat/src/v2/generated/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
#![cfg_attr(rustfmt, rustfmt_skip)]


use std::borrow::Cow;

use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result};
use quick_protobuf::sizeofs::*;
use super::*;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub(crate) enum DialStatus {
pub enum DialStatus {
UNUSED = 0,
E_DIAL_ERROR = 100,
E_DIAL_BACK_ERROR = 101,
Expand Down Expand Up @@ -55,8 +53,8 @@ impl<'a> From<&'a str> for DialStatus {

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub(crate) struct Message {
pub(crate) msg: structs::mod_Message::OneOfmsg,
pub struct Message {
pub msg: structs::mod_Message::OneOfmsg,
}

impl<'a> MessageRead<'a> for Message {
Expand Down Expand Up @@ -97,12 +95,12 @@ impl MessageWrite for Message {
}
}

pub(crate) mod mod_Message {
pub mod mod_Message {

use super::*;

#[derive(Debug, PartialEq, Clone)]
pub(crate) enum OneOfmsg {
pub enum OneOfmsg {
dialRequest(structs::DialRequest),
dialResponse(structs::DialResponse),
dialDataRequest(structs::DialDataRequest),
Expand All @@ -120,9 +118,9 @@ impl Default for OneOfmsg {

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub(crate) struct DialRequest {
pub(crate) addrs: Vec<Vec<u8>>,
pub(crate) nonce: Option<u64>,
pub struct DialRequest {
pub addrs: Vec<Vec<u8>>,
pub nonce: Option<u64>,
}

impl<'a> MessageRead<'a> for DialRequest {
Expand Down Expand Up @@ -156,9 +154,9 @@ impl MessageWrite for DialRequest {

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub(crate) struct DialDataRequest {
pub(crate) addrIdx: Option<u32>,
pub(crate) numBytes: Option<u64>,
pub struct DialDataRequest {
pub addrIdx: Option<u32>,
pub numBytes: Option<u64>,
}

impl<'a> MessageRead<'a> for DialDataRequest {
Expand Down Expand Up @@ -192,10 +190,10 @@ impl MessageWrite for DialDataRequest {

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub(crate) struct DialResponse {
pub(crate) status: Option<structs::mod_DialResponse::ResponseStatus>,
pub(crate) addrIdx: Option<u32>,
pub(crate) dialStatus: Option<structs::DialStatus>,
pub struct DialResponse {
pub status: Option<structs::mod_DialResponse::ResponseStatus>,
pub addrIdx: Option<u32>,
pub dialStatus: Option<structs::DialStatus>,
}

impl<'a> MessageRead<'a> for DialResponse {
Expand Down Expand Up @@ -230,11 +228,11 @@ impl MessageWrite for DialResponse {
}
}

pub(crate) mod mod_DialResponse {
pub mod mod_DialResponse {


#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub(crate) enum ResponseStatus {
pub enum ResponseStatus {
E_INTERNAL_ERROR = 0,
E_REQUEST_REJECTED = 100,
E_DIAL_REFUSED = 101,
Expand Down Expand Up @@ -275,16 +273,16 @@ impl<'a> From<&'a str> for ResponseStatus {

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub(crate) struct DialDataResponse {
pub(crate) data: Option<Cow<'static, [u8]>>,
pub struct DialDataResponse {
pub data: Option<Vec<u8>>,
}

impl<'a> MessageRead<'a> for DialDataResponse {
fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
let mut msg = Self::default();
while !r.is_eof() {
match r.next_tag(bytes) {
Ok(10) => msg.data = Some(r.read_bytes(bytes)?.to_owned().into()),
Ok(10) => msg.data = Some(r.read_bytes(bytes)?.to_owned()),
Ok(t) => { r.read_unknown(bytes, t)?; }
Err(e) => return Err(e),
}
Expand All @@ -307,8 +305,8 @@ impl MessageWrite for DialDataResponse {

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub(crate) struct DialBack {
pub(crate) nonce: Option<u64>,
pub struct DialBack {
pub nonce: Option<u64>,
}

impl<'a> MessageRead<'a> for DialBack {
Expand Down Expand Up @@ -339,8 +337,8 @@ impl MessageWrite for DialBack {

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub(crate) struct DialBackResponse {
pub(crate) status: Option<structs::mod_DialBackResponse::DialBackStatus>,
pub struct DialBackResponse {
pub status: Option<structs::mod_DialBackResponse::DialBackStatus>,
}

impl<'a> MessageRead<'a> for DialBackResponse {
Expand Down Expand Up @@ -369,11 +367,11 @@ impl MessageWrite for DialBackResponse {
}
}

pub(crate) mod mod_DialBackResponse {
pub mod mod_DialBackResponse {


#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub(crate) enum DialBackStatus {
pub enum DialBackStatus {
OK = 0,
}

Expand Down Expand Up @@ -402,3 +400,4 @@ impl<'a> From<&'a str> for DialBackStatus {
}

}

4 changes: 2 additions & 2 deletions protocols/autonat/src/v2/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// change to quick-protobuf-codec

use std::io;
use std::io::ErrorKind;
use std::{borrow::Cow, io};

use asynchronous_codec::{Framed, FramedRead, FramedWrite};

Expand Down Expand Up @@ -110,7 +110,7 @@ impl From<DialDataResponse> for proto::Message {
static DATA: &[u8] = &[0u8; DATA_FIELD_LEN_UPPER_BOUND];
proto::Message {
msg: proto::mod_Message::OneOfmsg::dialDataResponse(proto::DialDataResponse {
data: Some(Cow::Borrowed(&DATA[..val.data_count])),
data: Some(DATA[..val.data_count].to_vec()), // Once could use Cow::Borrowed here, but it will require a modification of the generated code and that will fail the CI
}),
}
}
Expand Down

0 comments on commit 38be2b4

Please sign in to comment.