From 094afdb15aa72f2e687534c57babc00bbf0f0467 Mon Sep 17 00:00:00 2001 From: zutto Date: Sun, 17 Apr 2022 01:33:34 +0300 Subject: [PATCH] update readme & add header_test sample cmd --- README.md | 2 +- cmd/samples/header_encode.go | 27 +++++++++++++++++++++++++++ pkg/headers/headers_test.go | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 cmd/samples/header_encode.go diff --git a/README.md b/README.md index 6abc1bc..0b90ce5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Project in progress. -[Click here for more](https://zutto.fi/posts/data-structure/) +[Click here for more](https://zutto.fi/posts/db/headers/) diff --git a/cmd/samples/header_encode.go b/cmd/samples/header_encode.go new file mode 100644 index 0000000..1542ab4 --- /dev/null +++ b/cmd/samples/header_encode.go @@ -0,0 +1,27 @@ +package main + +import ( + "crypto/rand" + "fmt" + + "git.zutto.fi/zutto/db/pkg/headers" +) + +func main() { + h := headers.Headers{ + HeaderString: []byte(headers.HeaderString), + PageSize: uint64(256 ^ 2), + DBVersion: uint16(1), + + WAL: false, + Commit: make([]byte, headers.CommitDataLength), + } + + //generate random string for the commit.. + _, err := rand.Read(h.Commit[:headers.CommitDataLength]) + if err != nil { + fmt.Errorf("Failed to generate random string") + } + + fmt.Printf("%c", h.Generate()) +} diff --git a/pkg/headers/headers_test.go b/pkg/headers/headers_test.go index 097b2b1..5e55a05 100644 --- a/pkg/headers/headers_test.go +++ b/pkg/headers/headers_test.go @@ -2,6 +2,7 @@ package headers import ( "crypto/rand" + "fmt" "reflect" "testing" ) @@ -23,7 +24,7 @@ func TestHeaders_Generate(t *testing.T) { } output := h.Generate() - + fmt.Printf("%c", output) h2 := Headers{} h2.Parse(output, 0)