github.com/cloudwego/frugal@v0.1.15/internal/binary/encoder/state.go (about)

     1  /*
     2   * Copyright 2022 ByteDance Inc.
     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 encoder
    18  
    19  import (
    20      `math`
    21      `unsafe`
    22  
    23      `github.com/cloudwego/frugal/internal/binary/defs`
    24      `github.com/cloudwego/frugal/internal/rt`
    25  )
    26  
    27  const (
    28      LnOffset = int64(unsafe.Offsetof(StateItem{}.Ln))
    29      MiOffset = int64(unsafe.Offsetof(StateItem{}.Mi))
    30      WpOffset = int64(unsafe.Offsetof(StateItem{}.Wp))
    31      BmOffset = int64(unsafe.Offsetof(RuntimeState{}.Bm))
    32  )
    33  
    34  const (
    35      MiKeyOffset   = int64(unsafe.Offsetof(rt.GoMapIterator{}.K))
    36      MiValueOffset = int64(unsafe.Offsetof(rt.GoMapIterator{}.V))
    37  )
    38  
    39  const (
    40      StateMax  = (defs.StackSize - 1) * StateSize
    41      StateSize = int64(unsafe.Sizeof(StateItem{}))
    42  )
    43  
    44  const (
    45      RangeUint8  = math.MaxUint8 + 1
    46      RangeUint16 = math.MaxUint16 + 1
    47  )
    48  
    49  type StateItem struct {
    50      Ln uintptr
    51      Wp unsafe.Pointer
    52      Mi rt.GoMapIterator
    53  }
    54  
    55  type RuntimeState struct {
    56      St  [defs.StackSize]StateItem    // Must be the first field.
    57      Bm  [1024]uint64                 // Bitmap, used for uniqueness check of set<i8> and set<i16>.
    58      Val unsafe.Pointer               // Pointer to the object to be encoded
    59  }