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
46
47
48
49
50
51
52
53
54
55
56
57
use std::io::{Cursor, Read, Seek, SeekFrom};
use byteorder::ReadBytesExt;
use crate::{utils::read_utf8_string, ReaderError};
use super::Name;
use serde::Serialize;
#[derive(Debug, Serialize)]
pub struct NetworkLocationShellItem {
pub location: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub comments: Option<String>
}
impl NetworkLocationShellItem {
pub fn from_buffer(buf: &[u8]) -> Result<Self, ReaderError>{
Self::from_reader(&mut Cursor::new(buf))
}
pub fn from_reader<R: Read + Seek>(r: &mut R) -> Result<Self, ReaderError>{
let _class_type = r.read_u8()?; let mut description = None;
let mut comments = None;
r.seek(SeekFrom::Current(1))?;
let flags = r.read_u8()?;
let location = read_utf8_string(r, None)?;
if flags & 0x80 > 0 {
description = Some(read_utf8_string(r, None)?);
}
if flags & 0x40 > 0 {
comments = Some(read_utf8_string(r, None)?);
}
Ok(
Self {
location,
description,
comments
}
)
}
}
impl Name for NetworkLocationShellItem {
fn name(&self) -> String {
format!("{:?}",&self.location)
}
}