go-hep.org/x/hep@v0.38.1/rio/utils.go (about) 1 // Copyright ©2015 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package rio 6 7 import ( 8 "reflect" 9 ) 10 11 // rioAlignU32 returns sz adjusted to align at 4-byte boundaries 12 func rioAlignU32(sz uint32) uint32 { 13 return sz + (4-(sz&gAlign))&gAlign 14 } 15 16 // rioAlign returns sz adjusted to align at 4-byte boundaries 17 func rioAlign(sz int) int { 18 return sz + (4-(sz&int(gAlign)))&int(gAlign) 19 } 20 21 func nameFromType(rt reflect.Type) string { 22 if rt == nil { 23 return "interface" 24 } 25 // Default to printed representation for unnamed types 26 name := rt.String() 27 28 // But for named types (or pointers to them), qualify with import path. 29 // Dereference one pointer looking for a named type. 30 star := "" 31 if rt.Name() == "" { 32 pt := rt 33 if pt.Kind() == reflect.Ptr { 34 star = "*" 35 rt = pt.Elem() 36 } 37 } 38 39 if rt.Name() != "" { 40 switch rt.PkgPath() { 41 case "": 42 name = star + rt.Name() 43 default: 44 name = star + rt.PkgPath() + "." + rt.Name() 45 } 46 } 47 48 return name 49 } 50 51 // EOF