From 6e0fb377b8232a9669d5b0ed1aeef84e667ad46f Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Sun, 23 Jun 2024 20:37:29 -0400 Subject: [PATCH] Init --- .vscode/launch.json | 15 +++++++++++++++ go.mod | 5 +++++ go.sum | 2 ++ main.go | 13 +++++++++++++ pkg/encoding/encoding.go | 33 +++++++++++++++++++++++++++++++++ pkg/utils/utils.go | 1 + 6 files changed, 69 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 pkg/encoding/encoding.go create mode 100644 pkg/utils/utils.go diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f79d986 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/main.go" + } + ] +} \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e513c84 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/rayaman/squish + +go 1.22.4 + +require github.com/fatih/structs v1.1.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b4a69db --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= +github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= diff --git a/main.go b/main.go new file mode 100644 index 0000000..07544df --- /dev/null +++ b/main.go @@ -0,0 +1,13 @@ +package main + +import "github.com/rayaman/squish/encoding" + +type User struct { + Name string `binary:"limit=24"` // no + Age int `binary:""` +} + +func main() { + user := &User{Name: "Ryan Ward", Age: 28} + encoding.GetOptions(user) +} diff --git a/pkg/encoding/encoding.go b/pkg/encoding/encoding.go new file mode 100644 index 0000000..be768cc --- /dev/null +++ b/pkg/encoding/encoding.go @@ -0,0 +1,33 @@ +package encoding + +import ( + "fmt" + "strings" + + "github.com/fatih/structs" +) + +type options struct { + max int64 +} + +func GetOptions(obj any) options { + fields := structs.Fields(obj) + for _, field := range fields { + tag := field.Tag("binary") + tags := strings.Split(tag, ",") + fmt.Println(tags) + for _, val := range tags { + fmt.Println(strings.Split(val, "=")) + } + } + return options{} +} + +func Marshal(obj any, version int16) error { + return nil +} + +func Unmarshal(data []byte) (any, int16, error) { + return nil, 0, nil +} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go new file mode 100644 index 0000000..d4b585b --- /dev/null +++ b/pkg/utils/utils.go @@ -0,0 +1 @@ +package utils