You could, perhaps, use ioutil.ReadAll and then typeswitch for the common
types (strings, []byte, the numerics) that you can easily handle. If the
given receiver was not of one of those types, try to cast it to an
encoding.BinaryUnmarshaler and/or encoding.TextUnmarshaler since that's
essentially what you're doing. Let the user implement the type specific
unmarshalling. Document the expectations for the library user. :)

//jb


ons 19 okt. 2016 kl 23:25 skrev Brian Picciano <mediocregop...@gmail.com>:

> Hi Ian! I don't think that would work, my data can be pretty much any
> arbitrary data, including binary data. So I would need to tell Fscan to
> ignore any spaces it sees in the data itself, and then somehow accept the
> space which I replaced from EOF.
>
> On Wed, Oct 19, 2016 at 8:38 AM Ian Davis <m...@iandavis.com> wrote:
>
>
> On Wed, Oct 19, 2016, at 03:34 PM, Brian Picciano wrote:
>
> Hi there! My use-case involves reading all data off of an io.Reader and
> scanning it into a receiver value provided by the user of my library. In
> many ways the same thing as fmt.Fscan. The difference is that only one
> receiver value is allowed, and I want to read _all_ data until io.EOF, not
> just until space or newline. So if my data is "hello world" and I'm
> scanning into a string, that string should have "hello world" in it. If my
> data is "12 OK" and I'm scanning into an int, that should error because the
> entirety of the data is not a parseable integer.
>
> If there was a fmt.Scanf which simply had no delimiter, or where the
> delimiter was somehow set to io.EOF, I think that would work for what I'm
> doing. But I can't find anything like that. Does anyone know of anything
> that could help me do this? Or do I just have to implement it myself?
>
>
> Could you write a Reader that send a delimiter in the stream when it
> encounters io.EOF? Then pass that reader to Fscan.
>
> Ian
>
> --
>
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/3_QJ6qK5Hqw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
>
>
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to