github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/proto/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{}) // not used
    23  )
    24  
    25  var (
    26  	// UseNativeSkipForGet indicates to use native.Skip (instead of go.Skip) method to skip proto value
    27  	// This only works for single-value searching API like GetByInt()/GetByRaw()/GetByStr()/Field()/Index()/GetByPath() methods.
    28  	UseNativeSkipForGet = false
    29  
    30  	// DefaultNodeSliceCap is the default capacity of a Node or NodePath slice
    31  	// Usually, a Node or NodePath slice is used to store intermediate or consequential elements of a generic API like Children()|Interface()|SetMany()
    32  	DefaultNodeSliceCap = 16
    33  	DefaultTagSliceCap  = 8
    34  )
    35  
    36  // Opions for generic.Node
    37  type Options struct {
    38  	// DisallowUnknown indicates to report error when read unknown fields.
    39  	DisallowUnknown bool
    40  
    41  	// MapStructById indicates to use FieldId instead of int as map key instead of when call Node.Interface() on STRUCT type.
    42  	MapStructById bool
    43  
    44  	// ClearDirtyValues indicates one multi-query (includeing
    45  	// Fields()/GetMany()/Gets()/Indexies()) to clear out all nodes
    46  	// in passed []PathNode first
    47  	ClearDirtyValues bool
    48  
    49  	// CastStringAsBinary indicates to cast STRING type to []byte when call Node.Interface()/Map().
    50  	CastStringAsBinary bool
    51  
    52  	WriteDefault bool // not implemented
    53  
    54  	UseNativeSkip bool // not implemented
    55  
    56  	NotScanParentNode bool // not implemented
    57  
    58  	StoreChildrenById bool // not implemented
    59  
    60  	StoreChildrenByHash bool // not implemented
    61  
    62  	IterateStructByName bool // not implemented
    63  }
    64  
    65  var (
    66  	// StoreChildrenByIdShreshold is the maximum id to store children node by id.
    67  	StoreChildrenByIdShreshold  = 256
    68  
    69  	// StoreChildrenByIdShreshold is the minimum id to store children node by hash.
    70  	StoreChildrenByIntHashShreshold = DefaultNodeSliceCap
    71  )
    72