-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
50 lines (44 loc) · 1014 Bytes
/
job.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
43
44
45
46
47
48
49
50
package types
import (
"bytes"
"encoding/gob"
)
type JobType int
const (
ArtistInfoRetrieval JobType = 1 << iota
RecordInfoRetrieval
JobInfoRetrieval
Die
)
type Job struct {
ID string `json:"id"`
Finished bool `json:"finished"`
Status bool `json:"status"`
Type JobType `json:"type"`
LastOrigin string `json:"lastorigin"`
RequiredOrigin string `json:"requiredorigin"`
Data []byte `json:"data"`
Result []byte `json:"result"`
Error string `json:"error"`
}
func EncodeJob(job Job) ([]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) (Job, error) {
var job Job
network := bytes.NewBuffer(encoded)
dec := gob.NewDecoder(network)
err := dec.Decode(&job)
if err != nil {
return Job{}, err
}
return job, nil
}