github.com/iDigitalFlame/xmt@v0.5.4/cmd/list_base.go (about) 1 // Copyright (C) 2020 - 2023 iDigitalFlame 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 // 16 17 package cmd 18 19 import "github.com/iDigitalFlame/xmt/data" 20 21 // ProcessInfo is a struct that holds simple process related data for extraction 22 // This struct is returned via a call to 'Processes'. 23 // 24 // This struct also supports binary Marshaling/UnMarshaling. 25 type ProcessInfo struct { 26 _ [0]func() 27 Name, User string 28 PID, PPID uint32 29 } 30 31 // MarshalStream transforms this struct into a binary format and writes to the 32 // supplied data.Writer. 33 func (p ProcessInfo) MarshalStream(w data.Writer) error { 34 if err := w.WriteUint32(p.PID); err != nil { 35 return err 36 } 37 if err := w.WriteUint32(p.PPID); err != nil { 38 return err 39 } 40 if err := w.WriteString(p.Name); err != nil { 41 return err 42 } 43 return w.WriteString(p.User) 44 } 45 46 // UnmarshalStream transforms this struct from a binary format that is read from 47 // the supplied data.Reader. 48 func (p *ProcessInfo) UnmarshalStream(r data.Reader) error { 49 if err := r.ReadUint32(&p.PID); err != nil { 50 return err 51 } 52 if err := r.ReadUint32(&p.PPID); err != nil { 53 return err 54 } 55 if err := r.ReadString(&p.Name); err != nil { 56 return err 57 } 58 return r.ReadString(&p.User) 59 }