1
0
Fork 0
forked from wry/wry

config: downgrade bincode to 1.3.3

This should not have any impact on existing configs since bincode claims
compatibility of the wire format between 1.3.3 and 2.0.0.
This commit is contained in:
Julian Orth 2024-02-16 14:02:45 +01:00
parent 6921531702
commit 615acd4847
22 changed files with 91 additions and 104 deletions

View file

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

View file

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

View file

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

View file

@ -9,11 +9,11 @@ use {
keyboard::Keymap,
Axis, Direction, ModifiedKeySym, Workspace,
},
bincode::{Decode, Encode},
serde::{Deserialize, Serialize},
};
/// 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);
impl InputDevice {
@ -114,7 +114,7 @@ impl InputDevice {
}
/// 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);
impl Seat {

View file

@ -2,10 +2,10 @@
//!
//! See the libinput documentation for details.
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
/// 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);
/// A flat acceleration profile.

View file

@ -2,10 +2,10 @@
//!
//! See the libinput documentation for the meanings of these constants.
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
/// 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 const CAP_KEYBOARD: Capability = Capability(0);

View file

@ -2,7 +2,7 @@
use {
crate::keyboard::{mods::Modifiers, syms::KeySym},
bincode::{Decode, Encode},
serde::{Deserialize, Serialize},
std::ops::{BitOr, BitOrAssign},
};
@ -10,7 +10,7 @@ pub mod mods;
pub mod syms;
/// 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 mods: Modifiers,
pub sym: KeySym,
@ -43,7 +43,7 @@ impl BitOrAssign<Modifiers> for ModifiedKeySym {
}
/// 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);
impl Keymap {

View file

@ -2,12 +2,12 @@
use {
crate::{keyboard::syms::KeySym, ModifiedKeySym},
bincode::{Decode, Encode},
serde::{Deserialize, Serialize},
std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign},
};
/// 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);
/// The Shift modifier

View file

@ -2,10 +2,10 @@
#![allow(non_upper_case_globals)]
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
/// 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 const SYM_BackSpace: KeySym = KeySym(0xff08);

View file

@ -42,7 +42,7 @@
use {
crate::keyboard::ModifiedKeySym,
bincode::{Decode, Encode},
serde::{Deserialize, Serialize},
std::fmt::{Debug, Display, Formatter},
};
@ -61,7 +61,7 @@ pub mod timer;
pub mod video;
/// A planar direction.
#[derive(Encode, Decode, Copy, Clone, Debug, Eq, PartialEq)]
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
pub enum Direction {
Left,
Down,
@ -70,7 +70,7 @@ pub enum Direction {
}
/// A planar axis.
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum Axis {
Horizontal,
Vertical,
@ -129,7 +129,7 @@ pub fn toggle_default_workspace_capture() {
}
/// 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);
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]: 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 vendor: 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.
//! automatically log into the compositors log.
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
/// 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 {
Error,
Warn,

View file

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

View file

@ -1,12 +1,12 @@
//! Timers for one-time or repeated actions.
use {
bincode::{Decode, Encode},
serde::{Deserialize, Serialize},
std::time::{Duration, SystemTime, UNIX_EPOCH},
};
/// 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);
/// Creates a new timer or returns an existing one.

View file

@ -10,7 +10,7 @@ use {
},
PciId,
},
bincode::{Decode, Encode},
serde::{Deserialize, Serialize},
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
/// 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);
impl Connector {
@ -286,10 +286,10 @@ impl ToConnectorId for &'_ str {
/// Module containing all known connector types.
pub mod connector_type {
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
/// 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 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.
/// There are also DRM devices that are emulated in software but you are unlikely to encounter
/// 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);
impl DrmDevice {
@ -373,7 +373,7 @@ impl DrmDevice {
/// A graphics API.
#[non_exhaustive]
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum GfxApi {
OpenGl,
Vulkan,