-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.go
48 lines (36 loc) · 815 Bytes
/
output.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
package synth
import "reflect"
type Output interface {
Type() string
Initialize(len int)
}
type TypedOutput[T any] struct {
Buffer []T
}
func NewTypedOutput[T any]() *TypedOutput[T] {
return &TypedOutput[T]{
Buffer: []T{},
}
}
func NewUint64Output() *TypedOutput[uint64] {
return NewTypedOutput[uint64]()
}
func NewInt64Output() *TypedOutput[int64] {
return NewTypedOutput[int64]()
}
func NewFloat64Output() *TypedOutput[float64] {
return NewTypedOutput[float64]()
}
func NewBoolOutput() *TypedOutput[bool] {
return NewTypedOutput[bool]()
}
func NewStringOutput() *TypedOutput[string] {
return NewTypedOutput[string]()
}
func (to *TypedOutput[T]) Type() string {
var val T
return reflect.TypeOf(val).String()
}
func (to *TypedOutput[T]) Initialize(len int) {
to.Buffer = make([]T, len)
}