有个非常大的结构而且是数组. 走 grpc 返回结果要一个一个赋值
想直接通过指针转换过来, 看起来可行 但是怕运行时被教育
https://go.dev/play/p/v5vJ53sXiEs
// You can edit this code!
// Click here and start typing.
package main
import (
"fmt"
"sync"
"unsafe"
)
// NoUnkeyedLiterals can be embedded in a struct to prevent unkeyed literals.
type NoUnkeyedLiterals struct{}
// DoNotCompare can be embedded in a struct to prevent comparability.
type DoNotCompare [0]func()
// DoNotCopy can be embedded in a struct to help prevent shallow copies.
// This does not rely on a Go language feature, but rather a special case
// within the vet checker.
//
// See https://golang.org/issues/8005.
type DoNotCopy [0]sync.Mutex
// Requirements:
// - The type M must implement protoreflect.ProtoMessage.
// - The address of m must not be nil.
// - The address of m and the address of m.state must be equal,
// even though they are different Go types.
type MessageState struct {
NoUnkeyedLiterals
DoNotCompare
DoNotCopy
// atomicMessageInfo *MessageInfo
}
type (
UnknownFields = unknownFieldsA // TODO: switch to unknownFieldsB
unknownFieldsA = []byte
)
type JuDianUpdateTeamReq struct {
state MessageState
sizeCache int32
unknownFields UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
CurHp uint64 `protobuf:"varint,2,opt,name=curHp,proto3" json:"curHp,omitempty"`
TotalHp uint64 `protobuf:"varint,3,opt,name=totalHp,proto3" json:"totalHp,omitempty"`
}
type TeamData struct {
Id string `json:"id,omitempty"`
CurHp uint64 `json:"curHp,omitempty"`
TotalHp uint64 `json:"totalHp,omitempty"`
}
func main() {
juDianUpdateTeamReq := &JuDianUpdateTeamReq{
Id: "team1",
CurHp: 100,
TotalHp: 200,
}
teamData := (*TeamData)(unsafe.Pointer(&juDianUpdateTeamReq.Id))
fmt.Println("teamData", teamData)
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.