Answer the question
In order to leave comments, you need to log in
Why can't I access the method?
package main
import (
"bytes"
"encoding/binary"
"fmt"
"io/ioutil"
"log"
)
type Buffer struct {
*bytes.Buffer
}
func (buf *Buffer) readUInt32() uint32 {
b := make([]byte, 4)
buf.Read(b)
return binary.LittleEndian.Uint32(b)
}
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
content, err := ioutil.ReadFile("subtitle.pck")
check(err)
buf := bytes.NewBuffer(content)
fmt.Print(buf.readUInt32()) // buf.readUInt32 undefined (type *bytes.Buffer has no field or method readUInt32)
Answer the question
In order to leave comments, you need to log in
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
)
type Buffer struct {
bytes.Buffer
}
func (buf *Buffer) readUInt32() uint32 {
b := make([]byte, 4)
buf.Read(b)
return binary.LittleEndian.Uint32(b)
}
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
var buf Buffer
content, err := ioutil.ReadFile("subtitle.pck")
check(err)
buf.Write(content)
fmt.Print(buf.readUInt32())
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question