Skip to content

Commit

Permalink
fix issue with sha gob encoding/decoding (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesHarness authored and Harness committed Mar 27, 2024
1 parent c57ea55 commit 18f857d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions git/sha/sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
package sha

import (
"bytes"
"encoding/gob"
"encoding/json"
"fmt"
"regexp"
"strings"

Expand Down Expand Up @@ -51,6 +54,22 @@ func New(value string) (SHA, error) {
}, nil
}

func (s SHA) GobEncode() ([]byte, error) {
buffer := &bytes.Buffer{}
err := gob.NewEncoder(buffer).Encode(s.str)
if err != nil {
return nil, fmt.Errorf("failed to pack sha value: %w", err)
}
return buffer.Bytes(), nil
}

func (s *SHA) GobDecode(v []byte) error {
if err := gob.NewDecoder(bytes.NewReader(v)).Decode(&s.str); err != nil {
return fmt.Errorf("failed to unpack sha value: %w", err)
}
return nil
}

func (s *SHA) UnmarshalJSON(content []byte) error {
if s == nil {
return nil
Expand Down

0 comments on commit 18f857d

Please sign in to comment.