mirror of
https://github.com/logos-messaging/chat_proto.git
synced 2026-01-07 15:33:11 +00:00
Add nim implementation
This commit is contained in:
parent
3bfd702716
commit
47dd29b414
14
nim/.devcontainer/devcontainer.json
Normal file
14
nim/.devcontainer/devcontainer.json
Normal 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"
|
||||||
|
}
|
||||||
1
nim/.devcontainer/post_create.sh
Executable file
1
nim/.devcontainer/post_create.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
nimble install nimlangserver
|
||||||
2
nim/.gitignore
vendored
Normal file
2
nim/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
nimble.develop
|
||||||
|
nimble.paths
|
||||||
13
nim/chat_types.nimble
Normal file
13
nim/chat_types.nimble
Normal 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
4
nim/config.nims
Normal 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
9
nim/src/chat_types.nim
Normal 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
1
nim/tests/config.nims
Normal file
@ -0,0 +1 @@
|
|||||||
|
switch("path", "$projectDir/../src")
|
||||||
16
nim/tests/test_encoding.nim
Normal file
16
nim/tests/test_encoding.nim
Normal 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)
|
||||||
Loading…
x
Reference in New Issue
Block a user