-
Notifications
You must be signed in to change notification settings - Fork 3
/
signalling.go
42 lines (34 loc) · 1013 Bytes
/
signalling.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 y3
import (
"fmt"
)
// signal is builder for PrimitivePacketEncoder
type signal struct {
encoder *PrimitivePacketEncoder
}
// createSignal create a signal
func createSignal(key byte) *signal {
return &signal{encoder: NewPrimitivePacketEncoder(int(key))}
}
// SetString set a string Value for the signal
func (s *signal) SetString(v string) *signal {
s.encoder.SetStringValue(v)
return s
}
// SetString set a int64 Value for the signal
func (s *signal) SetInt64(v int64) *signal {
s.encoder.SetInt64Value(v)
return s
}
// SetString set a float64 Value for the signal
func (s *signal) SetFloat64(v float64) *signal {
s.encoder.SetFloat64Value(v)
return s
}
// ToEncoder return current PrimitivePacketEncoder, and checking legality
func (s *signal) ToEncoder(allow func(key byte) bool) *PrimitivePacketEncoder {
if allow != nil && !allow(byte(s.encoder.seqID)) {
panic(fmt.Errorf("it is not allowed to use this key to create a signal: %#x", byte(s.encoder.seqID)))
}
return s.encoder
}