Debian Codegraph @

dstream/gen/dechunk.tmpl

raw
1 package dstream
2
3 import (
4 "fmt"
5 "time"
6 )
7
8 // Dechunk combines all chunks into a single chunk.
9 func Dechunk(source Dstream) Dstream {
10
11 // Use the first chunk to get started
12 if !source.Next() {
13 msg := "Can't read from stream"
14 panic(msg)
15 }
16
17 names := source.Names()
18 nvar := source.NumVar()
19 data := make([][]interface{}, nvar)
20 for j := 0; j<nvar; j++ {
21 // The result has only one chunk
22 data[j] = make([]interface{}, 1)
23 }
24
25 for {
26 for j := 0; j < nvar; j++ {
27 x := source.GetPos(j)
28 switch x := x.(type) {
29 {{- range . }}
30 case []{{ .Type }}:
31 var z []{{ .Type }}
32 if data[j][0] != nil {
33 z = data[j][0].([]{{ .Type }})
34 }
35 data[j][0] = append(z, x...)
36 {{- end }}
37 default:
38 panic(fmt.Sprintf("Type %T is not known\n", x))
39 }
40 }
41 if !source.Next() {
42 break
43 }
44 }
45
46 return NewFromArrays(data, names)
47 }