github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/persist/fs/msgpack/options.go (about) 1 // Copyright (c) 2016 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 msgpack 22 23 import "github.com/m3db/m3/src/dbnode/persist/schema" 24 25 // DecodingOptions provides a set of options for decoding data. 26 type DecodingOptions interface { 27 // SetAllocDecodedBytes sets whether we allocate new space when decoding 28 // a byte slice. 29 SetAllocDecodedBytes(value bool) DecodingOptions 30 31 // AllocDecodedBytes determines whether we allocate new space when decoding 32 // a byte slice. 33 AllocDecodedBytes() bool 34 35 // SetIndexEntryHasher sets the indexEntryHasher method for this decoder. 36 SetIndexEntryHasher(value schema.IndexEntryHasher) DecodingOptions 37 38 // IndexEntryHasher returns the IndexEntryHasher for this decoder. 39 IndexEntryHasher() schema.IndexEntryHasher 40 } 41 42 const ( 43 defaultAllocDecodedBytes = false 44 ) 45 46 type decodingOptions struct { 47 allocDecodedBytes bool 48 indexEntryHasher schema.IndexEntryHasher 49 } 50 51 // NewDecodingOptions creates a new set of decoding options. 52 func NewDecodingOptions() DecodingOptions { 53 return &decodingOptions{ 54 allocDecodedBytes: defaultAllocDecodedBytes, 55 indexEntryHasher: schema.NewXXHasher(), 56 } 57 } 58 59 func (o *decodingOptions) SetAllocDecodedBytes(value bool) DecodingOptions { 60 opts := *o 61 opts.allocDecodedBytes = value 62 return &opts 63 } 64 65 func (o *decodingOptions) AllocDecodedBytes() bool { 66 return o.allocDecodedBytes 67 } 68 69 func (o *decodingOptions) SetIndexEntryHasher(value schema.IndexEntryHasher) DecodingOptions { 70 opts := *o 71 opts.indexEntryHasher = value 72 return &opts 73 } 74 75 func (o *decodingOptions) IndexEntryHasher() schema.IndexEntryHasher { 76 return o.indexEntryHasher 77 }