diff options
Diffstat (limited to 'bug/operation_pack.go')
-rw-r--r-- | bug/operation_pack.go | 30 |
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 |