1// Generated by tmpl 2// https://github.com/benbjohnson/tmpl 3// 4// DO NOT EDIT! 5// Source: point.gen.go.tmpl 6 7package query 8 9import ( 10 "context" 11 "encoding/binary" 12 "io" 13 14 "github.com/gogo/protobuf/proto" 15 internal "github.com/influxdata/influxdb/query/internal" 16) 17 18// FloatPoint represents a point with a float64 value. 19// DO NOT ADD ADDITIONAL FIELDS TO THIS STRUCT. 20// See TestPoint_Fields in influxql/point_test.go for more details. 21type FloatPoint struct { 22 Name string 23 Tags Tags 24 25 Time int64 26 Value float64 27 Aux []interface{} 28 29 // Total number of points that were combined into this point from an aggregate. 30 // If this is zero, the point is not the result of an aggregate function. 31 Aggregated uint32 32 Nil bool 33} 34 35func (v *FloatPoint) name() string { return v.Name } 36func (v *FloatPoint) tags() Tags { return v.Tags } 37func (v *FloatPoint) time() int64 { return v.Time } 38func (v *FloatPoint) nil() bool { return v.Nil } 39func (v *FloatPoint) value() interface{} { 40 if v.Nil { 41 return nil 42 } 43 return v.Value 44} 45func (v *FloatPoint) aux() []interface{} { return v.Aux } 46 47// Clone returns a copy of v. 48func (v *FloatPoint) Clone() *FloatPoint { 49 if v == nil { 50 return nil 51 } 52 53 other := *v 54 if v.Aux != nil { 55 other.Aux = make([]interface{}, len(v.Aux)) 56 copy(other.Aux, v.Aux) 57 } 58 59 return &other 60} 61 62// CopyTo makes a deep copy into the point. 63func (v *FloatPoint) CopyTo(other *FloatPoint) { 64 other.Name, other.Tags = v.Name, v.Tags 65 other.Time = v.Time 66 other.Value, other.Nil = v.Value, v.Nil 67 if v.Aux != nil { 68 if len(other.Aux) != len(v.Aux) { 69 other.Aux = make([]interface{}, len(v.Aux)) 70 } 71 copy(other.Aux, v.Aux) 72 } 73} 74 75func encodeFloatPoint(p *FloatPoint) *internal.Point { 76 return &internal.Point{ 77 Name: proto.String(p.Name), 78 Tags: proto.String(p.Tags.ID()), 79 Time: proto.Int64(p.Time), 80 Nil: proto.Bool(p.Nil), 81 Aux: encodeAux(p.Aux), 82 Aggregated: proto.Uint32(p.Aggregated), 83 84 FloatValue: proto.Float64(p.Value), 85 } 86} 87 88func decodeFloatPoint(pb *internal.Point) *FloatPoint { 89 return &FloatPoint{ 90 Name: pb.GetName(), 91 Tags: newTagsID(pb.GetTags()), 92 Time: pb.GetTime(), 93 Nil: pb.GetNil(), 94 Aux: decodeAux(pb.Aux), 95 Aggregated: pb.GetAggregated(), 96 Value: pb.GetFloatValue(), 97 } 98} 99 100// floatPoints represents a slice of points sortable by value. 101type floatPoints []FloatPoint 102 103func (a floatPoints) Len() int { return len(a) } 104func (a floatPoints) Less(i, j int) bool { 105 if a[i].Time != a[j].Time { 106 return a[i].Time < a[j].Time 107 } 108 return a[i].Value < a[j].Value 109} 110func (a floatPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 111 112// floatPointsByValue represents a slice of points sortable by value. 113type floatPointsByValue []FloatPoint 114 115func (a floatPointsByValue) Len() int { return len(a) } 116 117func (a floatPointsByValue) Less(i, j int) bool { return a[i].Value < a[j].Value } 118 119func (a floatPointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 120 121// floatPointsByTime represents a slice of points sortable by value. 122type floatPointsByTime []FloatPoint 123 124func (a floatPointsByTime) Len() int { return len(a) } 125func (a floatPointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } 126func (a floatPointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 127 128// floatPointByFunc represents a slice of points sortable by a function. 129type floatPointsByFunc struct { 130 points []FloatPoint 131 cmp func(a, b *FloatPoint) bool 132} 133 134func (a *floatPointsByFunc) Len() int { return len(a.points) } 135func (a *floatPointsByFunc) Less(i, j int) bool { return a.cmp(&a.points[i], &a.points[j]) } 136func (a *floatPointsByFunc) Swap(i, j int) { a.points[i], a.points[j] = a.points[j], a.points[i] } 137 138func (a *floatPointsByFunc) Push(x interface{}) { 139 a.points = append(a.points, x.(FloatPoint)) 140} 141 142func (a *floatPointsByFunc) Pop() interface{} { 143 p := a.points[len(a.points)-1] 144 a.points = a.points[:len(a.points)-1] 145 return p 146} 147 148func floatPointsSortBy(points []FloatPoint, cmp func(a, b *FloatPoint) bool) *floatPointsByFunc { 149 return &floatPointsByFunc{ 150 points: points, 151 cmp: cmp, 152 } 153} 154 155// FloatPointEncoder encodes FloatPoint points to a writer. 156type FloatPointEncoder struct { 157 w io.Writer 158} 159 160// NewFloatPointEncoder returns a new instance of FloatPointEncoder that writes to w. 161func NewFloatPointEncoder(w io.Writer) *FloatPointEncoder { 162 return &FloatPointEncoder{w: w} 163} 164 165// EncodeFloatPoint marshals and writes p to the underlying writer. 166func (enc *FloatPointEncoder) EncodeFloatPoint(p *FloatPoint) error { 167 // Marshal to bytes. 168 buf, err := proto.Marshal(encodeFloatPoint(p)) 169 if err != nil { 170 return err 171 } 172 173 // Write the length. 174 if err := binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { 175 return err 176 } 177 178 // Write the encoded point. 179 if _, err := enc.w.Write(buf); err != nil { 180 return err 181 } 182 return nil 183} 184 185// FloatPointDecoder decodes FloatPoint points from a reader. 186type FloatPointDecoder struct { 187 r io.Reader 188 stats IteratorStats 189 ctx context.Context 190} 191 192// NewFloatPointDecoder returns a new instance of FloatPointDecoder that reads from r. 193func NewFloatPointDecoder(ctx context.Context, r io.Reader) *FloatPointDecoder { 194 return &FloatPointDecoder{r: r, ctx: ctx} 195} 196 197// Stats returns iterator stats embedded within the stream. 198func (dec *FloatPointDecoder) Stats() IteratorStats { return dec.stats } 199 200// DecodeFloatPoint reads from the underlying reader and unmarshals into p. 201func (dec *FloatPointDecoder) DecodeFloatPoint(p *FloatPoint) error { 202 for { 203 // Read length. 204 var sz uint32 205 if err := binary.Read(dec.r, binary.BigEndian, &sz); err != nil { 206 return err 207 } 208 209 // Read point data. 210 buf := make([]byte, sz) 211 if _, err := io.ReadFull(dec.r, buf); err != nil { 212 return err 213 } 214 215 // Unmarshal into point. 216 var pb internal.Point 217 if err := proto.Unmarshal(buf, &pb); err != nil { 218 return err 219 } 220 221 // If the point contains stats then read stats and retry. 222 if pb.Stats != nil { 223 dec.stats = decodeIteratorStats(pb.Stats) 224 continue 225 } 226 227 if len(pb.Trace) > 0 { 228 var err error 229 err = decodeIteratorTrace(dec.ctx, pb.Trace) 230 if err != nil { 231 return err 232 } 233 continue 234 } 235 236 // Decode into point object. 237 *p = *decodeFloatPoint(&pb) 238 239 return nil 240 } 241} 242 243// IntegerPoint represents a point with a int64 value. 244// DO NOT ADD ADDITIONAL FIELDS TO THIS STRUCT. 245// See TestPoint_Fields in influxql/point_test.go for more details. 246type IntegerPoint struct { 247 Name string 248 Tags Tags 249 250 Time int64 251 Value int64 252 Aux []interface{} 253 254 // Total number of points that were combined into this point from an aggregate. 255 // If this is zero, the point is not the result of an aggregate function. 256 Aggregated uint32 257 Nil bool 258} 259 260func (v *IntegerPoint) name() string { return v.Name } 261func (v *IntegerPoint) tags() Tags { return v.Tags } 262func (v *IntegerPoint) time() int64 { return v.Time } 263func (v *IntegerPoint) nil() bool { return v.Nil } 264func (v *IntegerPoint) value() interface{} { 265 if v.Nil { 266 return nil 267 } 268 return v.Value 269} 270func (v *IntegerPoint) aux() []interface{} { return v.Aux } 271 272// Clone returns a copy of v. 273func (v *IntegerPoint) Clone() *IntegerPoint { 274 if v == nil { 275 return nil 276 } 277 278 other := *v 279 if v.Aux != nil { 280 other.Aux = make([]interface{}, len(v.Aux)) 281 copy(other.Aux, v.Aux) 282 } 283 284 return &other 285} 286 287// CopyTo makes a deep copy into the point. 288func (v *IntegerPoint) CopyTo(other *IntegerPoint) { 289 other.Name, other.Tags = v.Name, v.Tags 290 other.Time = v.Time 291 other.Value, other.Nil = v.Value, v.Nil 292 if v.Aux != nil { 293 if len(other.Aux) != len(v.Aux) { 294 other.Aux = make([]interface{}, len(v.Aux)) 295 } 296 copy(other.Aux, v.Aux) 297 } 298} 299 300func encodeIntegerPoint(p *IntegerPoint) *internal.Point { 301 return &internal.Point{ 302 Name: proto.String(p.Name), 303 Tags: proto.String(p.Tags.ID()), 304 Time: proto.Int64(p.Time), 305 Nil: proto.Bool(p.Nil), 306 Aux: encodeAux(p.Aux), 307 Aggregated: proto.Uint32(p.Aggregated), 308 309 IntegerValue: proto.Int64(p.Value), 310 } 311} 312 313func decodeIntegerPoint(pb *internal.Point) *IntegerPoint { 314 return &IntegerPoint{ 315 Name: pb.GetName(), 316 Tags: newTagsID(pb.GetTags()), 317 Time: pb.GetTime(), 318 Nil: pb.GetNil(), 319 Aux: decodeAux(pb.Aux), 320 Aggregated: pb.GetAggregated(), 321 Value: pb.GetIntegerValue(), 322 } 323} 324 325// integerPoints represents a slice of points sortable by value. 326type integerPoints []IntegerPoint 327 328func (a integerPoints) Len() int { return len(a) } 329func (a integerPoints) Less(i, j int) bool { 330 if a[i].Time != a[j].Time { 331 return a[i].Time < a[j].Time 332 } 333 return a[i].Value < a[j].Value 334} 335func (a integerPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 336 337// integerPointsByValue represents a slice of points sortable by value. 338type integerPointsByValue []IntegerPoint 339 340func (a integerPointsByValue) Len() int { return len(a) } 341 342func (a integerPointsByValue) Less(i, j int) bool { return a[i].Value < a[j].Value } 343 344func (a integerPointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 345 346// integerPointsByTime represents a slice of points sortable by value. 347type integerPointsByTime []IntegerPoint 348 349func (a integerPointsByTime) Len() int { return len(a) } 350func (a integerPointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } 351func (a integerPointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 352 353// integerPointByFunc represents a slice of points sortable by a function. 354type integerPointsByFunc struct { 355 points []IntegerPoint 356 cmp func(a, b *IntegerPoint) bool 357} 358 359func (a *integerPointsByFunc) Len() int { return len(a.points) } 360func (a *integerPointsByFunc) Less(i, j int) bool { return a.cmp(&a.points[i], &a.points[j]) } 361func (a *integerPointsByFunc) Swap(i, j int) { a.points[i], a.points[j] = a.points[j], a.points[i] } 362 363func (a *integerPointsByFunc) Push(x interface{}) { 364 a.points = append(a.points, x.(IntegerPoint)) 365} 366 367func (a *integerPointsByFunc) Pop() interface{} { 368 p := a.points[len(a.points)-1] 369 a.points = a.points[:len(a.points)-1] 370 return p 371} 372 373func integerPointsSortBy(points []IntegerPoint, cmp func(a, b *IntegerPoint) bool) *integerPointsByFunc { 374 return &integerPointsByFunc{ 375 points: points, 376 cmp: cmp, 377 } 378} 379 380// IntegerPointEncoder encodes IntegerPoint points to a writer. 381type IntegerPointEncoder struct { 382 w io.Writer 383} 384 385// NewIntegerPointEncoder returns a new instance of IntegerPointEncoder that writes to w. 386func NewIntegerPointEncoder(w io.Writer) *IntegerPointEncoder { 387 return &IntegerPointEncoder{w: w} 388} 389 390// EncodeIntegerPoint marshals and writes p to the underlying writer. 391func (enc *IntegerPointEncoder) EncodeIntegerPoint(p *IntegerPoint) error { 392 // Marshal to bytes. 393 buf, err := proto.Marshal(encodeIntegerPoint(p)) 394 if err != nil { 395 return err 396 } 397 398 // Write the length. 399 if err := binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { 400 return err 401 } 402 403 // Write the encoded point. 404 if _, err := enc.w.Write(buf); err != nil { 405 return err 406 } 407 return nil 408} 409 410// IntegerPointDecoder decodes IntegerPoint points from a reader. 411type IntegerPointDecoder struct { 412 r io.Reader 413 stats IteratorStats 414 ctx context.Context 415} 416 417// NewIntegerPointDecoder returns a new instance of IntegerPointDecoder that reads from r. 418func NewIntegerPointDecoder(ctx context.Context, r io.Reader) *IntegerPointDecoder { 419 return &IntegerPointDecoder{r: r, ctx: ctx} 420} 421 422// Stats returns iterator stats embedded within the stream. 423func (dec *IntegerPointDecoder) Stats() IteratorStats { return dec.stats } 424 425// DecodeIntegerPoint reads from the underlying reader and unmarshals into p. 426func (dec *IntegerPointDecoder) DecodeIntegerPoint(p *IntegerPoint) error { 427 for { 428 // Read length. 429 var sz uint32 430 if err := binary.Read(dec.r, binary.BigEndian, &sz); err != nil { 431 return err 432 } 433 434 // Read point data. 435 buf := make([]byte, sz) 436 if _, err := io.ReadFull(dec.r, buf); err != nil { 437 return err 438 } 439 440 // Unmarshal into point. 441 var pb internal.Point 442 if err := proto.Unmarshal(buf, &pb); err != nil { 443 return err 444 } 445 446 // If the point contains stats then read stats and retry. 447 if pb.Stats != nil { 448 dec.stats = decodeIteratorStats(pb.Stats) 449 continue 450 } 451 452 if len(pb.Trace) > 0 { 453 var err error 454 err = decodeIteratorTrace(dec.ctx, pb.Trace) 455 if err != nil { 456 return err 457 } 458 continue 459 } 460 461 // Decode into point object. 462 *p = *decodeIntegerPoint(&pb) 463 464 return nil 465 } 466} 467 468// UnsignedPoint represents a point with a uint64 value. 469// DO NOT ADD ADDITIONAL FIELDS TO THIS STRUCT. 470// See TestPoint_Fields in influxql/point_test.go for more details. 471type UnsignedPoint struct { 472 Name string 473 Tags Tags 474 475 Time int64 476 Value uint64 477 Aux []interface{} 478 479 // Total number of points that were combined into this point from an aggregate. 480 // If this is zero, the point is not the result of an aggregate function. 481 Aggregated uint32 482 Nil bool 483} 484 485func (v *UnsignedPoint) name() string { return v.Name } 486func (v *UnsignedPoint) tags() Tags { return v.Tags } 487func (v *UnsignedPoint) time() int64 { return v.Time } 488func (v *UnsignedPoint) nil() bool { return v.Nil } 489func (v *UnsignedPoint) value() interface{} { 490 if v.Nil { 491 return nil 492 } 493 return v.Value 494} 495func (v *UnsignedPoint) aux() []interface{} { return v.Aux } 496 497// Clone returns a copy of v. 498func (v *UnsignedPoint) Clone() *UnsignedPoint { 499 if v == nil { 500 return nil 501 } 502 503 other := *v 504 if v.Aux != nil { 505 other.Aux = make([]interface{}, len(v.Aux)) 506 copy(other.Aux, v.Aux) 507 } 508 509 return &other 510} 511 512// CopyTo makes a deep copy into the point. 513func (v *UnsignedPoint) CopyTo(other *UnsignedPoint) { 514 other.Name, other.Tags = v.Name, v.Tags 515 other.Time = v.Time 516 other.Value, other.Nil = v.Value, v.Nil 517 if v.Aux != nil { 518 if len(other.Aux) != len(v.Aux) { 519 other.Aux = make([]interface{}, len(v.Aux)) 520 } 521 copy(other.Aux, v.Aux) 522 } 523} 524 525func encodeUnsignedPoint(p *UnsignedPoint) *internal.Point { 526 return &internal.Point{ 527 Name: proto.String(p.Name), 528 Tags: proto.String(p.Tags.ID()), 529 Time: proto.Int64(p.Time), 530 Nil: proto.Bool(p.Nil), 531 Aux: encodeAux(p.Aux), 532 Aggregated: proto.Uint32(p.Aggregated), 533 } 534} 535 536func decodeUnsignedPoint(pb *internal.Point) *UnsignedPoint { 537 return &UnsignedPoint{ 538 Name: pb.GetName(), 539 Tags: newTagsID(pb.GetTags()), 540 Time: pb.GetTime(), 541 Nil: pb.GetNil(), 542 Aux: decodeAux(pb.Aux), 543 Aggregated: pb.GetAggregated(), 544 Value: pb.GetUnsignedValue(), 545 } 546} 547 548// unsignedPoints represents a slice of points sortable by value. 549type unsignedPoints []UnsignedPoint 550 551func (a unsignedPoints) Len() int { return len(a) } 552func (a unsignedPoints) Less(i, j int) bool { 553 if a[i].Time != a[j].Time { 554 return a[i].Time < a[j].Time 555 } 556 return a[i].Value < a[j].Value 557} 558func (a unsignedPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 559 560// unsignedPointsByValue represents a slice of points sortable by value. 561type unsignedPointsByValue []UnsignedPoint 562 563func (a unsignedPointsByValue) Len() int { return len(a) } 564 565func (a unsignedPointsByValue) Less(i, j int) bool { return a[i].Value < a[j].Value } 566 567func (a unsignedPointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 568 569// unsignedPointsByTime represents a slice of points sortable by value. 570type unsignedPointsByTime []UnsignedPoint 571 572func (a unsignedPointsByTime) Len() int { return len(a) } 573func (a unsignedPointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } 574func (a unsignedPointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 575 576// unsignedPointByFunc represents a slice of points sortable by a function. 577type unsignedPointsByFunc struct { 578 points []UnsignedPoint 579 cmp func(a, b *UnsignedPoint) bool 580} 581 582func (a *unsignedPointsByFunc) Len() int { return len(a.points) } 583func (a *unsignedPointsByFunc) Less(i, j int) bool { return a.cmp(&a.points[i], &a.points[j]) } 584func (a *unsignedPointsByFunc) Swap(i, j int) { a.points[i], a.points[j] = a.points[j], a.points[i] } 585 586func (a *unsignedPointsByFunc) Push(x interface{}) { 587 a.points = append(a.points, x.(UnsignedPoint)) 588} 589 590func (a *unsignedPointsByFunc) Pop() interface{} { 591 p := a.points[len(a.points)-1] 592 a.points = a.points[:len(a.points)-1] 593 return p 594} 595 596func unsignedPointsSortBy(points []UnsignedPoint, cmp func(a, b *UnsignedPoint) bool) *unsignedPointsByFunc { 597 return &unsignedPointsByFunc{ 598 points: points, 599 cmp: cmp, 600 } 601} 602 603// UnsignedPointEncoder encodes UnsignedPoint points to a writer. 604type UnsignedPointEncoder struct { 605 w io.Writer 606} 607 608// NewUnsignedPointEncoder returns a new instance of UnsignedPointEncoder that writes to w. 609func NewUnsignedPointEncoder(w io.Writer) *UnsignedPointEncoder { 610 return &UnsignedPointEncoder{w: w} 611} 612 613// EncodeUnsignedPoint marshals and writes p to the underlying writer. 614func (enc *UnsignedPointEncoder) EncodeUnsignedPoint(p *UnsignedPoint) error { 615 // Marshal to bytes. 616 buf, err := proto.Marshal(encodeUnsignedPoint(p)) 617 if err != nil { 618 return err 619 } 620 621 // Write the length. 622 if err := binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { 623 return err 624 } 625 626 // Write the encoded point. 627 if _, err := enc.w.Write(buf); err != nil { 628 return err 629 } 630 return nil 631} 632 633// UnsignedPointDecoder decodes UnsignedPoint points from a reader. 634type UnsignedPointDecoder struct { 635 r io.Reader 636 stats IteratorStats 637 ctx context.Context 638} 639 640// NewUnsignedPointDecoder returns a new instance of UnsignedPointDecoder that reads from r. 641func NewUnsignedPointDecoder(ctx context.Context, r io.Reader) *UnsignedPointDecoder { 642 return &UnsignedPointDecoder{r: r, ctx: ctx} 643} 644 645// Stats returns iterator stats embedded within the stream. 646func (dec *UnsignedPointDecoder) Stats() IteratorStats { return dec.stats } 647 648// DecodeUnsignedPoint reads from the underlying reader and unmarshals into p. 649func (dec *UnsignedPointDecoder) DecodeUnsignedPoint(p *UnsignedPoint) error { 650 for { 651 // Read length. 652 var sz uint32 653 if err := binary.Read(dec.r, binary.BigEndian, &sz); err != nil { 654 return err 655 } 656 657 // Read point data. 658 buf := make([]byte, sz) 659 if _, err := io.ReadFull(dec.r, buf); err != nil { 660 return err 661 } 662 663 // Unmarshal into point. 664 var pb internal.Point 665 if err := proto.Unmarshal(buf, &pb); err != nil { 666 return err 667 } 668 669 // If the point contains stats then read stats and retry. 670 if pb.Stats != nil { 671 dec.stats = decodeIteratorStats(pb.Stats) 672 continue 673 } 674 675 if len(pb.Trace) > 0 { 676 var err error 677 err = decodeIteratorTrace(dec.ctx, pb.Trace) 678 if err != nil { 679 return err 680 } 681 continue 682 } 683 684 // Decode into point object. 685 *p = *decodeUnsignedPoint(&pb) 686 687 return nil 688 } 689} 690 691// StringPoint represents a point with a string value. 692// DO NOT ADD ADDITIONAL FIELDS TO THIS STRUCT. 693// See TestPoint_Fields in influxql/point_test.go for more details. 694type StringPoint struct { 695 Name string 696 Tags Tags 697 698 Time int64 699 Value string 700 Aux []interface{} 701 702 // Total number of points that were combined into this point from an aggregate. 703 // If this is zero, the point is not the result of an aggregate function. 704 Aggregated uint32 705 Nil bool 706} 707 708func (v *StringPoint) name() string { return v.Name } 709func (v *StringPoint) tags() Tags { return v.Tags } 710func (v *StringPoint) time() int64 { return v.Time } 711func (v *StringPoint) nil() bool { return v.Nil } 712func (v *StringPoint) value() interface{} { 713 if v.Nil { 714 return nil 715 } 716 return v.Value 717} 718func (v *StringPoint) aux() []interface{} { return v.Aux } 719 720// Clone returns a copy of v. 721func (v *StringPoint) Clone() *StringPoint { 722 if v == nil { 723 return nil 724 } 725 726 other := *v 727 if v.Aux != nil { 728 other.Aux = make([]interface{}, len(v.Aux)) 729 copy(other.Aux, v.Aux) 730 } 731 732 return &other 733} 734 735// CopyTo makes a deep copy into the point. 736func (v *StringPoint) CopyTo(other *StringPoint) { 737 other.Name, other.Tags = v.Name, v.Tags 738 other.Time = v.Time 739 other.Value, other.Nil = v.Value, v.Nil 740 if v.Aux != nil { 741 if len(other.Aux) != len(v.Aux) { 742 other.Aux = make([]interface{}, len(v.Aux)) 743 } 744 copy(other.Aux, v.Aux) 745 } 746} 747 748func encodeStringPoint(p *StringPoint) *internal.Point { 749 return &internal.Point{ 750 Name: proto.String(p.Name), 751 Tags: proto.String(p.Tags.ID()), 752 Time: proto.Int64(p.Time), 753 Nil: proto.Bool(p.Nil), 754 Aux: encodeAux(p.Aux), 755 Aggregated: proto.Uint32(p.Aggregated), 756 757 StringValue: proto.String(p.Value), 758 } 759} 760 761func decodeStringPoint(pb *internal.Point) *StringPoint { 762 return &StringPoint{ 763 Name: pb.GetName(), 764 Tags: newTagsID(pb.GetTags()), 765 Time: pb.GetTime(), 766 Nil: pb.GetNil(), 767 Aux: decodeAux(pb.Aux), 768 Aggregated: pb.GetAggregated(), 769 Value: pb.GetStringValue(), 770 } 771} 772 773// stringPoints represents a slice of points sortable by value. 774type stringPoints []StringPoint 775 776func (a stringPoints) Len() int { return len(a) } 777func (a stringPoints) Less(i, j int) bool { 778 if a[i].Time != a[j].Time { 779 return a[i].Time < a[j].Time 780 } 781 return a[i].Value < a[j].Value 782} 783func (a stringPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 784 785// stringPointsByValue represents a slice of points sortable by value. 786type stringPointsByValue []StringPoint 787 788func (a stringPointsByValue) Len() int { return len(a) } 789 790func (a stringPointsByValue) Less(i, j int) bool { return a[i].Value < a[j].Value } 791 792func (a stringPointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 793 794// stringPointsByTime represents a slice of points sortable by value. 795type stringPointsByTime []StringPoint 796 797func (a stringPointsByTime) Len() int { return len(a) } 798func (a stringPointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } 799func (a stringPointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 800 801// stringPointByFunc represents a slice of points sortable by a function. 802type stringPointsByFunc struct { 803 points []StringPoint 804 cmp func(a, b *StringPoint) bool 805} 806 807func (a *stringPointsByFunc) Len() int { return len(a.points) } 808func (a *stringPointsByFunc) Less(i, j int) bool { return a.cmp(&a.points[i], &a.points[j]) } 809func (a *stringPointsByFunc) Swap(i, j int) { a.points[i], a.points[j] = a.points[j], a.points[i] } 810 811func (a *stringPointsByFunc) Push(x interface{}) { 812 a.points = append(a.points, x.(StringPoint)) 813} 814 815func (a *stringPointsByFunc) Pop() interface{} { 816 p := a.points[len(a.points)-1] 817 a.points = a.points[:len(a.points)-1] 818 return p 819} 820 821func stringPointsSortBy(points []StringPoint, cmp func(a, b *StringPoint) bool) *stringPointsByFunc { 822 return &stringPointsByFunc{ 823 points: points, 824 cmp: cmp, 825 } 826} 827 828// StringPointEncoder encodes StringPoint points to a writer. 829type StringPointEncoder struct { 830 w io.Writer 831} 832 833// NewStringPointEncoder returns a new instance of StringPointEncoder that writes to w. 834func NewStringPointEncoder(w io.Writer) *StringPointEncoder { 835 return &StringPointEncoder{w: w} 836} 837 838// EncodeStringPoint marshals and writes p to the underlying writer. 839func (enc *StringPointEncoder) EncodeStringPoint(p *StringPoint) error { 840 // Marshal to bytes. 841 buf, err := proto.Marshal(encodeStringPoint(p)) 842 if err != nil { 843 return err 844 } 845 846 // Write the length. 847 if err := binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { 848 return err 849 } 850 851 // Write the encoded point. 852 if _, err := enc.w.Write(buf); err != nil { 853 return err 854 } 855 return nil 856} 857 858// StringPointDecoder decodes StringPoint points from a reader. 859type StringPointDecoder struct { 860 r io.Reader 861 stats IteratorStats 862 ctx context.Context 863} 864 865// NewStringPointDecoder returns a new instance of StringPointDecoder that reads from r. 866func NewStringPointDecoder(ctx context.Context, r io.Reader) *StringPointDecoder { 867 return &StringPointDecoder{r: r, ctx: ctx} 868} 869 870// Stats returns iterator stats embedded within the stream. 871func (dec *StringPointDecoder) Stats() IteratorStats { return dec.stats } 872 873// DecodeStringPoint reads from the underlying reader and unmarshals into p. 874func (dec *StringPointDecoder) DecodeStringPoint(p *StringPoint) error { 875 for { 876 // Read length. 877 var sz uint32 878 if err := binary.Read(dec.r, binary.BigEndian, &sz); err != nil { 879 return err 880 } 881 882 // Read point data. 883 buf := make([]byte, sz) 884 if _, err := io.ReadFull(dec.r, buf); err != nil { 885 return err 886 } 887 888 // Unmarshal into point. 889 var pb internal.Point 890 if err := proto.Unmarshal(buf, &pb); err != nil { 891 return err 892 } 893 894 // If the point contains stats then read stats and retry. 895 if pb.Stats != nil { 896 dec.stats = decodeIteratorStats(pb.Stats) 897 continue 898 } 899 900 if len(pb.Trace) > 0 { 901 var err error 902 err = decodeIteratorTrace(dec.ctx, pb.Trace) 903 if err != nil { 904 return err 905 } 906 continue 907 } 908 909 // Decode into point object. 910 *p = *decodeStringPoint(&pb) 911 912 return nil 913 } 914} 915 916// BooleanPoint represents a point with a bool value. 917// DO NOT ADD ADDITIONAL FIELDS TO THIS STRUCT. 918// See TestPoint_Fields in influxql/point_test.go for more details. 919type BooleanPoint struct { 920 Name string 921 Tags Tags 922 923 Time int64 924 Value bool 925 Aux []interface{} 926 927 // Total number of points that were combined into this point from an aggregate. 928 // If this is zero, the point is not the result of an aggregate function. 929 Aggregated uint32 930 Nil bool 931} 932 933func (v *BooleanPoint) name() string { return v.Name } 934func (v *BooleanPoint) tags() Tags { return v.Tags } 935func (v *BooleanPoint) time() int64 { return v.Time } 936func (v *BooleanPoint) nil() bool { return v.Nil } 937func (v *BooleanPoint) value() interface{} { 938 if v.Nil { 939 return nil 940 } 941 return v.Value 942} 943func (v *BooleanPoint) aux() []interface{} { return v.Aux } 944 945// Clone returns a copy of v. 946func (v *BooleanPoint) Clone() *BooleanPoint { 947 if v == nil { 948 return nil 949 } 950 951 other := *v 952 if v.Aux != nil { 953 other.Aux = make([]interface{}, len(v.Aux)) 954 copy(other.Aux, v.Aux) 955 } 956 957 return &other 958} 959 960// CopyTo makes a deep copy into the point. 961func (v *BooleanPoint) CopyTo(other *BooleanPoint) { 962 other.Name, other.Tags = v.Name, v.Tags 963 other.Time = v.Time 964 other.Value, other.Nil = v.Value, v.Nil 965 if v.Aux != nil { 966 if len(other.Aux) != len(v.Aux) { 967 other.Aux = make([]interface{}, len(v.Aux)) 968 } 969 copy(other.Aux, v.Aux) 970 } 971} 972 973func encodeBooleanPoint(p *BooleanPoint) *internal.Point { 974 return &internal.Point{ 975 Name: proto.String(p.Name), 976 Tags: proto.String(p.Tags.ID()), 977 Time: proto.Int64(p.Time), 978 Nil: proto.Bool(p.Nil), 979 Aux: encodeAux(p.Aux), 980 Aggregated: proto.Uint32(p.Aggregated), 981 982 BooleanValue: proto.Bool(p.Value), 983 } 984} 985 986func decodeBooleanPoint(pb *internal.Point) *BooleanPoint { 987 return &BooleanPoint{ 988 Name: pb.GetName(), 989 Tags: newTagsID(pb.GetTags()), 990 Time: pb.GetTime(), 991 Nil: pb.GetNil(), 992 Aux: decodeAux(pb.Aux), 993 Aggregated: pb.GetAggregated(), 994 Value: pb.GetBooleanValue(), 995 } 996} 997 998// booleanPoints represents a slice of points sortable by value. 999type booleanPoints []BooleanPoint 1000 1001func (a booleanPoints) Len() int { return len(a) } 1002func (a booleanPoints) Less(i, j int) bool { 1003 if a[i].Time != a[j].Time { 1004 return a[i].Time < a[j].Time 1005 } 1006 return !a[i].Value 1007} 1008func (a booleanPoints) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 1009 1010// booleanPointsByValue represents a slice of points sortable by value. 1011type booleanPointsByValue []BooleanPoint 1012 1013func (a booleanPointsByValue) Len() int { return len(a) } 1014 1015func (a booleanPointsByValue) Less(i, j int) bool { return !a[i].Value } 1016 1017func (a booleanPointsByValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 1018 1019// booleanPointsByTime represents a slice of points sortable by value. 1020type booleanPointsByTime []BooleanPoint 1021 1022func (a booleanPointsByTime) Len() int { return len(a) } 1023func (a booleanPointsByTime) Less(i, j int) bool { return a[i].Time < a[j].Time } 1024func (a booleanPointsByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 1025 1026// booleanPointByFunc represents a slice of points sortable by a function. 1027type booleanPointsByFunc struct { 1028 points []BooleanPoint 1029 cmp func(a, b *BooleanPoint) bool 1030} 1031 1032func (a *booleanPointsByFunc) Len() int { return len(a.points) } 1033func (a *booleanPointsByFunc) Less(i, j int) bool { return a.cmp(&a.points[i], &a.points[j]) } 1034func (a *booleanPointsByFunc) Swap(i, j int) { a.points[i], a.points[j] = a.points[j], a.points[i] } 1035 1036func (a *booleanPointsByFunc) Push(x interface{}) { 1037 a.points = append(a.points, x.(BooleanPoint)) 1038} 1039 1040func (a *booleanPointsByFunc) Pop() interface{} { 1041 p := a.points[len(a.points)-1] 1042 a.points = a.points[:len(a.points)-1] 1043 return p 1044} 1045 1046func booleanPointsSortBy(points []BooleanPoint, cmp func(a, b *BooleanPoint) bool) *booleanPointsByFunc { 1047 return &booleanPointsByFunc{ 1048 points: points, 1049 cmp: cmp, 1050 } 1051} 1052 1053// BooleanPointEncoder encodes BooleanPoint points to a writer. 1054type BooleanPointEncoder struct { 1055 w io.Writer 1056} 1057 1058// NewBooleanPointEncoder returns a new instance of BooleanPointEncoder that writes to w. 1059func NewBooleanPointEncoder(w io.Writer) *BooleanPointEncoder { 1060 return &BooleanPointEncoder{w: w} 1061} 1062 1063// EncodeBooleanPoint marshals and writes p to the underlying writer. 1064func (enc *BooleanPointEncoder) EncodeBooleanPoint(p *BooleanPoint) error { 1065 // Marshal to bytes. 1066 buf, err := proto.Marshal(encodeBooleanPoint(p)) 1067 if err != nil { 1068 return err 1069 } 1070 1071 // Write the length. 1072 if err := binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { 1073 return err 1074 } 1075 1076 // Write the encoded point. 1077 if _, err := enc.w.Write(buf); err != nil { 1078 return err 1079 } 1080 return nil 1081} 1082 1083// BooleanPointDecoder decodes BooleanPoint points from a reader. 1084type BooleanPointDecoder struct { 1085 r io.Reader 1086 stats IteratorStats 1087 ctx context.Context 1088} 1089 1090// NewBooleanPointDecoder returns a new instance of BooleanPointDecoder that reads from r. 1091func NewBooleanPointDecoder(ctx context.Context, r io.Reader) *BooleanPointDecoder { 1092 return &BooleanPointDecoder{r: r, ctx: ctx} 1093} 1094 1095// Stats returns iterator stats embedded within the stream. 1096func (dec *BooleanPointDecoder) Stats() IteratorStats { return dec.stats } 1097 1098// DecodeBooleanPoint reads from the underlying reader and unmarshals into p. 1099func (dec *BooleanPointDecoder) DecodeBooleanPoint(p *BooleanPoint) error { 1100 for { 1101 // Read length. 1102 var sz uint32 1103 if err := binary.Read(dec.r, binary.BigEndian, &sz); err != nil { 1104 return err 1105 } 1106 1107 // Read point data. 1108 buf := make([]byte, sz) 1109 if _, err := io.ReadFull(dec.r, buf); err != nil { 1110 return err 1111 } 1112 1113 // Unmarshal into point. 1114 var pb internal.Point 1115 if err := proto.Unmarshal(buf, &pb); err != nil { 1116 return err 1117 } 1118 1119 // If the point contains stats then read stats and retry. 1120 if pb.Stats != nil { 1121 dec.stats = decodeIteratorStats(pb.Stats) 1122 continue 1123 } 1124 1125 if len(pb.Trace) > 0 { 1126 var err error 1127 err = decodeIteratorTrace(dec.ctx, pb.Trace) 1128 if err != nil { 1129 return err 1130 } 1131 continue 1132 } 1133 1134 // Decode into point object. 1135 *p = *decodeBooleanPoint(&pb) 1136 1137 return nil 1138 } 1139} 1140