@@ -507,54 +507,74 @@ private static int WriteExemplar(byte[] buffer, int writePosition, in Exemplar e
507
507
508
508
private static int WriteHistogramBuckets ( byte [ ] buffer , int writePosition , HistogramBuckets buckets )
509
509
{
510
- const int Fixed64Size = 8 ;
510
+ writePosition = WriteBucketCounts ( buffer , writePosition , buckets . BucketCounts ) ;
511
511
512
- int length = buckets . BucketCounts . Length ;
512
+ writePosition = WriteExplicitBounds ( buffer , writePosition , buckets . ExplicitBounds ! ) ;
513
513
514
- writePosition = ProtobufSerializer . WriteTagAndLength (
515
- buffer ,
516
- writePosition ,
517
- length * Fixed64Size ,
518
- ProtobufOtlpMetricFieldNumberConstants . HistogramDataPoint_Bucket_Counts ,
519
- ProtobufWireType . LEN ) ;
514
+ return writePosition ;
520
515
521
- for ( int i = 0 ; i < length ; i ++ )
516
+ static int WriteBucketCounts ( byte [ ] buffer , int writePosition , HistogramBuckets . HistogramBucketValues [ ] values )
522
517
{
523
- writePosition = ProtobufSerializer . WriteFixed64LittleEndianFormat (
518
+ int length = values . Length ;
519
+
520
+ writePosition = WritePackedLength (
524
521
buffer ,
525
522
writePosition ,
526
- ( ulong ) buckets . BucketCounts [ i ] . SnapshotValue ) ;
527
- }
528
-
529
- length = 0 ;
523
+ length ,
524
+ ProtobufOtlpMetricFieldNumberConstants . HistogramDataPoint_Bucket_Counts ) ;
530
525
531
- for ( int i = 0 ; i < buckets . ExplicitBounds ! . Length ; i ++ )
532
- {
533
- if ( buckets . ExplicitBounds [ i ] != double . PositiveInfinity )
526
+ for ( int i = 0 ; i < length ; i ++ )
534
527
{
535
- length ++ ;
528
+ writePosition = ProtobufSerializer . WriteFixed64LittleEndianFormat (
529
+ buffer ,
530
+ writePosition ,
531
+ ( ulong ) values [ i ] . SnapshotValue ) ;
536
532
}
533
+
534
+ return writePosition ;
537
535
}
538
536
539
- if ( length > 0 )
537
+ static int WriteExplicitBounds ( byte [ ] buffer , int writePosition , double [ ] values )
540
538
{
541
- writePosition = ProtobufSerializer . WriteTagAndLength (
542
- buffer ,
543
- writePosition ,
544
- length * Fixed64Size ,
545
- ProtobufOtlpMetricFieldNumberConstants . HistogramDataPoint_Explicit_Bounds ,
546
- ProtobufWireType . LEN ) ;
539
+ int length = 0 ;
540
+
541
+ for ( int i = 0 ; i < values . Length ; i ++ )
542
+ {
543
+ if ( values [ i ] != double . PositiveInfinity )
544
+ {
545
+ length ++ ;
546
+ }
547
+ }
547
548
548
- for ( int i = 0 ; i < buckets . ExplicitBounds ! . Length ; i ++ )
549
+ if ( length > 0 )
549
550
{
550
- var value = buckets . ExplicitBounds [ i ] ;
551
- if ( value != double . PositiveInfinity )
551
+ writePosition = WritePackedLength (
552
+ buffer ,
553
+ writePosition ,
554
+ length ,
555
+ ProtobufOtlpMetricFieldNumberConstants . HistogramDataPoint_Explicit_Bounds ) ;
556
+
557
+ for ( int i = 0 ; i < values . Length ; i ++ )
552
558
{
553
- writePosition = ProtobufSerializer . WriteDouble ( buffer , writePosition , value ) ;
559
+ var value = values [ i ] ;
560
+ if ( value != double . PositiveInfinity )
561
+ {
562
+ writePosition = ProtobufSerializer . WriteDouble ( buffer , writePosition , value ) ;
563
+ }
554
564
}
555
565
}
566
+
567
+ return writePosition ;
556
568
}
557
569
558
- return writePosition ;
570
+ static int WritePackedLength ( byte [ ] buffer , int writePosition , int length , int fieldNumber )
571
+ {
572
+ return ProtobufSerializer . WriteTagAndLength (
573
+ buffer ,
574
+ writePosition ,
575
+ length * 8 ,
576
+ ProtobufOtlpMetricFieldNumberConstants . HistogramDataPoint_Bucket_Counts ,
577
+ ProtobufWireType . LEN ) ;
578
+ }
559
579
}
560
580
}
0 commit comments