gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/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  import (
    18  	"context"
    19  )
    20  
    21  type unregisteredEmptyStruct struct{}
    22  
    23  // typeOnlyEmptyStruct just implements the state.Type interface.
    24  type typeOnlyEmptyStruct struct{}
    25  
    26  func (*typeOnlyEmptyStruct) StateTypeName() string { return "registeredEmptyStruct" }
    27  
    28  func (*typeOnlyEmptyStruct) StateFields() []string { return nil }
    29  
    30  // +stateify savable
    31  type savableEmptyStruct struct{}
    32  
    33  // +stateify savable
    34  type emptyStructPointer struct {
    35  	nothing *struct{}
    36  }
    37  
    38  // +stateify savable
    39  type outerSame struct {
    40  	inner inner
    41  }
    42  
    43  // +stateify savable
    44  type outerFieldFirst struct {
    45  	inner inner
    46  	v     int64
    47  }
    48  
    49  // +stateify savable
    50  type outerFieldSecond struct {
    51  	v     int64
    52  	inner inner
    53  }
    54  
    55  // +stateify savable
    56  type outerArray struct {
    57  	inner [2]inner
    58  }
    59  
    60  // +stateify savable
    61  type outerSlice struct {
    62  	inner []inner
    63  }
    64  
    65  // +stateify savable
    66  type inner struct {
    67  	v int64
    68  }
    69  
    70  // +stateify savable
    71  type outerFieldValue struct {
    72  	inner innerFieldValue
    73  }
    74  
    75  // +stateify savable
    76  type innerFieldValue struct {
    77  	v int64 `state:".(*savedFieldValue)"`
    78  }
    79  
    80  // +stateify savable
    81  type savedFieldValue struct {
    82  	v int64
    83  }
    84  
    85  func (ifv *innerFieldValue) saveV() *savedFieldValue {
    86  	return &savedFieldValue{ifv.v}
    87  }
    88  
    89  func (ifv *innerFieldValue) loadV(_ context.Context, sfv *savedFieldValue) {
    90  	ifv.v = sfv.v
    91  }
    92  
    93  // +stateify savable
    94  type system struct {
    95  	v1 any
    96  	v2 any
    97  }
    98  
    99  // +stateify savable
   100  type system3 struct {
   101  	v1 any
   102  	v2 any
   103  	v3 any
   104  }
   105  
   106  // +stateify savable
   107  type multiName struct {
   108  	_, b, c string
   109  	x, y    int64
   110  	z       int32
   111  }