github.com/influxdata/influxdb/v2@v2.7.6/influxql/query/point.gen.go (about)

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