diff --git a/nim/.devcontainer/devcontainer.json b/nim/.devcontainer/devcontainer.json new file mode 100644 index 0000000..6661940 --- /dev/null +++ b/nim/.devcontainer/devcontainer.json @@ -0,0 +1,14 @@ +{ + "name": "UmbraTypes", + "image": "nimlang/nim", + "customizations": { + "vscode": { + "extensions": [ + "NimLang.nimlang", //Nim lang extension + "vadimcn.vscode-lldb", //for Nim debug + "streetsidesoftware.code-spell-checker" //spell checker + ] + } + }, + "postCreateCommand": "./.devcontainer/post_create.sh" +} \ No newline at end of file diff --git a/nim/.devcontainer/post_create.sh b/nim/.devcontainer/post_create.sh new file mode 100755 index 0000000..06c8937 --- /dev/null +++ b/nim/.devcontainer/post_create.sh @@ -0,0 +1 @@ +nimble install nimlangserver \ No newline at end of file diff --git a/nim/.gitignore b/nim/.gitignore new file mode 100644 index 0000000..2ca3f1f --- /dev/null +++ b/nim/.gitignore @@ -0,0 +1,2 @@ +nimble.develop +nimble.paths diff --git a/nim/chat_types.nimble b/nim/chat_types.nimble new file mode 100644 index 0000000..6f93a8d --- /dev/null +++ b/nim/chat_types.nimble @@ -0,0 +1,13 @@ +# Package + +version = "0.1.0" +author = "jazzz" +description = "Type definitions for the chat protocol" +license = "MIT" +srcDir = "src" +bin = @["dev"] # Remove + +# Dependencies +requires "nim >= 2.0.14" +requires "chronicles" +requires "protobuf_serialization" diff --git a/nim/config.nims b/nim/config.nims new file mode 100644 index 0000000..8ee48d2 --- /dev/null +++ b/nim/config.nims @@ -0,0 +1,4 @@ +# begin Nimble config (version 2) +when withDir(thisDir(), system.fileExists("nimble.paths")): + include "nimble.paths" +# end Nimble config diff --git a/nim/src/chat_types.nim b/nim/src/chat_types.nim new file mode 100644 index 0000000..51cb1ad --- /dev/null +++ b/nim/src/chat_types.nim @@ -0,0 +1,9 @@ +import protobuf_serialization +import protobuf_serialization/proto_parser + +import_proto3 "../../proto/umbra/base.proto" + +export protobuf_serialization + +# TODO: Do the Objects have to be listed manually? +export HistoryEntry \ No newline at end of file diff --git a/nim/tests/config.nims b/nim/tests/config.nims new file mode 100644 index 0000000..3bb69f8 --- /dev/null +++ b/nim/tests/config.nims @@ -0,0 +1 @@ +switch("path", "$projectDir/../src") \ No newline at end of file diff --git a/nim/tests/test_encoding.nim b/nim/tests/test_encoding.nim new file mode 100644 index 0000000..22e2b82 --- /dev/null +++ b/nim/tests/test_encoding.nim @@ -0,0 +1,16 @@ +import unittest + +import chat_types + +suite "Type Encoding Tests": + test "HistoryEntry roundtrip": + let x = chat_types.HistoryEntry(message_id: "12345", retrieval_hint: @[1'u8, 2, 3, 255]) + let encoded = Protobuf.encode(x) + let decoded = Protobuf.decode(encoded, HistoryEntry) + + check x.message_id == decoded.message_id + check x.retrieval_hint == decoded.retrieval_hint + check x == decoded + + test "Multiplication works": + check(2 * 3 == 6) \ No newline at end of file