-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshotjob.go
42 lines (38 loc) · 947 Bytes
/
snapshotjob.go
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
package jobs
import (
"bytes"
"encoding/gob"
)
type SnapshotJob struct {
ID string `json:"id"`
Errored bool `json:"errored"`
Finished bool `json:"finished"`
SnapshotPath string `json:"snapshotpath"`
IP string `json:"ip"`
User string `json:"user"`
Password string `json:"password"`
Port int `json:"port"`
StreamPath string `json:"streampath"`
Sender int `json:"sender"`
}
func EncodeJob(job SnapshotJob) ([]byte, error) {
var encodedJob []byte
var network bytes.Buffer
enc := gob.NewEncoder(&network)
err := enc.Encode(job)
if err != nil {
return encodedJob, err
}
encodedJob = network.Bytes()
return encodedJob, nil
}
func DecodeJob(encoded []byte) (SnapshotJob, error) {
var job SnapshotJob
network := bytes.NewBuffer(encoded)
dec := gob.NewDecoder(network)
err := dec.Decode(&job)
if err != nil {
return SnapshotJob{}, err
}
return job, nil
}