本文整理汇总了Golang中reflect.StructType.Size方法的典型用法代码示例。如果您正苦于以下问题:Golang StructType.Size方法的具体用法?Golang StructType.Size怎么用?Golang StructType.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reflect.StructType
的用法示例。
在下文中一共展示了StructType.Size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: decodeStruct
func decodeStruct(engine *decEngine, rtyp *reflect.StructType, b *bytes.Buffer, p uintptr, indir int) os.Error {
if indir > 0 {
up := unsafe.Pointer(p)
if indir > 1 {
up = decIndirect(up, indir)
}
if *(*unsafe.Pointer)(up) == nil {
// Allocate object by making a slice of bytes and recording the
// address of the beginning of the array. TODO(rsc).
b := make([]byte, rtyp.Size())
*(*unsafe.Pointer)(up) = unsafe.Pointer(&b[0])
}
p = *(*uintptr)(up)
}
state := newDecodeState(b)
state.fieldnum = -1
basep := p
for state.err == nil {
delta := int(decodeUint(state))
if delta < 0 {
state.err = os.ErrorString("gob decode: corrupted data: negative delta")
break
}
if state.err != nil || delta == 0 { // struct terminator is zero delta fieldnum
break
}
fieldnum := state.fieldnum + delta
if fieldnum >= len(engine.instr) {
state.err = errRange
break
}
instr := &engine.instr[fieldnum]
p := unsafe.Pointer(basep + instr.offset)
if instr.indir > 1 {
p = decIndirect(p, instr.indir)
}
instr.op(instr, state, p)
state.fieldnum = fieldnum
}
return state.err
}