github.com/go-graphite/carbonapi@v0.17.0/intervalset/intervalset.go (about) 1 package intervalset 2 3 // Copy paste from https://github.com/lomik/go-carbon/blob/master/carbonserver/pickle.go 4 // Original license: MIT 5 // Original author: Roman Lomonosov 6 7 import ( 8 "encoding/binary" 9 "math" 10 ) 11 12 // Fake single interval set for graphite 13 type IntervalSet struct { 14 Start int32 15 End int32 16 } 17 18 func (i *IntervalSet) MarshalPickle() ([]byte, error) { 19 // 0: ( MARK 20 // 1: c GLOBAL 'graphite.intervals IntervalSet' 21 // 33: o OBJ (MARK at 0) 22 // 34: } EMPTY_DICT 23 // 35: ( MARK 24 // 36: U SHORT_BINSTRING 'intervals' 25 // 47: ] EMPTY_LIST 26 // 48: ( MARK 27 // 49: c GLOBAL 'graphite.intervals Interval' 28 // 78: o OBJ (MARK at 48) 29 // 79: } EMPTY_DICT 30 // 80: ( MARK 31 // 81: U SHORT_BINSTRING 'start' 32 // 88: G BINFLOAT 1322087998.393128 33 // 97: U SHORT_BINSTRING 'size' 34 // 103: G BINFLOAT 157679977.1475761 35 // 112: U SHORT_BINSTRING 'end' 36 // 117: G BINFLOAT 1479767975.540704 37 // 126: U SHORT_BINSTRING 'tuple' 38 // 133: G BINFLOAT 1322087998.393128 39 // 142: G BINFLOAT 1479767975.540704 40 // 151: \x86 TUPLE2 41 // 152: u SETITEMS (MARK at 80) 42 // 153: b BUILD 43 // 154: a APPEND 44 // 155: U SHORT_BINSTRING 'size' 45 // 161: G BINFLOAT 157679977.1475761 46 // 170: u SETITEMS (MARK at 35) 47 // 171: b BUILD 48 // 172: . STOP 49 b := []byte("(cgraphite.intervals\nIntervalSet\no}(U\tintervals](cgraphite.intervals\nInterval\no}(U\x05startGA\xd3\xb3]\x8f\x99)\x02U\x04sizeGA\xa2\xcc\x02\xd2K\x8f\x18U\x03endGA\xd6\x0c\xdd\xe9\xe2\x9a\xe5U\x05tupleGA\xd3\xb3]\x8f\x99)\x02GA\xd6\x0c\xdd\xe9\xe2\x9a\xe5\x86ubaU\x04sizeGA\xa2\xcc\x02\xd2K\x8f\x18ub") 50 51 binary.BigEndian.PutUint64(b[89:97], math.Float64bits(float64(i.Start))) 52 binary.BigEndian.PutUint64(b[104:112], math.Float64bits(float64(i.End-i.Start))) 53 binary.BigEndian.PutUint64(b[118:126], math.Float64bits(float64(i.End))) 54 binary.BigEndian.PutUint64(b[134:142], math.Float64bits(float64(i.Start))) 55 binary.BigEndian.PutUint64(b[143:151], math.Float64bits(float64(i.End))) 56 binary.BigEndian.PutUint64(b[162:170], math.Float64bits(float64(i.End-i.Start))) 57 58 return b, nil 59 }