代码拉取完成,页面将自动刷新
package struc
import (
"fmt"
"reflect"
)
type Type int
const (
Invalid Type = iota
Pad
Bool
Int
Int8
Uint8
Int16
Uint16
Int32
Uint32
Int64
Uint64
Float32
Float64
String
Struct
Ptr
SizeType
OffType
CustomType
)
func (t Type) Resolve(options *Options) Type {
switch t {
case OffType:
switch options.PtrSize {
case 8:
return Int8
case 16:
return Int16
case 32:
return Int32
case 64:
return Int64
default:
panic(fmt.Sprintf("unsupported ptr bits: %d", options.PtrSize))
}
case SizeType:
switch options.PtrSize {
case 8:
return Uint8
case 16:
return Uint16
case 32:
return Uint32
case 64:
return Uint64
default:
panic(fmt.Sprintf("unsupported ptr bits: %d", options.PtrSize))
}
}
return t
}
func (t Type) String() string {
return typeNames[t]
}
func (t Type) Size() int {
switch t {
case SizeType, OffType:
panic("Size_t/Off_t types must be converted to another type using options.PtrSize")
case Pad, String, Int8, Uint8, Bool:
return 1
case Int16, Uint16:
return 2
case Int32, Uint32, Float32:
return 4
case Int64, Uint64, Float64:
return 8
default:
panic("Cannot resolve size of type:" + t.String())
}
}
var typeLookup = map[string]Type{
"pad": Pad,
"bool": Bool,
"byte": Uint8,
"int8": Int8,
"uint8": Uint8,
"int16": Int16,
"uint16": Uint16,
"int32": Int32,
"uint32": Uint32,
"int64": Int64,
"uint64": Uint64,
"float32": Float32,
"float64": Float64,
"size_t": SizeType,
"off_t": OffType,
}
var typeNames = map[Type]string{
CustomType: "Custom",
}
func init() {
for name, enum := range typeLookup {
typeNames[enum] = name
}
}
type Size_t uint64
type Off_t int64
var reflectTypeMap = map[reflect.Kind]Type{
reflect.Bool: Bool,
reflect.Int8: Int8,
reflect.Int16: Int16,
reflect.Int: Int32,
reflect.Int32: Int32,
reflect.Int64: Int64,
reflect.Uint8: Uint8,
reflect.Uint16: Uint16,
reflect.Uint: Uint32,
reflect.Uint32: Uint32,
reflect.Uint64: Uint64,
reflect.Float32: Float32,
reflect.Float64: Float64,
reflect.String: String,
reflect.Struct: Struct,
reflect.Ptr: Ptr,
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。