Hey all this is my very firist time in the forum.
So i want to write some structs in a binary file, i was searching and i found this two functions to do it.
func writeGob(path string, object interface{}, offset int64) error {
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0777)
if err != nil {
PrintError("Error intentando abrir el archivo")
return errors.New("Error intentado abrir el archivo")
}
file.Seek(offset, 0)
encoder := gob.NewEncoder(file)
encoder.Encode(object)
file.Close()
return err
}
func readGob(path string, offset int64, object interface{}) error {
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 666)
if err != nil {
PrintError("Error intentando abrir el archivo: " + err.Error())
return errors.New("Error intentando abrir el archivo")
}
file.Seek(offset, 0)
decoder := gob.NewDecoder(file)
err = decoder.Decode(object)
file.Close()
return err // must be nil
}
this are the two structs that im using
type Ebr struct {
PartStatus uint8
PartFit uint8
PartStart int64
PartSize int64
PartName [16]uint8
PartNext int64
}
type Mbr struct {
MbrTamanio int64
MbrFechaCreacion [20]uint8
MbrDiskSignature int64
DiskFit uint8
MbrPartition [4]Partition
}
for getting you and idea this is a tinny ext2 implementation for a college work
everything was going fine, until i tried to read an ebr and i am getting this error
gob: Duplicate types received
This is the line code where the error occurs
var ebr = new(Ebr)
err := readGob(c.Args["path"].(string), ext.PartStart, ebr)
i search that error on google but i dont found any help. so if u can help me u will make me a very happy men