-
Notifications
You must be signed in to change notification settings - Fork 495
/
trickle.go
55 lines (50 loc) · 1.05 KB
/
trickle.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
51
52
53
54
55
package pipeline
import (
"encoding/json"
"fmt"
)
// A node that converts from batchedges to streamedges.
// Example:
//
// var errors = stream
// |from()
// |trickle()
//
// Children of trickle will be treated as if they are in a stream.
type TrickleNode struct {
chainnode `json:"-"`
}
func newTrickleNode() *TrickleNode {
return &TrickleNode{
chainnode: newBasicChainNode("trickle", BatchEdge, StreamEdge),
}
}
// MarshalJSON converts TrickleNode to JSON
// tick:ignore
func (n *TrickleNode) MarshalJSON() ([]byte, error) {
var raw = &struct {
TypeOf
}{
TypeOf: TypeOf{
Type: "trickle",
ID: n.ID(),
},
}
return json.Marshal(raw)
}
// UnmarshalJSON converts JSON to an TrickleNode
// tick:ignore
func (n *TrickleNode) UnmarshalJSON(data []byte) error {
var raw = &struct {
TypeOf
}{}
err := json.Unmarshal(data, raw)
if err != nil {
return err
}
if raw.Type != "trickle" {
return fmt.Errorf("error unmarshaling node %d of type %s as TrickleNode", raw.ID, raw.Type)
}
n.setID(raw.ID)
return nil
}