first commit

This commit is contained in:
micialware committed 2026-09-16 10:57:26 +03:00
commit 24818c99e5
5 files changed
+77

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
/target
.idea
Generated
+16
View File
@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "minicbor"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c12b4033ffaa92fbf9df03df38d19324f52bad130dd223f811734a8006dd2d69"
[[package]]
name = "remote_marker"
version = "0.1.0"
dependencies = [
"minicbor",
]
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "remote_marker"
version = "0.1.0"
edition = "2024"
[dependencies]
minicbor = "2.3.0"
+10
View File
@@ -0,0 +1,10 @@
use remote_marker::push;
fn main() {
println!("Hello, world!");
push("stack", 5);
push("stack", 6);
push("stack", 8);
push("stack", 9);
push("stack", 1000);
}
+42
View File
@@ -0,0 +1,42 @@
use minicbor::Encoder;
use std::env;
use std::net::UdpSocket;
use std::str::FromStr;
pub fn push<T: minicbor::Encode<()>>(key: &str, value: T) {
send_with_header("PUSH:", key, value);
}
pub fn set<T: minicbor::Encode<()>>(key: &str, value: T) {
send_with_header("SET:", key, value);
}
fn send_with_header<T: minicbor::Encode<()>>(header: &str, key: &str, value: T) {
if let Some(dest) = env::var("REMOTE_MARKS").ok() {
println!("Sending with header: {}", key);
let header_len = header.len();
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.connect(dest.as_str()).unwrap();
let mut buffer = [0; 1024];
buffer[..header_len].copy_from_slice(header.as_bytes());
let mut enc = Encoder::new(&mut buffer[header_len..]);
enc.begin_array()
.unwrap()
.str_len(key.len() as u64)
.unwrap()
.str(&key)
.unwrap().encode(value).unwrap();
let amount = enc.writer().len();
let encoded = buffer.len() - amount;
println!("Sending {} bytes", encoded);
let sending = &buffer[..encoded];
_ = socket.send(&sending);
}
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {}
}