(data []byte)
| 172 | } |
| 173 | |
| 174 | func DecodeMessage(data []byte) (Message, error) { |
| 175 | msg := wireCombined{} |
| 176 | if err := internaljson.Unmarshal(data, &msg); err != nil { |
| 177 | return nil, fmt.Errorf("unmarshaling jsonrpc message: %w", err) |
| 178 | } |
| 179 | if msg.VersionTag != wireVersion { |
| 180 | return nil, fmt.Errorf("invalid message version tag %q; expected %q", msg.VersionTag, wireVersion) |
| 181 | } |
| 182 | id, err := MakeID(msg.ID) |
| 183 | if err != nil { |
| 184 | return nil, err |
| 185 | } |
| 186 | if msg.Method != "" { |
| 187 | // has a method, must be a call |
| 188 | return &Request{ |
| 189 | Method: msg.Method, |
| 190 | ID: id, |
| 191 | Params: msg.Params, |
| 192 | }, nil |
| 193 | } |
| 194 | // no method, should be a response |
| 195 | if !id.IsValid() { |
| 196 | return nil, ErrInvalidRequest |
| 197 | } |
| 198 | resp := &Response{ |
| 199 | ID: id, |
| 200 | Result: msg.Result, |
| 201 | } |
| 202 | // we have to check if msg.Error is nil to avoid a typed error |
| 203 | if msg.Error != nil { |
| 204 | resp.Error = msg.Error |
| 205 | } |
| 206 | return resp, nil |
| 207 | } |
| 208 | |
| 209 | func marshalToRaw(obj any) (json.RawMessage, error) { |
| 210 | if obj == nil { |
searching dependent graphs…