-
Notifications
You must be signed in to change notification settings - Fork 15
/
marshaller.go
37 lines (30 loc) · 953 Bytes
/
marshaller.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
package dingo
var Encode = struct {
// Default marshalling mode
Default int
// JSON marshalling mode
JSON int
// Gob marshalling mode
GOB int
// JSON-Safe marshalling mode
JSONSAFE int
}{
0, 1, 2, 3,
}
/*
Marshaller(s) is the major component between []interface{} and []byte.
- Note: all marshalled []byte should be prefixed with a Header.
- Note: all implemented functions should be routine(thread)-safe.
*/
type Marshaller interface {
// you can perform any preprocessing for every worker function when registered.
Prepare(name string, fn interface{}) (err error)
// Encode a task.
EncodeTask(fn interface{}, task *Task) (b []byte, err error)
// Decode a task.
DecodeTask(h *Header, fn interface{}, b []byte) (task *Task, err error)
// Encode a report.
EncodeReport(fn interface{}, report *Report) (b []byte, err error)
// Decode a report.
DecodeReport(h *Header, fn interface{}, b []byte) (report *Report, err error)
}