1
0
Fork 0
forked from wry/wry

Merge pull request #92 from mahkoh/jorth/bincode1

config: downgrade bincode to 1.3.3
This commit is contained in:
mahkoh 2024-02-16 14:42:04 +01:00 committed by GitHub
commit 63ed3fa689
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 91 additions and 104 deletions

22
Cargo.lock generated
View file

@ -153,23 +153,13 @@ dependencies = [
[[package]] [[package]]
name = "bincode" name = "bincode"
version = "2.0.0-rc.3" version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95" checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [ dependencies = [
"bincode_derive",
"serde", "serde",
] ]
[[package]]
name = "bincode_derive"
version = "2.0.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e30759b3b99a1b802a7a3aa21c85c3ded5c28e1c83170d82d70f08bbf7f3e4c"
dependencies = [
"virtue",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -533,6 +523,7 @@ dependencies = [
"pin-project", "pin-project",
"rand", "rand",
"repc", "repc",
"serde",
"shaderc", "shaderc",
"smallvec", "smallvec",
"thiserror", "thiserror",
@ -545,6 +536,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"bincode", "bincode",
"log", "log",
"serde",
] ]
[[package]] [[package]]
@ -1057,12 +1049,6 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "virtue"
version = "0.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"

View file

@ -29,7 +29,7 @@ once_cell = "1.19.0"
rand = "0.8.5" rand = "0.8.5"
smallvec = { version = "1.11.1", features = ["const_generics", "const_new", "union"] } smallvec = { version = "1.11.1", features = ["const_generics", "const_new", "union"] }
byteorder = "1.5.0" byteorder = "1.5.0"
bincode = "2.0.0-rc.3" bincode = "1.3.3"
jay-config = { path = "jay-config" } jay-config = { path = "jay-config" }
default-config = { path = "default-config" } default-config = { path = "default-config" }
algorithms = { path = "algorithms" } algorithms = { path = "algorithms" }
@ -46,6 +46,7 @@ indexmap = "2.2.0"
ash = "0.37.3" ash = "0.37.3"
gpu-alloc = "0.6.0" gpu-alloc = "0.6.0"
gpu-alloc-ash = "0.6.0" gpu-alloc-ash = "0.6.0"
serde = { version = "1.0.196", features = ["derive"] }
[build-dependencies] [build-dependencies]
repc = "0.1.1" repc = "0.1.1"

View file

@ -6,5 +6,6 @@ license = "GPL-3.0-only"
description = "Configuration crate for the Jay compositor" description = "Configuration crate for the Jay compositor"
[dependencies] [dependencies]
bincode = "2.0.0-rc.1" bincode = "1.3.3"
serde = { version = "1.0.196", features = ["derive"] }
log = "0.4.14" log = "0.4.14"

View file

@ -2,7 +2,7 @@ pub mod client;
pub mod ipc; pub mod ipc;
mod logging; mod logging;
use std::marker::PhantomData; use {bincode::Options, std::marker::PhantomData};
pub const VERSION: u32 = 1; pub const VERSION: u32 = 1;
@ -26,9 +26,9 @@ pub struct ConfigEntryGen<T> {
impl<T: Config> ConfigEntryGen<T> {} impl<T: Config> ConfigEntryGen<T> {}
pub fn bincode_ops() -> impl bincode::config::Config { pub fn bincode_ops() -> impl Options {
bincode::config::standard() bincode::DefaultOptions::new()
.with_fixed_int_encoding() .with_fixint_encoding()
.with_little_endian() .with_little_endian()
.with_no_limit() .with_no_limit()
} }

View file

@ -19,6 +19,7 @@ use {
}, },
Axis, Direction, ModifiedKeySym, PciId, Workspace, Axis, Direction, ModifiedKeySym, PciId, Workspace,
}, },
bincode::Options,
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
collections::{hash_map::Entry, HashMap}, collections::{hash_map::Entry, HashMap},
@ -171,7 +172,7 @@ impl Client {
fn send(&self, msg: &ClientMessage) { fn send(&self, msg: &ClientMessage) {
let mut buf = self.bufs.borrow_mut().pop().unwrap_or_default(); let mut buf = self.bufs.borrow_mut().pop().unwrap_or_default();
buf.clear(); buf.clear();
bincode::encode_into_std_write(msg, &mut buf, bincode_ops()).unwrap(); bincode_ops().serialize_into(&mut buf, msg).unwrap();
unsafe { unsafe {
(self.srv_handler)(self.srv_data, buf.as_ptr(), buf.len()); (self.srv_handler)(self.srv_data, buf.as_ptr(), buf.len());
} }
@ -700,8 +701,8 @@ impl Client {
} }
fn handle_msg(&self, msg: &[u8]) { fn handle_msg(&self, msg: &[u8]) {
let res = bincode::borrow_decode_from_slice::<ServerMessage, _>(msg, bincode_ops()); let res = bincode_ops().deserialize::<ServerMessage>(msg);
let (msg, _) = match res { let msg = match res {
Ok(msg) => msg, Ok(msg) => msg,
Err(e) => { Err(e) => {
let msg = format!("could not deserialize message: {}", e); let msg = format!("could not deserialize message: {}", e);
@ -787,7 +788,7 @@ impl Client {
} }
fn handle_init_msg(&self, msg: &[u8]) { fn handle_init_msg(&self, msg: &[u8]) {
let (init, _) = match bincode::decode_from_slice::<InitMessage, _>(msg, bincode_ops()) { let init = match bincode_ops().deserialize::<InitMessage>(msg) {
Ok(m) => m, Ok(m) => m,
Err(e) => { Err(e) => {
let msg = format!("could not deserialize message: {}", e); let msg = format!("could not deserialize message: {}", e);

View file

@ -8,11 +8,11 @@ use {
video::{connector_type::ConnectorType, Connector, DrmDevice, GfxApi}, video::{connector_type::ConnectorType, Connector, DrmDevice, GfxApi},
Axis, Direction, PciId, Workspace, Axis, Direction, PciId, Workspace,
}, },
bincode::{BorrowDecode, Decode, Encode}, serde::{Deserialize, Serialize},
std::time::Duration, std::time::Duration,
}; };
#[derive(Encode, BorrowDecode, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub enum ServerMessage { pub enum ServerMessage {
Configure { Configure {
reload: bool, reload: bool,
@ -58,7 +58,7 @@ pub enum ServerMessage {
DevicesEnumerated, DevicesEnumerated,
} }
#[derive(Encode, BorrowDecode, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub enum ClientMessage<'a> { pub enum ClientMessage<'a> {
Reload, Reload,
Quit, Quit,
@ -340,7 +340,7 @@ pub enum ClientMessage<'a> {
}, },
} }
#[derive(Encode, Decode, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub enum Response { pub enum Response {
None, None,
GetSeats { GetSeats {
@ -442,10 +442,10 @@ pub enum Response {
}, },
} }
#[derive(Encode, Decode, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub enum InitMessage { pub enum InitMessage {
V1(V1InitMessage), V1(V1InitMessage),
} }
#[derive(Encode, Decode, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct V1InitMessage {} pub struct V1InitMessage {}

View file

@ -9,11 +9,11 @@ use {
keyboard::Keymap, keyboard::Keymap,
Axis, Direction, ModifiedKeySym, Workspace, Axis, Direction, ModifiedKeySym, Workspace,
}, },
bincode::{Decode, Encode}, serde::{Deserialize, Serialize},
}; };
/// An input device. /// An input device.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct InputDevice(pub u64); pub struct InputDevice(pub u64);
impl InputDevice { impl InputDevice {
@ -114,7 +114,7 @@ impl InputDevice {
} }
/// A seat. /// A seat.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Seat(pub u64); pub struct Seat(pub u64);
impl Seat { impl Seat {

View file

@ -2,10 +2,10 @@
//! //!
//! See the libinput documentation for details. //! See the libinput documentation for details.
use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize};
/// The acceleration profile of a device. /// The acceleration profile of a device.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct AccelProfile(pub u32); pub struct AccelProfile(pub u32);
/// A flat acceleration profile. /// A flat acceleration profile.

View file

@ -2,10 +2,10 @@
//! //!
//! See the libinput documentation for the meanings of these constants. //! See the libinput documentation for the meanings of these constants.
use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize};
/// A capability of an input device. /// A capability of an input device.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Capability(pub u32); pub struct Capability(pub u32);
pub const CAP_KEYBOARD: Capability = Capability(0); pub const CAP_KEYBOARD: Capability = Capability(0);

View file

@ -2,7 +2,7 @@
use { use {
crate::keyboard::{mods::Modifiers, syms::KeySym}, crate::keyboard::{mods::Modifiers, syms::KeySym},
bincode::{Decode, Encode}, serde::{Deserialize, Serialize},
std::ops::{BitOr, BitOrAssign}, std::ops::{BitOr, BitOrAssign},
}; };
@ -10,7 +10,7 @@ pub mod mods;
pub mod syms; pub mod syms;
/// A keysym with zero or more modifiers /// A keysym with zero or more modifiers
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Hash, Debug)] #[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct ModifiedKeySym { pub struct ModifiedKeySym {
pub mods: Modifiers, pub mods: Modifiers,
pub sym: KeySym, pub sym: KeySym,
@ -43,7 +43,7 @@ impl BitOrAssign<Modifiers> for ModifiedKeySym {
} }
/// A keymap. /// A keymap.
#[derive(Encode, Decode, Copy, Clone, Debug, Eq, PartialEq, Hash)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct Keymap(pub u64); pub struct Keymap(pub u64);
impl Keymap { impl Keymap {

View file

@ -2,12 +2,12 @@
use { use {
crate::{keyboard::syms::KeySym, ModifiedKeySym}, crate::{keyboard::syms::KeySym, ModifiedKeySym},
bincode::{Decode, Encode}, serde::{Deserialize, Serialize},
std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign}, std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign},
}; };
/// Zero or more keyboard modifiers /// Zero or more keyboard modifiers
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Default, Hash, Debug)] #[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Default, Hash, Debug)]
pub struct Modifiers(pub u32); pub struct Modifiers(pub u32);
/// The Shift modifier /// The Shift modifier

View file

@ -2,10 +2,10 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize};
/// A keysym. /// A keysym.
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Hash, Debug)] #[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct KeySym(pub u32); pub struct KeySym(pub u32);
pub const SYM_BackSpace: KeySym = KeySym(0xff08); pub const SYM_BackSpace: KeySym = KeySym(0xff08);

View file

@ -42,7 +42,7 @@
use { use {
crate::keyboard::ModifiedKeySym, crate::keyboard::ModifiedKeySym,
bincode::{Decode, Encode}, serde::{Deserialize, Serialize},
std::fmt::{Debug, Display, Formatter}, std::fmt::{Debug, Display, Formatter},
}; };
@ -61,7 +61,7 @@ pub mod timer;
pub mod video; pub mod video;
/// A planar direction. /// A planar direction.
#[derive(Encode, Decode, Copy, Clone, Debug, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub enum Direction { pub enum Direction {
Left, Left,
Down, Down,
@ -70,7 +70,7 @@ pub enum Direction {
} }
/// A planar axis. /// A planar axis.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum Axis { pub enum Axis {
Horizontal, Horizontal,
Vertical, Vertical,
@ -129,7 +129,7 @@ pub fn toggle_default_workspace_capture() {
} }
/// A workspace. /// A workspace.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Workspace(pub u64); pub struct Workspace(pub u64);
impl Workspace { impl Workspace {
@ -170,7 +170,7 @@ pub fn get_workspace(name: &str) -> Workspace {
/// PCI IDs can be used to identify a hardware component. See the Debian [documentation][pci]. /// PCI IDs can be used to identify a hardware component. See the Debian [documentation][pci].
/// ///
/// [pci]: https://wiki.debian.org/HowToIdentifyADevice/PCI /// [pci]: https://wiki.debian.org/HowToIdentifyADevice/PCI
#[derive(Encode, Decode, Debug, Copy, Clone, Hash, Eq, PartialEq, Default)] #[derive(Serialize, Deserialize, Debug, Copy, Clone, Hash, Eq, PartialEq, Default)]
pub struct PciId { pub struct PciId {
pub vendor: u32, pub vendor: u32,
pub model: u32, pub model: u32,

View file

@ -3,10 +3,10 @@
//! Note that you can use the `log` crate for logging. All invocations of `log::info` etc. //! Note that you can use the `log` crate for logging. All invocations of `log::info` etc.
//! automatically log into the compositors log. //! automatically log into the compositors log.
use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize};
/// The log level of the compositor or a log message. /// The log level of the compositor or a log message.
#[derive(Encode, Decode, Copy, Clone, Debug)] #[derive(Serialize, Deserialize, Copy, Clone, Debug)]
pub enum LogLevel { pub enum LogLevel {
Error, Error,
Warn, Warn,

View file

@ -1,6 +1,6 @@
//! Tools for configuring the look of the compositor. //! Tools for configuring the look of the compositor.
use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize};
/// A color. /// A color.
/// ///
@ -15,7 +15,7 @@ use bincode::{Decode, Encode};
/// ///
/// When using hexadecimal notation, `#RRGGBBAA`, the RGB values are usually straight. /// When using hexadecimal notation, `#RRGGBBAA`, the RGB values are usually straight.
// values are stored premultiplied // values are stored premultiplied
#[derive(Encode, Decode, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Color { pub struct Color {
r: f32, r: f32,
g: f32, g: f32,
@ -160,11 +160,11 @@ pub fn reset_font() {
pub mod colors { pub mod colors {
use { use {
crate::theme::Color, crate::theme::Color,
bincode::{Decode, Encode}, serde::{Deserialize, Serialize},
}; };
/// An element of the GUI whose color can be changed. /// An element of the GUI whose color can be changed.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Colorable(#[doc(hidden)] pub u32); pub struct Colorable(#[doc(hidden)] pub u32);
impl Colorable { impl Colorable {
@ -262,10 +262,10 @@ pub mod colors {
/// Elements of the compositor whose size can be changed. /// Elements of the compositor whose size can be changed.
pub mod sized { pub mod sized {
use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize};
/// An element of the GUI whose size can be changed. /// An element of the GUI whose size can be changed.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Resizable(#[doc(hidden)] pub u32); pub struct Resizable(#[doc(hidden)] pub u32);
impl Resizable { impl Resizable {

View file

@ -1,12 +1,12 @@
//! Timers for one-time or repeated actions. //! Timers for one-time or repeated actions.
use { use {
bincode::{Decode, Encode}, serde::{Deserialize, Serialize},
std::time::{Duration, SystemTime, UNIX_EPOCH}, std::time::{Duration, SystemTime, UNIX_EPOCH},
}; };
/// A timer. /// A timer.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Timer(pub u64); pub struct Timer(pub u64);
/// Creates a new timer or returns an existing one. /// Creates a new timer or returns an existing one.

View file

@ -10,7 +10,7 @@ use {
}, },
PciId, PciId,
}, },
bincode::{Decode, Encode}, serde::{Deserialize, Serialize},
std::str::FromStr, std::str::FromStr,
}; };
@ -59,7 +59,7 @@ impl Mode {
/// ///
/// A connector is the part that sticks out of your graphics card. A graphics card usually /// A connector is the part that sticks out of your graphics card. A graphics card usually
/// has many connectors but one few of them are actually connected to a monitor. /// has many connectors but one few of them are actually connected to a monitor.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Connector(pub u64); pub struct Connector(pub u64);
impl Connector { impl Connector {
@ -286,10 +286,10 @@ impl ToConnectorId for &'_ str {
/// Module containing all known connector types. /// Module containing all known connector types.
pub mod connector_type { pub mod connector_type {
use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize};
/// The type of a connector. /// The type of a connector.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct ConnectorType(pub u32); pub struct ConnectorType(pub u32);
pub const CON_UNKNOWN: ConnectorType = ConnectorType(0); pub const CON_UNKNOWN: ConnectorType = ConnectorType(0);
@ -321,7 +321,7 @@ pub mod connector_type {
/// It's easiest to think of a DRM device as a graphics card. /// It's easiest to think of a DRM device as a graphics card.
/// There are also DRM devices that are emulated in software but you are unlikely to encounter /// There are also DRM devices that are emulated in software but you are unlikely to encounter
/// those accidentally. /// those accidentally.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct DrmDevice(pub u64); pub struct DrmDevice(pub u64);
impl DrmDevice { impl DrmDevice {
@ -373,7 +373,7 @@ impl DrmDevice {
/// A graphics API. /// A graphics API.
#[non_exhaustive] #[non_exhaustive]
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum GfxApi { pub enum GfxApi {
OpenGl, OpenGl,
Vulkan, Vulkan,

View file

@ -13,6 +13,7 @@ use {
unlink_on_drop::UnlinkOnDrop, xrd::xrd, unlink_on_drop::UnlinkOnDrop, xrd::xrd,
}, },
}, },
bincode::Options,
jay_config::{ jay_config::{
_private::{ _private::{
bincode_ops, bincode_ops,
@ -175,8 +176,9 @@ impl ConfigProxy {
timers_by_name: Default::default(), timers_by_name: Default::default(),
timers_by_id: Default::default(), timers_by_id: Default::default(),
}); });
let init_msg = let init_msg = bincode_ops()
bincode::encode_to_vec(&InitMessage::V1(V1InitMessage {}), bincode_ops()).unwrap(); .serialize(&InitMessage::V1(V1InitMessage {}))
.unwrap();
unsafe { unsafe {
let client_data = (entry.init)( let client_data = (entry.init)(
Rc::into_raw(data.clone()) as _, Rc::into_raw(data.clone()) as _,

View file

@ -22,7 +22,7 @@ use {
}, },
xkbcommon::{XkbCommonError, XkbKeymap}, xkbcommon::{XkbCommonError, XkbKeymap},
}, },
bincode::error::DecodeError, bincode::Options,
jay_config::{ jay_config::{
_private::{ _private::{
bincode_ops, bincode_ops,
@ -89,7 +89,7 @@ impl ConfigProxyHandler {
pub fn send(&self, msg: &ServerMessage) { pub fn send(&self, msg: &ServerMessage) {
let mut buf = self.bufs.pop().unwrap_or_default(); let mut buf = self.bufs.pop().unwrap_or_default();
buf.clear(); buf.clear();
bincode::encode_into_std_write(msg, &mut buf, bincode_ops()).unwrap(); bincode_ops().serialize_into(&mut buf, msg).unwrap();
unsafe { unsafe {
(self.handle_msg)(self.client_data.get(), buf.as_ptr(), buf.len()); (self.handle_msg)(self.client_data.get(), buf.as_ptr(), buf.len());
} }
@ -1097,11 +1097,10 @@ impl ConfigProxyHandler {
} }
fn handle_request_(self: &Rc<Self>, msg: &[u8]) -> Result<(), CphError> { fn handle_request_(self: &Rc<Self>, msg: &[u8]) -> Result<(), CphError> {
let (request, _) = let request = match bincode_ops().deserialize::<ClientMessage>(msg) {
match bincode::borrow_decode_from_slice::<ClientMessage, _>(msg, bincode_ops()) { Ok(msg) => msg,
Ok(msg) => msg, Err(e) => return Err(CphError::ParsingFailed(e)),
Err(e) => return Err(CphError::ParsingFailed(e)), };
};
match request { match request {
ClientMessage::Log { ClientMessage::Log {
level, level,
@ -1367,7 +1366,7 @@ enum CphError {
#[error("Sized element {0} is not known")] #[error("Sized element {0} is not known")]
UnknownSized(u32), UnknownSized(u32),
#[error("Could not parse the message")] #[error("Could not parse the message")]
ParsingFailed(#[source] DecodeError), ParsingFailed(#[source] bincode::Error),
#[error("Could not process a `{0}` request")] #[error("Could not process a `{0}` request")]
FailedRequest(&'static str, #[source] Box<Self>), FailedRequest(&'static str, #[source] Box<Self>),
#[error(transparent)] #[error(transparent)]

View file

@ -17,12 +17,10 @@ use {
}, },
xwayland, xwayland,
}, },
bincode::{ bincode::Options,
error::{DecodeError, EncodeError},
Decode, Encode,
},
jay_config::_private::bincode_ops, jay_config::_private::bincode_ops,
log::Level, log::Level,
serde::{Deserialize, Serialize},
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
env, env,
@ -65,9 +63,9 @@ pub enum ForkerError {
#[error("Could not write the next message")] #[error("Could not write the next message")]
WriteFailed(#[source] BufFdError), WriteFailed(#[source] BufFdError),
#[error("Could not decode the next message")] #[error("Could not decode the next message")]
DecodeFailed(#[source] DecodeError), DecodeFailed(#[source] bincode::Error),
#[error("Could not encode the next message")] #[error("Could not encode the next message")]
EncodeFailed(#[source] EncodeError), EncodeFailed(#[source] bincode::Error),
#[error("Could not fork")] #[error("Could not fork")]
PidfdForkFailed, PidfdForkFailed,
} }
@ -264,7 +262,7 @@ impl ForkerProxy {
} }
} }
#[derive(Encode, Decode)] #[derive(Serialize, Deserialize)]
enum ServerMessage { enum ServerMessage {
SetEnv { SetEnv {
var: Vec<u8>, var: Vec<u8>,
@ -281,7 +279,7 @@ enum ServerMessage {
}, },
} }
#[derive(Encode, Decode)] #[derive(Serialize, Deserialize)]
enum ForkerMessage { enum ForkerMessage {
Log { Log {
level: usize, level: usize,
@ -319,7 +317,7 @@ impl Forker {
level: log::Level::Error as _, level: log::Level::Error as _,
msg: format!("The ol' forker panicked: {}", pi), msg: format!("The ol' forker panicked: {}", pi),
}; };
let msg = bincode::encode_to_vec(msg, bincode_ops()).unwrap(); let msg = bincode_ops().serialize(&msg).unwrap();
let _ = Fd::new(socket).write_all(&msg); let _ = Fd::new(socket).write_all(&msg);
}) })
}); });

View file

@ -1,5 +1,6 @@
use { use {
bincode::{Decode, Encode}, bincode::Options,
serde::{de::DeserializeOwned, Serialize},
std::{mem, rc::Rc}, std::{mem, rc::Rc},
}; };
@ -34,7 +35,7 @@ impl IoIn {
self.incoming.get_fd().ok() self.incoming.get_fd().ok()
} }
pub async fn read_msg<T: Decode>(&mut self) -> Result<T, ForkerError> { pub async fn read_msg<T: DeserializeOwned>(&mut self) -> Result<T, ForkerError> {
let mut len = 0usize; let mut len = 0usize;
if let Err(e) = self.incoming.read_full(&mut len).await { if let Err(e) = self.incoming.read_full(&mut len).await {
return Err(ForkerError::ReadFailed(e)); return Err(ForkerError::ReadFailed(e));
@ -48,11 +49,9 @@ impl IoIn {
unsafe { unsafe {
self.scratch.set_len(len); self.scratch.set_len(len);
} }
let res = bincode::decode_from_slice::<T, _>(&self.scratch, bincode_ops()); bincode_ops()
match res { .deserialize::<T>(&self.scratch)
Ok((msg, _)) => Ok(msg), .map_err(ForkerError::DecodeFailed)
Err(e) => Err(ForkerError::DecodeFailed(e)),
}
} }
} }
@ -75,14 +74,13 @@ impl IoOut {
self.fds.push(fd); self.fds.push(fd);
} }
pub async fn write_msg<T: Encode>(&mut self, msg: T) -> Result<(), ForkerError> { pub async fn write_msg<T: Serialize>(&mut self, msg: T) -> Result<(), ForkerError> {
self.scratch.clear(); self.scratch.clear();
self.scratch.extend_from_slice(uapi::as_bytes(&0usize)); self.scratch.extend_from_slice(uapi::as_bytes(&0usize));
let res = bincode::encode_into_std_write(&msg, &mut self.scratch, bincode_ops()); bincode_ops()
let len = match res { .serialize_into(&mut self.scratch, &msg)
Ok(l) => l, .map_err(ForkerError::EncodeFailed)?;
Err(e) => return Err(ForkerError::EncodeFailed(e)), let len = self.scratch.len() - mem::size_of_val(&0usize);
};
self.scratch[..mem::size_of_val(&len)].copy_from_slice(uapi::as_bytes(&len)); self.scratch[..mem::size_of_val(&len)].copy_from_slice(uapi::as_bytes(&len));
let mut buf = self.scratch.borrow(); let mut buf = self.scratch.borrow();
match self match self

View file

@ -5,6 +5,7 @@ use {
it::test_error::{TestError, TestResult}, it::test_error::{TestError, TestResult},
utils::{copyhashmap::CopyHashMap, stack::Stack}, utils::{copyhashmap::CopyHashMap, stack::Stack},
}, },
bincode::Options,
isnt::std_1::primitive::IsntConstPtrExt, isnt::std_1::primitive::IsntConstPtrExt,
jay_config::{ jay_config::{
_private::{ _private::{
@ -76,8 +77,8 @@ unsafe extern "C" fn unref(data: *const u8) {
unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) { unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
let tc = &*data.cast::<TestConfig>(); let tc = &*data.cast::<TestConfig>();
let msg = std::slice::from_raw_parts(msg, size); let msg = std::slice::from_raw_parts(msg, size);
let res = bincode::borrow_decode_from_slice::<ServerMessage, _>(msg, bincode_ops()); let res = bincode_ops().deserialize::<ServerMessage>(msg);
let (msg, _) = match res { let msg = match res {
Ok(msg) => msg, Ok(msg) => msg,
Err(e) => { Err(e) => {
log::error!("could not deserialize message: {}", e); log::error!("could not deserialize message: {}", e);
@ -145,7 +146,7 @@ impl TestConfig {
_ => bail!("srv not set"), _ => bail!("srv not set"),
}; };
let mut buf = vec![]; let mut buf = vec![];
bincode::encode_into_std_write(msg, &mut buf, bincode_ops()).unwrap(); bincode_ops().serialize_into(&mut buf, msg).unwrap();
unsafe { unsafe {
(srv.srv_handler)(srv.srv_data, buf.as_ptr(), buf.len()); (srv.srv_handler)(srv.srv_data, buf.as_ptr(), buf.len());
} }