-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package codec | ||
|
||
import ( | ||
"bytes" | ||
"encoding/gob" | ||
) | ||
|
||
func Encode(input string) (*bytes.Buffer, error) { | ||
var buf bytes.Buffer | ||
enc := gob.NewEncoder(&buf) | ||
|
||
if err := enc.Encode(input); err != nil { | ||
return nil, err | ||
} | ||
return &buf, nil | ||
|
||
} | ||
|
||
func Decode(input *[]byte) (*string, error){ | ||
buf := bytes.NewBuffer(*input) | ||
dec := gob.NewDecoder(buf) | ||
|
||
s := "" | ||
if err := dec.Decode(&s); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &s, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package codec | ||
|
||
import ( | ||
"testing" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEncodeDecode(t *testing.T) { | ||
bytes, err := Encode("test"); if err != nil { | ||
panic("Failed to encode") | ||
} | ||
|
||
byteArray := bytes.Bytes() | ||
str, err := Decode(&byteArray); if err != nil { | ||
panic("Failed to decode") | ||
} | ||
assert.Equal(t, "test", *str, "decoded string is not 'test'") | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package storage_engine | ||
|
||
|
||
import "fmt" | ||
|
||
type BTree struct { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters