MCPcopy Index your code
hub / github.com/FunctionStream/function-stream / decode

Method decode

admin/client/client.go:435–488  ·  view source on GitHub ↗
(v interface{}, b []byte, contentType string)

Source from the content-addressed store, hash-verified

433}
434
435func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) {
436 if len(b) == 0 {
437 return nil
438 }
439 if s, ok := v.(*string); ok {
440 *s = string(b)
441 return nil
442 }
443 if f, ok := v.(*os.File); ok {
444 f, err = os.CreateTemp("", "HttpClientFile")
445 if err != nil {
446 return
447 }
448 _, err = f.Write(b)
449 if err != nil {
450 return
451 }
452 _, err = f.Seek(0, io.SeekStart)
453 return
454 }
455 if f, ok := v.(**os.File); ok {
456 *f, err = os.CreateTemp("", "HttpClientFile")
457 if err != nil {
458 return
459 }
460 _, err = (*f).Write(b)
461 if err != nil {
462 return
463 }
464 _, err = (*f).Seek(0, io.SeekStart)
465 return
466 }
467 if XmlCheck.MatchString(contentType) {
468 if err = xml.Unmarshal(b, v); err != nil {
469 return err
470 }
471 return nil
472 }
473 if JsonCheck.MatchString(contentType) {
474 if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas
475 if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined
476 if err = unmarshalObj.UnmarshalJSON(b); err != nil {
477 return err
478 }
479 } else {
480 return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined")
481 }
482 } else if err = json.Unmarshal(b, v); err != nil { // simple model
483 return err
484 }
485 return nil
486 }
487 return errors.New("undefined response type")
488}
489
490// Add a file to the multipart request
491func addFile(w *multipart.Writer, fieldName, path string) error {

Callers 3

ConsumeMessageExecuteMethod · 0.80
GetStateExecuteMethod · 0.80

Calls 2

WriteMethod · 0.45
UnmarshalJSONMethod · 0.45

Tested by

no test coverage detected