|
|
@ -4,11 +4,11 @@ package main
|
|
|
|
//go:generate go run ./gen/main.go ./dota
|
|
|
|
//go:generate go run ./gen/main.go ./dota
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"bytes"
|
|
|
|
"compress/bzip2"
|
|
|
|
"compress/bzip2"
|
|
|
|
"flag"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"reflect"
|
|
|
|
"runtime/pprof"
|
|
|
|
"runtime/pprof"
|
|
|
@ -108,45 +108,70 @@ func printTypes(m proto.Message) {
|
|
|
|
fmt.Println(reflect.TypeOf(m))
|
|
|
|
fmt.Println(reflect.TypeOf(m))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func prettyVals(m proto.Message) {
|
|
|
|
func prettySlice(v reflect.Value) string {
|
|
|
|
v := reflect.ValueOf(m)
|
|
|
|
if v.Type().Elem().Kind() == reflect.Uint8 {
|
|
|
|
if v.Kind() == reflect.Ptr {
|
|
|
|
l := v.Len()
|
|
|
|
v = v.Elem()
|
|
|
|
if l > 16 {
|
|
|
|
|
|
|
|
l = 16
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
b := make([]byte, l)
|
|
|
|
|
|
|
|
for i := 0; i < l; i++ {
|
|
|
|
|
|
|
|
b[i] = byte(v.Index(i).Uint())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%x", b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if v.Kind() != reflect.Struct {
|
|
|
|
width := 0
|
|
|
|
fmt.Fprintf(os.Stderr, "don't know how to pretty-print value of type %v", reflect.TypeOf(m))
|
|
|
|
parts := make([]string, 0, v.Len())
|
|
|
|
return
|
|
|
|
for i := 0; i < v.Len() && width <= 32; i++ {
|
|
|
|
}
|
|
|
|
parts = append(parts, pretty(v.Index(i)))
|
|
|
|
|
|
|
|
width += len(parts[i]) // obligatory byte count is not rune count rabble
|
|
|
|
var buf bytes.Buffer
|
|
|
|
}
|
|
|
|
fmt.Fprintf(&buf, "%s ", v.Type())
|
|
|
|
return fmt.Sprintf("[%s]", strings.Join(parts, ", "))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for fn := 0; fn < v.NumField(); fn++ {
|
|
|
|
func prettyStruct(v reflect.Value) string {
|
|
|
|
field := v.Type().Field(fn)
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if field.Name == "XXX_unrecognized" {
|
|
|
|
fmt.Fprintf(&buf, "{%s ", v.Type())
|
|
|
|
continue
|
|
|
|
for fn := 0; fn < v.NumField(); fn++ {
|
|
|
|
}
|
|
|
|
field := v.Type().Field(fn)
|
|
|
|
|
|
|
|
if field.Name == "XXX_unrecognized" {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
fv := v.Field(fn)
|
|
|
|
fv := v.Field(fn)
|
|
|
|
if fv.Kind() == reflect.Ptr {
|
|
|
|
fmt.Fprintf(&buf, "%s: %s ", field.Name, pretty(fv))
|
|
|
|
if fv.IsNil() {
|
|
|
|
}
|
|
|
|
fmt.Fprintf(&buf, "%s: nil ", field.Name)
|
|
|
|
fmt.Fprint(&buf, "}")
|
|
|
|
continue
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fv = fv.Elem()
|
|
|
|
|
|
|
|
}
|
|
|
|
func pretty(v reflect.Value) string {
|
|
|
|
switch fv.Kind() {
|
|
|
|
switch v.Kind() {
|
|
|
|
case reflect.String:
|
|
|
|
case reflect.Ptr:
|
|
|
|
fmt.Fprintf(&buf, "%s: %q ", field.Name, fv.String())
|
|
|
|
if v.IsNil() {
|
|
|
|
case reflect.Int32:
|
|
|
|
return "nil"
|
|
|
|
fmt.Fprintf(&buf, "%s: %d ", field.Name, fv.Int())
|
|
|
|
|
|
|
|
case reflect.Bool:
|
|
|
|
|
|
|
|
fmt.Fprintf(&buf, "%s: %t ", field.Name, fv.Bool())
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
fmt.Fprintf(&buf, "%s: %s ", field.Name, fv.Type())
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pretty(v.Elem())
|
|
|
|
fmt.Printf("{%s}\n", buf.String())
|
|
|
|
case reflect.Struct:
|
|
|
|
|
|
|
|
return prettyStruct(v)
|
|
|
|
|
|
|
|
case reflect.Slice:
|
|
|
|
|
|
|
|
return prettySlice(v)
|
|
|
|
|
|
|
|
case reflect.String:
|
|
|
|
|
|
|
|
return fmt.Sprintf("%q", v.String())
|
|
|
|
|
|
|
|
case reflect.Int32:
|
|
|
|
|
|
|
|
return fmt.Sprintf("%d", v.Int())
|
|
|
|
|
|
|
|
case reflect.Uint8, reflect.Uint32:
|
|
|
|
|
|
|
|
return fmt.Sprintf("%d", v.Uint())
|
|
|
|
|
|
|
|
case reflect.Bool:
|
|
|
|
|
|
|
|
return fmt.Sprintf("%t", v.Bool())
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return v.Type().Name()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func prettyVals(m proto.Message) {
|
|
|
|
|
|
|
|
v := reflect.ValueOf(m)
|
|
|
|
|
|
|
|
fmt.Println(pretty(v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|