github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/state/tests/struct.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tests 16 17 type unregisteredEmptyStruct struct{} 18 19 // typeOnlyEmptyStruct just implements the state.Type interface. 20 type typeOnlyEmptyStruct struct{} 21 22 func (*typeOnlyEmptyStruct) StateTypeName() string { return "registeredEmptyStruct" } 23 24 func (*typeOnlyEmptyStruct) StateFields() []string { return nil } 25 26 // +stateify savable 27 type savableEmptyStruct struct{} 28 29 // +stateify savable 30 type emptyStructPointer struct { 31 nothing *struct{} 32 } 33 34 // +stateify savable 35 type outerSame struct { 36 inner inner 37 } 38 39 // +stateify savable 40 type outerFieldFirst struct { 41 inner inner 42 v int64 43 } 44 45 // +stateify savable 46 type outerFieldSecond struct { 47 v int64 48 inner inner 49 } 50 51 // +stateify savable 52 type outerArray struct { 53 inner [2]inner 54 } 55 56 // +stateify savable 57 type outerSlice struct { 58 inner []inner 59 } 60 61 // +stateify savable 62 type inner struct { 63 v int64 64 } 65 66 // +stateify savable 67 type outerFieldValue struct { 68 inner innerFieldValue 69 } 70 71 // +stateify savable 72 type innerFieldValue struct { 73 v int64 `state:".(*savedFieldValue)"` 74 } 75 76 // +stateify savable 77 type savedFieldValue struct { 78 v int64 79 } 80 81 func (ifv *innerFieldValue) saveV() *savedFieldValue { 82 return &savedFieldValue{ifv.v} 83 } 84 85 func (ifv *innerFieldValue) loadV(sfv *savedFieldValue) { 86 ifv.v = sfv.v 87 } 88 89 // +stateify savable 90 type system struct { 91 v1 interface{} 92 v2 interface{} 93 } 94 95 // +stateify savable 96 type system3 struct { 97 v1 interface{} 98 v2 interface{} 99 v3 interface{} 100 }