MCPcopy
hub / github.com/slimtoolkit/slim / Encode

Function Encode

pkg/ipc/command/command.go:115–137  ·  view source on GitHub ↗

Encode encodes the message instance to a JSON buffer object

(m Message)

Source from the content-addressed store, hash-verified

113
114// Encode encodes the message instance to a JSON buffer object
115func Encode(m Message) ([]byte, error) {
116 obj := messageWrapper{
117 Name: m.GetName(),
118 }
119
120 switch v := m.(type) {
121 case *StartMonitor:
122 var b bytes.Buffer
123 encoder := json.NewEncoder(&b)
124 encoder.SetEscapeHTML(false)
125 if err := encoder.Encode(v); err != nil {
126 return nil, err
127 }
128
129 obj.Data = b.Bytes()
130 case *StopMonitor:
131 case *ShutdownSensor:
132 default:
133 return nil, ErrUnknownMessage
134 }
135
136 return json.Marshal(&obj)
137}
138
139// Decode decodes JSON data into a message instance
140func Decode(data []byte) (Message, error) {

Callers 3

SendCommandMethod · 0.92
SendCommandMethod · 0.92

Calls 1

GetNameMethod · 0.65

Tested by

no test coverage detected