Add nim implementation

This commit is contained in:
Jazz Turner-Baggs 2025-06-30 17:52:54 -07:00
parent 3bfd702716
commit 47dd29b414
No known key found for this signature in database
8 changed files with 60 additions and 0 deletions

View File

@ -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"
}

View File

@ -0,0 +1 @@
nimble install nimlangserver

2
nim/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
nimble.develop
nimble.paths

13
nim/chat_types.nimble Normal file
View File

@ -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"

4
nim/config.nims Normal file
View File

@ -0,0 +1,4 @@
# begin Nimble config (version 2)
when withDir(thisDir(), system.fileExists("nimble.paths")):
include "nimble.paths"
# end Nimble config

9
nim/src/chat_types.nim Normal file
View File

@ -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

1
nim/tests/config.nims Normal file
View File

@ -0,0 +1 @@
switch("path", "$projectDir/../src")

View File

@ -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)