gitee.com/zhongguo168a/gocodes@v0.0.0-20230609140523-e1828349603f/datax/schemax/other_test.go (about)

     1  package schemax
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"unsafe"
     7  )
     8  
     9  type PinkStruct struct {
    10  	A uint8
    11  	B int
    12  	C int64
    13  }
    14  
    15  type VioletStruct struct {
    16  	A uint8
    17  	B int64
    18  	C int64
    19  }
    20  
    21  func TestVioletStruct(t *testing.T) {
    22  	pink := PinkStruct{
    23  		A: 1,
    24  		B: 42,
    25  		C: 9000,
    26  	}
    27  
    28  	violet := *(*VioletStruct)(unsafe.Pointer(&pink))
    29  
    30  	fmt.Println(violet.A)
    31  	fmt.Println(violet.B)
    32  	fmt.Println(violet.C)
    33  }