DEVELOPMENT ENVIRONMENT

~liljamo/emerwen

ref: 99bece8be8f11baece0ce10934feecb5d0f51863 emerwen/emerwen-master/src/worker.rs -rw-r--r-- 981 bytes
99bece8bJonni Liljamo feat(protocol): init WebToMaster service 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Copyright (C) 2024 Jonni Liljamo <jonni@liljamo.com>
 *
 * This file is licensed under GPL-3.0-or-later, see NOTICE and LICENSE for
 * more information.
 */

use emerwen_protocol::emerwen::shared::Target;
use redb::{TypeName, Value};
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
pub struct Worker {
    pub id: u32,
    pub auth_token: String,
    pub targets: Vec<Target>,
}

impl Value for Worker {
    type SelfType<'a> = Worker;
    type AsBytes<'a> = Vec<u8>;

    fn fixed_width() -> Option<usize> {
        None
    }

    fn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a>
    where
        Self: 'a,
    {
        bincode::deserialize(data).unwrap()
    }

    fn as_bytes<'a, 'b: 'a>(value: &'a Self::SelfType<'b>) -> Self::AsBytes<'a>
    where
        Self: 'a,
        Self: 'b,
    {
        bincode::serialize(value).unwrap()
    }

    fn type_name() -> TypeName {
        TypeName::new("emerwen_master_worker")
    }
}