encode writes the value v to w, using the JDWP encoding scheme.
(w binary.Writer, v reflect.Value)
| 34 | |
| 35 | // encode writes the value v to w, using the JDWP encoding scheme. |
| 36 | func (c *Connection) encode(w binary.Writer, v reflect.Value) error { |
| 37 | if debug { |
| 38 | defer func() { |
| 39 | if r := recover(); r != nil { |
| 40 | panic(fmt.Errorf("Type %T %v %v", v.Interface(), v.Type().Name(), v.Kind())) |
| 41 | } |
| 42 | }() |
| 43 | } |
| 44 | |
| 45 | t := v.Type() |
| 46 | o := v.Interface() |
| 47 | |
| 48 | switch v.Type() { |
| 49 | case reflect.TypeOf((*EventModifier)(nil)).Elem(): |
| 50 | // EventModifier's are prefixed with their 1-byte modKind. |
| 51 | w.Uint8(o.(EventModifier).modKind()) |
| 52 | |
| 53 | case reflect.TypeOf((*Value)(nil)).Elem(): |
| 54 | // values are prefixed with their 1-tag type. |
| 55 | switch o.(type) { |
| 56 | case ArrayID: |
| 57 | w.Uint8(uint8(TagArray)) |
| 58 | case byte: |
| 59 | w.Uint8(uint8(TagByte)) |
| 60 | case Char: |
| 61 | w.Uint8(uint8(TagChar)) |
| 62 | case ObjectID: |
| 63 | w.Uint8(uint8(TagObject)) |
| 64 | case float32: |
| 65 | w.Uint8(uint8(TagFloat)) |
| 66 | case float64: |
| 67 | w.Uint8(uint8(TagDouble)) |
| 68 | case int, int32: |
| 69 | w.Uint8(uint8(TagInt)) |
| 70 | case int16: |
| 71 | w.Uint8(uint8(TagShort)) |
| 72 | case int64: |
| 73 | w.Uint8(uint8(TagLong)) |
| 74 | case nil: |
| 75 | w.Uint8(uint8(TagVoid)) |
| 76 | case bool: |
| 77 | w.Uint8(uint8(TagBoolean)) |
| 78 | case StringID: |
| 79 | w.Uint8(uint8(TagString)) |
| 80 | case ThreadID: |
| 81 | w.Uint8(uint8(TagThread)) |
| 82 | case ThreadGroupID: |
| 83 | w.Uint8(uint8(TagThreadGroup)) |
| 84 | case ClassLoaderID: |
| 85 | w.Uint8(uint8(TagClassLoader)) |
| 86 | case ClassObjectID: |
| 87 | w.Uint8(uint8(TagClassObject)) |
| 88 | default: |
| 89 | panic(fmt.Errorf("Got Value of type %T", o)) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | switch o := o.(type) { |