Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ByteStreamConsumer can't write to interface{} #167

Closed
danny-cheung opened this issue Nov 25, 2019 · 1 comment · Fixed by #273
Closed

ByteStreamConsumer can't write to interface{} #167

danny-cheung opened this issue Nov 25, 2019 · 1 comment · Fixed by #273

Comments

@danny-cheung
Copy link
Contributor

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
[]
@danny-cheung
Copy link
Contributor Author

Similar issue for TextConsumer as well

kzys pushed a commit to kzys/runtime that referenced this issue Dec 17, 2022
fredbi added a commit to fredbi/runtime that referenced this issue Dec 7, 2023
ByteStreamConsumer may write into an interface which underlying type
is []byte or string.

* fixes go-openapi#167

This PR affects only the ByteStreamConsumer.

Obviously, there is a lot of commonality with the TextConsumer, which
could be augmented the same way in a follow-up.
Also the newly proposed type switch could benefit the Producer.

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/runtime that referenced this issue Dec 8, 2023
ByteStreamConsumer may write into an interface which underlying type
is []byte or string.

* fixes go-openapi#167

This PR affects only the ByteStreamConsumer.

Obviously, there is a lot of commonality with the TextConsumer, which
could be augmented the same way in a follow-up.
Also the newly proposed type switch could benefit the Producer.

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/runtime that referenced this issue Dec 10, 2023
ByteStreamConsumer may write into an interface which underlying type
is []byte or string.

* fixes go-openapi#167

This PR affects only the ByteStreamConsumer.

Obviously, there is a lot of commonality with the TextConsumer, which
could be augmented the same way in a follow-up.
Also the newly proposed type switch could benefit the Producer.

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/runtime that referenced this issue Dec 11, 2023
ByteStreamConsumer may write into an interface which underlying type
is []byte or string.

* fixes go-openapi#167

This PR affects only the ByteStreamConsumer.

Obviously, there is a lot of commonality with the TextConsumer, which
could be augmented the same way in a follow-up.
Also the newly proposed type switch could benefit the Producer.

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to fredbi/runtime that referenced this issue Dec 11, 2023
* fix(ByteStreamConsumer): may now write into an interface which
  underlying type is []byte or string.

* feat(ByteStreamConsumer): added support to io.ReaderFrom, preferred
  over io.Writer if available
* feat(ByteStreamProducer): added support to io.WriterTo, preferred
  over io.Reader if available

* refact(ByteStreamProducer): removed redundant case "string" and preferred
  the more general reflected case (supports aliased strings)

* test: refactored ByteStream tests
* test: added benchmark for bytestream.Consume

* fixes go-openapi#167

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit that referenced this issue Dec 12, 2023
* fix(ByteStreamConsumer): may now write into an interface which
  underlying type is []byte or string.

* feat(ByteStreamConsumer): added support to io.ReaderFrom, preferred
  over io.Writer if available
* feat(ByteStreamProducer): added support to io.WriterTo, preferred
  over io.Reader if available

* refact(ByteStreamProducer): removed redundant case "string" and preferred
  the more general reflected case (supports aliased strings)

* test: refactored ByteStream tests
* test: added benchmark for bytestream.Consume

* fixes #167

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants