github.com/cloudwego/frugal@v0.1.15/internal/binary/decoder/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 decoder 18 19 import ( 20 `unsafe` 21 22 `github.com/cloudwego/frugal/internal/binary/defs` 23 `github.com/cloudwego/frugal/internal/rt` 24 ) 25 26 const ( 27 NbOffset = int64(unsafe.Offsetof(StateItem{}.Nb)) 28 MpOffset = int64(unsafe.Offsetof(StateItem{}.Mp)) 29 WpOffset = int64(unsafe.Offsetof(StateItem{}.Wp)) 30 FmOffset = int64(unsafe.Offsetof(StateItem{}.Fm)) 31 ) 32 33 const ( 34 SkOffset = int64(unsafe.Offsetof(RuntimeState{}.Sk)) 35 PrOffset = int64(unsafe.Offsetof(RuntimeState{}.Pr)) 36 IvOffset = int64(unsafe.Offsetof(RuntimeState{}.Iv)) 37 ) 38 39 const ( 40 StateMax = (defs.StackSize - 1) * StateSize 41 StateSize = int64(unsafe.Sizeof(StateItem{})) 42 ) 43 44 type SkipItem struct { 45 T defs.Tag 46 K defs.Tag 47 V defs.Tag 48 N uint32 49 } 50 51 type StateItem struct { 52 Nb uint64 53 Mp *rt.GoMap 54 Wp unsafe.Pointer 55 Fm *FieldBitmap 56 } 57 58 type RuntimeState struct { 59 St [defs.StackSize]StateItem // Must be the first field. 60 Sk [defs.StackSize]SkipItem // Skip buffer, used for non-recursive skipping 61 Pr unsafe.Pointer // Pointer spill space, used for non-fast string or pointer map access. 62 Iv uint64 // Integer spill space, used for non-fast string map access. 63 }