github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/thrift/generic/option.go (about) 1 /** 2 * Copyright 2023 CloudWeGo Authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package generic 18 19 import "unsafe" 20 21 const ( 22 sizePathNode = unsafe.Sizeof(PathNode{}) 23 ) 24 25 var ( 26 // UseNativeSkipForGet indicates to use native.Skip (instead of go.Skip) method to skip thrift value 27 // This only works for single-value searching API like GetByInt()/GetByRaw()/GetByStr()/Field()/Index()/GetByPath() methods. 28 // WARN: this will promote performance when thrift value to be skipped is large, but may decrease preformance when thrift value is small. 29 UseNativeSkipForGet = false 30 31 // DefaultNodeSliceCap is the default capacity of a Node or NodePath slice 32 // Usually, a Node or NodePath slice is used to store intermediate or consequential elements of a generic API like Children()|Interface()|SetMany() 33 DefaultNodeSliceCap = 16 34 ) 35 36 // Opions for generic.Node 37 type Options struct { 38 // DisallowUnknow indicates to report error when read unknown fields. 39 DisallowUnknow bool 40 41 // WriteDefault indicates to write value if a DEFAULT requireness field is not set. 42 WriteDefault bool 43 44 // NoCheckRequireNess indicates not to check requiredness when writing. 45 NotCheckRequireNess bool 46 47 // UseNativeSkip indicates to use native.Skip (instead of go.Skip) method to skip thrift value 48 // WARNING: this will promote performance when thrift value to be skipped is large, but may decrease preformance when thrift value is small. 49 UseNativeSkip bool 50 51 // MapStructById indicates to use FieldId instead of int as map key instead of when call Node.Interface() on STRUCT type. 52 MapStructById bool 53 54 // CastStringAsBinary indicates to cast STRING type to []byte when call Node.Interface()/Map(). 55 CastStringAsBinary bool 56 57 // NotScanParentNode indicates to only assign children node when PathNode.Load()/Node.Children. 58 // Thies will promote performance but may be misued when handle PathNode. 59 NotScanParentNode bool 60 61 // ClearDirtyValues indicates one multi-query (includeing 62 // Fields()/GetMany()/Gets()/Indexies()) to clear out all nodes 63 // in passed []PathNode first 64 ClearDirtyValues bool 65 66 // StoreChildrenById indicates to store children node by id when call Node.Children() or PathNode.Load(). 67 // When field id exceeds StoreChildrenByIdShreshold, children node will be stored sequentially after the threshold. 68 StoreChildrenById bool 69 70 // StoreChildrenByHash indicates to store children node by str hash (mod parent's size) when call Node.Children() or PathNode.Load(). 71 StoreChildrenByHash bool 72 73 // IterateStructByName indicates `Value.Foreach()` API to pass PathFieldName instead of PathFieldId to handler. 74 IterateStructByName bool 75 76 // DescriptorToPathNodeArraySize indicates initial array size for API `DescriptorToPathNode` 77 DescriptorToPathNodeArraySize int 78 79 // DescriptorToPathNodeArraySize indicates initial map size for API `DescriptorToPathNode` 80 DescriptorToPathNodeMapSize int 81 82 // DescriptorToPathNodeMaxDepth indicates max recurse limits (>0) for API `DescriptorToPathNode` 83 DescriptorToPathNodeMaxDepth int 84 85 // DescriptorToPathNodeWriteOptional indicates writing empty value for optional fields for API `DescriptorToPathNode` 86 DescriptorToPathNodeWriteOptional bool 87 88 // DescriptorToPathNodeWriteDefualt indicates writing empty value for default fields for API `DescriptorToPathNode` 89 DescriptorToPathNodeWriteDefualt bool 90 91 // SliceAsSet indicates `NewNodeAny()` to covert go slice to SET instead of LIST 92 SliceAsSet bool 93 } 94 95 var ( 96 // StoreChildrenByIdShreshold is the maximum id to store children node by id. 97 StoreChildrenByIdShreshold = 256 98 99 // StoreChildrenByIdShreshold is the minimum id to store children node by hash. 100 StoreChildrenByIntHashShreshold = DefaultNodeSliceCap 101 102 // DefaultNodeBufferSize indicates every element buffer size for one complex-type Node, 103 // including `NewNodeList()\NewNodeSet()\NewNodeMap()\NewNodeStruct()\NewNodeAny()` 104 DefaultNodeBufferSize = 64 105 )