github.com/m3db/m3@v1.5.0/src/x/serialize/types.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package serialize 22 23 import ( 24 "github.com/m3db/m3/src/dbnode/x/xpool" 25 "github.com/m3db/m3/src/metrics/metric/id" 26 "github.com/m3db/m3/src/x/checked" 27 "github.com/m3db/m3/src/x/ident" 28 ) 29 30 const ( 31 // HeaderMagicNumber is an internal header used to denote the beginning of 32 // an encoded stream. 33 HeaderMagicNumber uint16 = 10101 34 ) 35 36 // TagEncoder encodes provided Tag iterators. 37 type TagEncoder interface { 38 // Encode encodes the provided iterator into its internal byte stream. 39 // NB: leaves the original iterator un-modified. 40 Encode(ident.TagIterator) error 41 42 // Data returns the encoded bytes. 43 // NB: The bytes returned as still owned by the TagEncoder. i.e. They are 44 // only safe for use until Reset/Finalize is called upon the original 45 // TagEncoder. 46 Data() (checked.Bytes, bool) 47 48 // Reset resets the internal state to allow reuse of the encoder. 49 Reset() 50 51 // Finalize releases any held resources. 52 Finalize() 53 } 54 55 // TagEncoderPool pools TagEncoders. 56 type TagEncoderPool interface { 57 // Init initializes the pool. 58 Init() 59 60 // Get returns an encoder. NB: calling Finalize() on the 61 // returned TagEncoder puts it back in the pool. 62 Get() TagEncoder 63 64 // Put puts the encoder back in the pool. 65 Put(TagEncoder) 66 } 67 68 // TagDecoder decodes an encoded byte stream to a TagIterator. 69 type TagDecoder interface { 70 ident.TagIterator 71 72 // Reset resets internal state to iterate over the provided bytes. 73 // NB: the TagDecoder takes ownership of the provided checked.Bytes. 74 Reset(checked.Bytes) 75 } 76 77 // TagDecoderPool pools TagDecoders. 78 type TagDecoderPool interface { 79 // Init initializes the pool. 80 Init() 81 82 // Get returns a decoder. NB: calling Finalize() on the 83 // returned TagDecoder puts it back in the pool. 84 Get() TagDecoder 85 86 // Put puts the decoder back in the pool. 87 Put(TagDecoder) 88 } 89 90 // TagEncoderOptions sets the knobs for TagEncoder limits. 91 type TagEncoderOptions interface { 92 // SetInitialCapacity sets the initial capacity of the bytes underlying 93 // the TagEncoder. 94 SetInitialCapacity(v int) TagEncoderOptions 95 96 // InitialCapacity returns the initial capacity of the bytes underlying 97 // the TagEncoder. 98 InitialCapacity() int 99 100 // SetTagSerializationLimits sets the TagSerializationLimits. 101 SetTagSerializationLimits(v TagSerializationLimits) TagEncoderOptions 102 103 // TagSerializationLimits returns the TagSerializationLimits. 104 TagSerializationLimits() TagSerializationLimits 105 } 106 107 // TagDecoderOptions sets the knobs for TagDecoders. 108 type TagDecoderOptions interface { 109 // SetCheckedBytesWrapperPool sets the checked.Bytes wrapper pool. 110 SetCheckedBytesWrapperPool(v xpool.CheckedBytesWrapperPool) TagDecoderOptions 111 112 // CheckedBytesWrapperPool returns the checked.Bytes wrapper pool. 113 CheckedBytesWrapperPool() xpool.CheckedBytesWrapperPool 114 115 // SetTagSerializationLimits sets the TagSerializationLimits. 116 SetTagSerializationLimits(v TagSerializationLimits) TagDecoderOptions 117 118 // TagSerializationLimits returns the TagSerializationLimits. 119 TagSerializationLimits() TagSerializationLimits 120 } 121 122 // TagSerializationLimits sets the limits around tag serialization. 123 type TagSerializationLimits interface { 124 // SetMaxNumberTags sets the maximum number of tags allowed. 125 SetMaxNumberTags(uint16) TagSerializationLimits 126 127 // MaxNumberTags returns the maximum number of tags allowed. 128 MaxNumberTags() uint16 129 130 // SetMaxTagLiteralLength sets the maximum length of a tag Name/Value. 131 SetMaxTagLiteralLength(uint16) TagSerializationLimits 132 133 // MaxTagLiteralLength returns the maximum length of a tag Name/Value. 134 MaxTagLiteralLength() uint16 135 } 136 137 // MetricTagsIterator iterates over a set of tags. 138 type MetricTagsIterator interface { 139 id.ID 140 id.SortedTagIterator 141 NumTags() int 142 } 143 144 // MetricTagsIteratorPool pools MetricTagsIterator. 145 type MetricTagsIteratorPool interface { 146 Init() 147 Get() MetricTagsIterator 148 Put(iter MetricTagsIterator) 149 }