MCPcopy
hub / github.com/nats-io/nats.go / Decode

Method Decode

encoders/builtin/default_enc.go:67–123  ·  view source on GitHub ↗

Decode Deprecated: Encoded connections are no longer supported.

(subject string, data []byte, vPtr any)

Source from the content-addressed store, hash-verified

65//
66// Deprecated: Encoded connections are no longer supported.
67func (je *DefaultEncoder) Decode(subject string, data []byte, vPtr any) error {
68 // Figure out what it's pointing to...
69 sData := *(*string)(unsafe.Pointer(&data))
70 switch arg := vPtr.(type) {
71 case *string:
72 *arg = sData
73 return nil
74 case *[]byte:
75 *arg = data
76 return nil
77 case *int:
78 n, err := strconv.ParseInt(sData, 10, 64)
79 if err != nil {
80 return err
81 }
82 *arg = int(n)
83 return nil
84 case *int32:
85 n, err := strconv.ParseInt(sData, 10, 64)
86 if err != nil {
87 return err
88 }
89 *arg = int32(n)
90 return nil
91 case *int64:
92 n, err := strconv.ParseInt(sData, 10, 64)
93 if err != nil {
94 return err
95 }
96 *arg = int64(n)
97 return nil
98 case *float32:
99 n, err := strconv.ParseFloat(sData, 32)
100 if err != nil {
101 return err
102 }
103 *arg = float32(n)
104 return nil
105 case *float64:
106 n, err := strconv.ParseFloat(sData, 64)
107 if err != nil {
108 return err
109 }
110 *arg = float64(n)
111 return nil
112 case *bool:
113 b, err := strconv.ParseBool(sData)
114 if err != nil {
115 return err
116 }
117 *arg = b
118 return nil
119 default:
120 vt := reflect.TypeOf(arg).Elem()
121 return fmt.Errorf("nats: Default Encoder can't decode to type %s", vt)
122 }
123}

Callers 1

Calls 1

ErrorfMethod · 0.80

Tested by 1