aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operation_pack.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-14 22:17:37 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-14 22:17:37 +0200
commitda470993d13ce63087034db9b7e8ffbdf18e87a5 (patch)
tree7846ad86de6d93c51c54bf3e764a2108baa63612 /bug/operation_pack.go
parentf8e07748743f7e66ff1adf101a797cb1bedfc140 (diff)
downloadgit-bug-da470993d13ce63087034db9b7e8ffbdf18e87a5.tar.gz
complete the storage/read process + tests (!)
Diffstat (limited to 'bug/operation_pack.go')
-rw-r--r--bug/operation_pack.go30
1 files changed, 22 insertions, 8 deletions
diff --git a/bug/operation_pack.go b/bug/operation_pack.go
index 67a2a072..60016474 100644
--- a/bug/operation_pack.go
+++ b/bug/operation_pack.go
@@ -1,7 +1,8 @@
package bug
import (
- "encoding/json"
+ "bytes"
+ "encoding/gob"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util"
)
@@ -13,22 +14,35 @@ import (
// inside Git to form the complete ordered chain of operation to
// apply to get the final state of the Bug
type OperationPack struct {
- Operations []Operation `json:"ops"`
- hash util.Hash
+ Operations []Operation
}
-func Parse() (OperationPack, error) {
- // TODO
- return OperationPack{}, nil
+func ParseOperationPack(data []byte) (*OperationPack, error) {
+ reader := bytes.NewReader(data)
+ decoder := gob.NewDecoder(reader)
+
+ var opp OperationPack
+
+ err := decoder.Decode(&opp)
+
+ if err != nil {
+ return nil, err
+ }
+
+ return &opp, nil
}
func (opp *OperationPack) Serialize() ([]byte, error) {
- jsonBytes, err := json.Marshal(*opp)
+ var data bytes.Buffer
+
+ encoder := gob.NewEncoder(&data)
+ err := encoder.Encode(*opp)
+
if err != nil {
return nil, err
}
- return jsonBytes, nil
+ return data.Bytes(), nil
}
// Append a new operation to the pack