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

encoding/binary: error in reading bool #12201

Closed
lysevi opened this issue Aug 19, 2015 · 1 comment
Closed

encoding/binary: error in reading bool #12201

lysevi opened this issue Aug 19, 2015 · 1 comment

Comments

@lysevi
Copy link

lysevi commented Aug 19, 2015

go 1.4.2 windows7 x64

package main

import(
    "fmt"
    "bytes"
    "encoding/binary"
)

type Header struct {
    IsFull        bool
}

func main(){
    a:=make([]byte,1024,1024)
    for i:=0;i<1024;i++{
        a[i]=byte(i)
    }
    var pi Header
    buf := bytes.NewReader(a)
    err := binary.Read(buf, binary.LittleEndian, &pi)
    fmt.Println(err)    
}

result: "binary.Read: invalid type *main.Header"

but, if o change type of Header.IsFull from bool to byte or int8 (or something else int*), then all works done

@ianlancetaylor
Copy link
Contributor

This is working as expected. The encoding/binary package, as the documentation says, "implements simple translation between numbers and byte sequences." The type bool is not a number.

@mikioh mikioh changed the title error in encoding/binary Read encoding/binary: error in reading bool Aug 21, 2015
@golang golang locked and limited conversation to collaborators Aug 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants