// Unpack the result and any errors from the Response
187856
func (res *rpcResponse) unpack() (result map[string]interface{}, err error) {
	if res.Error != nil {
		err = fmt.Errorf(`Kodi error (%v): %v`, res.Error.Code, res.Error.Message)
	} else if res.Result != nil {
		result = *res.Result
	} else {
		log.WithField(`response`, res).Debug(`Received unknown response type from Kodi`)
	}
	return result, err
}
554162
func (r *UploadPackResponse) Read(p []byte) (int, error) {
	if r.r == nil {
		return 0, ErrUploadPackResponseNotDecoded
	}

	return r.r.Read(p)
}
415106
func (pr *PubrecPacket) Unpack(b io.Reader) error {
	var err error
	pr.MessageID, err = decodeUint16(b)

	return err
}
476913
func (r Result) Get() (runtime.Object, error) {
	if r.err != nil {
		return nil, r.err
	}
	return r.codec.Decode(r.body)
}
533654
func (cs *StreamManager) Unpack(payload string) []byte {
	return cs.Stream.Unpack(payload)
}
494166
func Unwrap(err error) error {
	for {
		switch specific := err.(type) {
		case *HereError:
			err = specific.error
		case *CauseError:
			err = specific.error
		case *TraceError:
			err = specific.error
		case *ContextError:
			err = specific.error
		case *SubjectError:
			err = specific.error
		default:
			return err
		}
	}
}
395437
func (sa *SubackPacket) Unpack(src []byte) {
	sa.MessageID = loadUint16(src)
	if len(src) < 2 {
		sa.GrantedQoss = make([]byte, 0) // FIXME: error
	} else {
		sa.GrantedQoss = src[2:]
	}
}
1000783
func (r *Response) Read(p []byte) (n int, err error) {

	if r.Error != nil {
		return -1, r.Error
	}

	return r.RawResponse.Body.Read(p)
}
523223
func Return(w http.ResponseWriter, code int, data interface{}) {
	w.WriteHeader(code)
	switch data.(type) {
	case string:
		w.Write([]byte(data.(string)))
	case []byte:
		w.Write(data.([]byte))
	}
}
320393
func Unwrap(err error) error {
	for {
		wrap, ok := err.(Wrapped)
		if !ok {
			return err
		}

		inner := wrap.InnerError()
		if inner == nil {
			break
		}
		err = inner
	}
	return err
}
10297
func ParsePacket(q []byte) (*Packet, error) {
	var pkt Packet
	if err := (&pkt).UnmarshalBinary(q); err != nil {
		return nil, err
	}
	return &pkt, nil
}
119663
func (pc *PubcompPacket) Unpack(b io.Reader) {
	pc.MessageID = decodeUint16(b)
}
1115422
func UnpackValue(v reflect.Value) (reflect.Value, error) {
	if v.IsNil() {
		return v, nil
	}
	k := v.Type().Kind()
	if k == reflect.Map {
		return v, nil
	} else if k == reflect.Ptr {
		return UnpackValue(v.Elem())
	} else if k == reflect.Interface {
		return UnpackValue(v.Elem())
	}
	return v, fmt.Errorf("Unsupported type")
}
1083744
func UnpackBytesToFloat(val []byte) float64 {
	pb := unsafe.Pointer(&val[0])
	return *(*float64)(pb)
}
651421
func (pr *PubrecPacket) Unpack(b io.Reader) {
	pr.MessageID = decodeUint16(b)
}
831027
func unpackMetadata(data *compute.Metadata) map[string]string {
	if data == nil {
		return nil
	}

	result := make(map[string]string)
	for _, item := range data.Items {
		if item == nil {
			continue
		}
		value := ""
		if item.Value != nil {
			value = *item.Value
		}
		result[item.Key] = value
	}
	return result
}
1165258
func unpack(t *Type, dst interface{}, src interface{}) error {
	var (
		dstVal = reflect.ValueOf(dst).Elem()
		srcVal = reflect.ValueOf(src)
	)

	if t.T != TupleTy && !((t.T == SliceTy || t.T == ArrayTy) && t.Elem.T == TupleTy) {
		return set(dstVal, srcVal)
	}

	switch t.T {
	case TupleTy:
		if dstVal.Kind() != reflect.Struct {
			return fmt.Errorf("abi: invalid dst value for unpack, want struct, got %s", dstVal.Kind())
		}
		fieldmap, err := mapArgNamesToStructFields(t.TupleRawNames, dstVal)
		if err != nil {
			return err
		}
		for i, elem := range t.TupleElems {
			fname := fieldmap[t.TupleRawNames[i]]
			field := dstVal.FieldByName(fname)
			if !field.IsValid() {
				return fmt.Errorf("abi: field %s can't found in the given value", t.TupleRawNames[i])
			}
			if err := unpack(elem, field.Addr().Interface(), srcVal.Field(i).Interface()); err != nil {
				return err
			}
		}
		return nil
	case SliceTy:
		if dstVal.Kind() != reflect.Slice {
			return fmt.Errorf("abi: invalid dst value for unpack, want slice, got %s", dstVal.Kind())
		}
		slice := reflect.MakeSlice(dstVal.Type(), srcVal.Len(), srcVal.Len())
		for i := 0; i < slice.Len(); i++ {
			if err := unpack(t.Elem, slice.Index(i).Addr().Interface(), srcVal.Index(i).Interface()); err != nil {
				return err
			}
		}
		dstVal.Set(slice)
	case ArrayTy:
		if dstVal.Kind() != reflect.Array {
			return fmt.Errorf("abi: invalid dst value for unpack, want array, got %s", dstVal.Kind())
		}
		array := reflect.New(dstVal.Type()).Elem()
		for i := 0; i < array.Len(); i++ {
			if err := unpack(t.Elem, array.Index(i).Addr().Interface(), srcVal.Index(i).Interface()); err != nil {
				return err
			}
		}
		dstVal.Set(array)
	}
	return nil
}