Skip to content

Commit

Permalink
add Serialize/UnSerialize Linker
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujhd committed Jan 13, 2024
1 parent 6200a43 commit e2a4e23
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions serialize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package goloader

import (
"encoding/binary"
"encoding/gob"
"io"
)

func Serialize(linker *Linker, writer io.Writer) error {
gob.Register(binary.LittleEndian)
gob.Register(binary.BigEndian)
encoder := gob.NewEncoder(writer)
err := encoder.Encode(linker)
if err != nil {
return err
}
return nil
}

func UnSerialize(reader io.Reader) (*Linker, error) {
gob.Register(binary.LittleEndian)
gob.Register(binary.BigEndian)
linker := initLinker()
decoder := gob.NewDecoder(reader)
err := decoder.Decode(linker)
if err != nil {
return nil, err
}
return linker, nil
}

0 comments on commit e2a4e23

Please sign in to comment.