initial import from steam-vent repo

This commit is contained in:
Robin Appelman 2025-09-07 22:35:14 +02:00
commit d936a6049b
237 changed files with 607341 additions and 0 deletions

98
common/Cargo.lock generated Normal file
View file

@ -0,0 +1,98 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "bytes"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "proc-macro2"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
dependencies = [
"unicode-ident",
]
[[package]]
name = "protobuf"
version = "3.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bcc343da15609eaecd65f8aa76df8dc4209d325131d8219358c0aaaebab0bf6"
dependencies = [
"bytes",
"once_cell",
"protobuf-support",
"thiserror",
]
[[package]]
name = "protobuf-support"
version = "3.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0766e3675a627c327e4b3964582594b0e8741305d628a98a5de75a1d15f99b9"
dependencies = [
"thiserror",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "steam-vent-proto-common"
version = "0.5.0"
dependencies = [
"protobuf",
]
[[package]]
name = "syn"
version = "2.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"

12
common/Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "steam-vent-proto-common"
description = "Trait for protobuf structs used by the Steam client protocol"
version = "0.5.0"
edition = "2021"
rust-version = "1.75.0"
authors = ["Robin Appelman <robin@icewind.nl>"]
license = "MIT"
repository = "https://codeberg.org/steam-vent/proto"
[dependencies]
protobuf = { version = "=3.5.1", features = ["with-bytes"] }

105
common/src/lib.rs Normal file
View file

@ -0,0 +1,105 @@
//! Common types for protobufs used by steam-vent
pub use protobuf;
use protobuf::Enum;
use std::fmt::Debug;
use std::io::{Read, Write};
/// Constant used to verify that all proto crates use the same version of the codegen.
pub const VERSION_0_5_0: () = ();
pub trait RpcService {
const SERVICE_NAME: &'static str;
}
/// A protobuf message for an rpc method with associated response
pub trait RpcMethod: protobuf::Message + RpcMessage {
const METHOD_NAME: &'static str;
type Response: RpcMessage;
}
/// A protobuf message send as either request or response
pub trait RpcMessage: Debug + Sized {
fn parse(_reader: &mut dyn Read) -> protobuf::Result<Self>;
fn write(&self, _writer: &mut dyn Write) -> protobuf::Result<()>;
fn encode_size(&self) -> usize;
}
/// An empty message
impl RpcMessage for () {
fn parse(_reader: &mut dyn Read) -> protobuf::Result<Self> {
Ok(())
}
fn write(&self, _writer: &mut dyn Write) -> protobuf::Result<()> {
Ok(())
}
fn encode_size(&self) -> usize {
0
}
}
/// An rpc message with associated kind.
///
/// The associated kind is used to differentiate incoming messages
pub trait RpcMessageWithKind: RpcMessage {
type KindEnum: MsgKindEnum;
const KIND: Self::KindEnum;
}
/// A generic wrapper for "kind" constants used by network messages
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub struct MsgKind(pub i32);
impl MsgKind {
pub fn value(&self) -> i32 {
self.0
}
}
impl From<MsgKind> for i32 {
fn from(value: MsgKind) -> Self {
value.0
}
}
pub const PROTO_MASK: u32 = 0x80000000;
/// An enum containing "kind" constants used by the network messages
///
/// Though it is possible to use the generic [`MsgKind`] struct. Applications shipping their own protobufs
/// are encouraged to create their own enums containing the constants in use for ease of use.
pub trait MsgKindEnum: Enum + Debug {
fn enum_value(&self) -> i32 {
<Self as Enum>::value(self)
}
fn encode_kind(&self, is_protobuf: bool) -> u32 {
if is_protobuf {
self.enum_value() as u32 | PROTO_MASK
} else {
self.enum_value() as u32
}
}
}
impl<T: MsgKindEnum> From<T> for MsgKind {
fn from(value: T) -> Self {
MsgKind(value.enum_value())
}
}
impl<T: MsgKindEnum> PartialEq<T> for MsgKind {
fn eq(&self, other: &T) -> bool {
self.0.eq(&other.enum_value())
}
}
/// Trait for implementing a check for completion of a job that returns a response stream
pub trait JobMultiple {
/// If the job has completed
fn completed(&self) -> bool;
}