github.com/influxdata/influxdb/v2@v2.7.6/influxql/query/point.gen.go.tmpl (about) 1 package query 2 3 //lint:file-ignore U1000 Ignore all unused code, it's generated 4 5 import ( 6 "context" 7 "encoding/binary" 8 "io" 9 10 internal "github.com/influxdata/influxdb/v2/influxql/query/internal" 11 "google.golang.org/protobuf/proto" 12 ) 13 14 {{range .}} 15 16 // {{.Name}}Point represents a point with a {{.Type}} value. 17 // DO NOT ADD ADDITIONAL FIELDS TO THIS STRUCT. 18 // See TestPoint_Fields in influxql/point_test.go for more details. 19 type {{.Name}}Point struct { 20 Name string 21 Tags Tags 22 23 Time int64 24 Value {{.Type}} 25 Aux []interface{} 26 27 // Total number of points that were combined into this point from an aggregate. 28 // If this is zero, the point is not the result of an aggregate function. 29 Aggregated uint32 30 Nil bool 31 } 32 33 func (v *{{.Name}}Point) name() string { return v.Name } 34 func (v *{{.Name}}Point) tags() Tags { return v.Tags } 35 func (v *{{.Name}}Point) time() int64 { return v.Time } 36 func (v *{{.Name}}Point) nil() bool { return v.Nil } 37 func (v *{{.Name}}Point) value() interface{} { 38 if v.Nil { 39 return nil 40 } 41 return v.Value 42 } 43 func (v *{{.Name}}Point) aux() []interface{} { return v.Aux } 44 45 // Clone returns a copy of v. 46 func (v *{{.Name}}Point) Clone() *{{.Name}}Point { 47 if v == nil { 48 return nil 49 } 50 51 other := *v 52 if v.Aux != nil { 53 other.Aux = make([]interface{}, len(v.Aux)) 54 copy(other.Aux, v.Aux) 55 } 56 57 return &other 58 } 59 60 // CopyTo makes a deep copy into the point. 61 func (v *{{.Name}}Point) CopyTo(other *{{.Name}}Point) { 62 other.Name, other.Tags = v.Name, v.Tags 63 other.Time = v.Time 64 other.Value, other.Nil = v.Value, v.Nil 65 if v.Aux != nil { 66 if len(other.Aux) != len(v.Aux) { 67 other.Aux = make([]interface{}, len(v.Aux)) 68 } 69 copy(other.Aux, v.Aux) 70 } 71 } 72 73 func encode{{.Name}}Point(p *{{.Name}}Point) *internal.Point { 74 return &internal.Point{ 75 Name: proto.String(p.Name), 76 Tags: proto.String(p.Tags.ID()), 77 Time: proto.Int64(p.Time), 78 Nil: proto.Bool(p.Nil), 79 Aux: encodeAux(p.Aux), 80 Aggregated: proto.Uint32(p.Aggregated), 81 82 {{if eq .Name "Float"}} 83 FloatValue: proto.Float64(p.Value), 84 {{else if eq .Name "Integer"}} 85 IntegerValue: proto.Int64(p.Value), 86 {{else if eq .Name "String"}} 87 StringValue: proto.String(p.Value), 88 {{else if eq .Name "Boolean"}} 89 BooleanValue: proto.Bool(p.Value), 90 {{end}} 91 } 92 } 93 94 func decode{{.Name}}Point(pb *internal.Point) *{{.Name}}Point { 95 return &{{.Name}}Point{ 96 Name: pb.GetName(), 97 Tags: newTagsID(pb.GetTags()), 98 Time: pb.GetTime(), 99 Nil: pb.GetNil(), 100 Aux: decodeAux(pb.Aux), 101 Aggregated: pb.GetAggregated(), 102 Value: pb.Get{{.Name}}Value(), 103 } 104 } 105 106 // {{.name}}Points represents a slice of points sortable by value. 107 type {{.name}}Points []{{.Name}}Point 108 109 func (a {{.name}}Points) Len() int { return len(a) } 110 func (a {{.name}}Points) Less(i, j int) bool { 111 if a[i].Time != a[j].Time { 112 return a[i].Time < a[j].Time 113 } 114 return {{if ne .Name "Boolean"}}a[i].Value < a[j].Value{{else}}!a[i].Value{{end}} 115 } 116 func (a {{.name}}Points) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 117 118 // {{.name}}PointsByValue represents a slice of points sortable by value. 119 type {{.name}}PointsByValue []{{.Name}}Point 120 121 func (a {{.name}}PointsByValue) Len() int { return len(a) } 122 {{if eq .Name "Boolean"}} 123 func (a {{.name}}PointsByValue) Less(i, j int) bool { return !a[i].Value } 124 {{else}} 125 func (a {{.name}}PointsByValue) Less(i, j int) bool { return a[i].Value < a[j].Value } 126 {{end}} 127 func (a {{.name}}PointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 128 129 // {{.name}}PointsByTime represents a slice of points sortable by value. 130 type {{.name}}PointsByTime []{{.Name}}Point 131 132 func (a {{.name}}PointsByTime) Len() int { return len(a) } 133 func (a {{.name}}PointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } 134 func (a {{.name}}PointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 135 136 // {{.name}}PointByFunc represents a slice of points sortable by a function. 137 type {{.name}}PointsByFunc struct { 138 points []{{.Name}}Point 139 cmp func(a, b *{{.Name}}Point) bool 140 } 141 142 func (a *{{.name}}PointsByFunc) Len() int { return len(a.points) } 143 func (a *{{.name}}PointsByFunc) Less(i, j int) bool { return a.cmp(&a.points[i], &a.points[j]) } 144 func (a *{{.name}}PointsByFunc) Swap(i, j int) { a.points[i], a.points[j] = a.points[j], a.points[i] } 145 146 func (a *{{.name}}PointsByFunc) Push(x interface{}) { 147 a.points = append(a.points, x.({{.Name}}Point)) 148 } 149 150 func (a *{{.name}}PointsByFunc) Pop() interface{} { 151 p := a.points[len(a.points)-1] 152 a.points = a.points[:len(a.points)-1] 153 return p 154 } 155 156 func {{.name}}PointsSortBy(points []{{.Name}}Point, cmp func(a, b *{{.Name}}Point) bool) *{{.name}}PointsByFunc { 157 return &{{.name}}PointsByFunc{ 158 points: points, 159 cmp: cmp, 160 } 161 } 162 163 // {{.Name}}PointEncoder encodes {{.Name}}Point points to a writer. 164 type {{.Name}}PointEncoder struct { 165 w io.Writer 166 } 167 168 // New{{.Name}}PointEncoder returns a new instance of {{.Name}}PointEncoder that writes to w. 169 func New{{.Name}}PointEncoder(w io.Writer) *{{.Name}}PointEncoder { 170 return &{{.Name}}PointEncoder{w: w} 171 } 172 173 // Encode{{.Name}}Point marshals and writes p to the underlying writer. 174 func (enc *{{.Name}}PointEncoder) Encode{{.Name}}Point(p *{{.Name}}Point) error { 175 // Marshal to bytes. 176 buf, err := proto.Marshal(encode{{.Name}}Point(p)) 177 if err != nil { 178 return err 179 } 180 181 // Write the length. 182 if err := binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { 183 return err 184 } 185 186 // Write the encoded point. 187 if _, err := enc.w.Write(buf); err != nil { 188 return err 189 } 190 return nil 191 } 192 193 194 // {{.Name}}PointDecoder decodes {{.Name}}Point points from a reader. 195 type {{.Name}}PointDecoder struct { 196 r io.Reader 197 stats IteratorStats 198 ctx context.Context 199 } 200 201 // New{{.Name}}PointDecoder returns a new instance of {{.Name}}PointDecoder that reads from r. 202 func New{{.Name}}PointDecoder(ctx context.Context, r io.Reader) *{{.Name}}PointDecoder { 203 return &{{.Name}}PointDecoder{r: r, ctx: ctx} 204 } 205 206 // Stats returns iterator stats embedded within the stream. 207 func (dec *{{.Name}}PointDecoder) Stats() IteratorStats { return dec.stats } 208 209 // Decode{{.Name}}Point reads from the underlying reader and unmarshals into p. 210 func (dec *{{.Name}}PointDecoder) Decode{{.Name}}Point(p *{{.Name}}Point) error { 211 for { 212 // Read length. 213 var sz uint32 214 if err := binary.Read(dec.r, binary.BigEndian, &sz); err != nil { 215 return err 216 } 217 218 // Read point data. 219 buf := make([]byte, sz) 220 if _, err := io.ReadFull(dec.r, buf); err != nil { 221 return err 222 } 223 224 // Unmarshal into point. 225 var pb internal.Point 226 if err := proto.Unmarshal(buf, &pb); err != nil { 227 return err 228 } 229 230 // If the point contains stats then read stats and retry. 231 if pb.Stats != nil { 232 dec.stats = decodeIteratorStats(pb.Stats) 233 continue 234 } 235 236 // Decode into point object. 237 *p = *decode{{.Name}}Point(&pb) 238 239 return nil 240 } 241 } 242 243 {{end}}