Skip to content

ByteStreamConsumer can't write to interface{} #167

@danny-cheung

Description

@danny-cheung

ByteStreamConsumer won't write to a destination of type interface{} even if it has a concrete type of []byte

package main
  
import (
        "bytes"
        "fmt"

        "github.com/go-openapi/runtime"
)

func main() {
	src := []byte{0x1, 0x2, 0x3}
	bsc := runtime.ByteStreamConsumer()

	dst := []byte{}
	err := bsc.Consume(bytes.NewBuffer(src), &dst)
	if err !=nil {
		fmt.Println(err)
	}
	fmt.Println(dst)
	
	var dst2 interface{} = []byte{}
	err = bsc.Consume(bytes.NewBuffer(src), &dst2)
	if err !=nil {
		fmt.Println(err)
	}
	fmt.Println(dst2)
}

produces

[1 2 3]
0xc0001ed340 (*interface {}) is not supported by the ByteStreamConsumer, can be resolved by supporting Writer/BinaryUnmarshaler interface
[]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions