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)
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())
}