Skip to content

ByteStreamConsumer can't write to interface{} #167

Closed

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
[]

Activity

  1. danny-cheung commented on Nov 25, 2019

    @danny-cheung
    ContributorAuthor

    Similar issue for TextConsumer as well

  2. added a commit that references this issue on Dec 17, 2022
  3. added a commit that references this issue on Dec 7, 2023
    d2cdb7c
  4. added 4 commits that reference this issue on Dec 8, 2023
    e1af0d1
    168d308
    7e3eae8
    0a0b04d
  5. added a commit that references this issue on Dec 12, 2023
    e9d312a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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