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

Method Encode

encoders/builtin/default_enc.go:42–62  ·  view source on GitHub ↗

Encode Deprecated: Encoded connections are no longer supported.

(subject string, v any)

Source from the content-addressed store, hash-verified

40//
41// Deprecated: Encoded connections are no longer supported.
42func (je *DefaultEncoder) Encode(subject string, v any) ([]byte, error) {
43 switch arg := v.(type) {
44 case string:
45 bytes := *(*[]byte)(unsafe.Pointer(&arg))
46 return bytes, nil
47 case []byte:
48 return arg, nil
49 case bool:
50 if arg {
51 return trueB, nil
52 } else {
53 return falseB, nil
54 }
55 case nil:
56 return nilB, nil
57 default:
58 var buf bytes.Buffer
59 fmt.Fprintf(&buf, "%+v", arg)
60 return buf.Bytes(), nil
61 }
62}
63
64// Decode
65//

Callers 2

TestEncBuiltinEncodeNilFunction · 0.95

Calls 1

BytesMethod · 0.65

Tested by 2

TestEncBuiltinEncodeNilFunction · 0.76