Skip to content

Commit

Permalink
make Object ZPartialDeserializer require a new() constructor, rather …
Browse files Browse the repository at this point in the history
…than an object instance
  • Loading branch information
DenisBiryukov91 committed Jan 31, 2025
1 parent df13e68 commit 36e8d33
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 7 deletions.
143 changes: 142 additions & 1 deletion zenoh-ts/examples/chat/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

"@eclipse-zenoh/zenoh-ts@file:../..":
version "1.0.3"
version "1.1.1"
dependencies:
"@thi.ng/leb128" "^3.1.36"
base64-arraybuffer "^1.0.2"
channel-ts "^0.1.2"
eslint "^9.10.0"
Expand Down Expand Up @@ -146,6 +147,141 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@thi.ng/api@^8.11.19":
version "8.11.19"
resolved "https://registry.yarnpkg.com/@thi.ng/api/-/api-8.11.19.tgz#9ce8eb5657a28ddbd82a1864792b59a753a4ee33"
integrity sha512-ffK8nyNDd3kiwiijpb0Uv/0MtRUYpRtJj3K8OwFXdCzboll+/DNvXpfAlBMwSkLqZR0GighDwApyl0/4njiHCg==

"@thi.ng/arrays@^2.10.14":
version "2.10.14"
resolved "https://registry.yarnpkg.com/@thi.ng/arrays/-/arrays-2.10.14.tgz#a6202d3e208e2930554083b24c8a7143e23e8d56"
integrity sha512-hTuot92azDcX/GbWIFtbrKEPTThQn9tlRqKAnGL0xerCXEvHlvJ9F2zgf/crhBt8vcP8ca/P+4xYJYLKa54iBw==
dependencies:
"@thi.ng/api" "^8.11.19"
"@thi.ng/checks" "^3.6.22"
"@thi.ng/compare" "^2.4.11"
"@thi.ng/equiv" "^2.1.75"
"@thi.ng/errors" "^2.5.25"
"@thi.ng/random" "^4.1.10"

"@thi.ng/binary@^3.4.42":
version "3.4.42"
resolved "https://registry.yarnpkg.com/@thi.ng/binary/-/binary-3.4.42.tgz#2fdd71c7c06d9bfb38bd94b71598343ccf8d89a9"
integrity sha512-DU5JiBOONjx4synwos2GPaq8ByIfPSx6H6BsBmTf/Ou1PiABMlFuHlz8aOzw/Z1jUTYzb04arwUpYl1MVKjrAg==
dependencies:
"@thi.ng/api" "^8.11.19"

"@thi.ng/checks@^3.6.22":
version "3.6.22"
resolved "https://registry.yarnpkg.com/@thi.ng/checks/-/checks-3.6.22.tgz#00b3c6e4f8562f4108795b645a97cfc588c7cdcd"
integrity sha512-CMxQHrxvHnAVnmhxfP44GVS1TmAUWLsX8uZTVrL4IQcWzVVyHgvD6uXYw5E7kaZCR2S6wnS+Ng5oOCBE0EU/Hg==
dependencies:
tslib "^2.8.1"

"@thi.ng/compare@^2.4.11":
version "2.4.11"
resolved "https://registry.yarnpkg.com/@thi.ng/compare/-/compare-2.4.11.tgz#63cf4bebcd15575265f68bcf85d9b61c953c9cf6"
integrity sha512-SNbRrf19ntPmpXVkdMK04ZRRSDzPmRxxV9WKdH6+3J5NkYbASffi9o9WWun9In09P1+/Zh5yYfi2LzNsIDHNDw==
dependencies:
"@thi.ng/api" "^8.11.19"

"@thi.ng/compose@^3.0.22":
version "3.0.22"
resolved "https://registry.yarnpkg.com/@thi.ng/compose/-/compose-3.0.22.tgz#a7b4f4927fd896c0e37a797c8f2a2aa1f7a14271"
integrity sha512-PdXT/X4Ca8VfzyGryhAlw7PYyPvbRhpFqT4hej2oOgGuXeifoNr2J6WejTEwK8wA4F57onHHr7TisPVNfN/PMQ==
dependencies:
"@thi.ng/api" "^8.11.19"
"@thi.ng/errors" "^2.5.25"

"@thi.ng/equiv@^2.1.75":
version "2.1.75"
resolved "https://registry.yarnpkg.com/@thi.ng/equiv/-/equiv-2.1.75.tgz#f6fa49df08c1fd17da1302e057f1809cea3b5cb2"
integrity sha512-AoQQgrhW0xtXgxkrDK5EP5Y9Fe/QBGCmQgVKJ2G7uYCW/IbN/nTZEUM6011v41ydpmKl4wJjmr+s3StcIeDfdQ==

"@thi.ng/errors@^2.5.25":
version "2.5.25"
resolved "https://registry.yarnpkg.com/@thi.ng/errors/-/errors-2.5.25.tgz#4a9b91fbe51413b151d3758bdf6ef7e53cbc2d1f"
integrity sha512-PmK56hWGvRWr9Eq0V5xkV4tQvhjPtfvv6urFONP/D0gwFQXj+v6rcDYkAFLzOkbLqa0DYtkgvUsMklF/L53upA==

"@thi.ng/hex@^2.3.63":
version "2.3.63"
resolved "https://registry.yarnpkg.com/@thi.ng/hex/-/hex-2.3.63.tgz#75f91f6e4d4dec22046a74526b30f81d32d138f4"
integrity sha512-5xaQEKdaPls8de4zx4piPjCP13AHZLlyJCwHp4enSfeH5ZmDR3/aRwbmJod4FlJAvQdvDa3jBz+OtHNdxwrPLg==

"@thi.ng/leb128@^3.1.36":
version "3.1.36"
resolved "https://registry.yarnpkg.com/@thi.ng/leb128/-/leb128-3.1.36.tgz#9516fe5113d030a617039da3c8f5361d62185940"
integrity sha512-NfEfBpjtOwGJxgxDXyuLYxfmikT8u7TPT3J1rc51JmScxtTXZQkpgR3ORwy/xshILmGVMID2vww3NshZbSHqZg==
dependencies:
"@thi.ng/checks" "^3.6.22"
"@thi.ng/errors" "^2.5.25"
"@thi.ng/transducers-binary" "^2.1.152"

"@thi.ng/math@^5.11.19":
version "5.11.19"
resolved "https://registry.yarnpkg.com/@thi.ng/math/-/math-5.11.19.tgz#0a0ff7ad249f2960fcc3b39f930568d4a19a2b35"
integrity sha512-nsS1hP0rtgfuLtD6fLEtNTv07DlPZjKlgRoTrJcpkr47zzGcabwxo7a2VlHYFjhnShVUVSdQTFCnSSHN40drOQ==
dependencies:
"@thi.ng/api" "^8.11.19"

"@thi.ng/memoize@^4.0.9":
version "4.0.9"
resolved "https://registry.yarnpkg.com/@thi.ng/memoize/-/memoize-4.0.9.tgz#57ab73ed0e7ff98df94c7182a703b0dbd6edf8c3"
integrity sha512-YQD5lOew7mAZRripl3ylyOOq0OJ7yv/9D2o9w0Rd3ZrL2nl49tbticcH0V6nSKHEJhJSeRftCjmxNXNZulZkBw==
dependencies:
"@thi.ng/api" "^8.11.19"

"@thi.ng/random@^4.1.10":
version "4.1.10"
resolved "https://registry.yarnpkg.com/@thi.ng/random/-/random-4.1.10.tgz#732bae76ffb397ca42e771bbe94f6c8c2fbd815a"
integrity sha512-BBEAr0fg0pDoHtk4iBsdyLfZ9HcGvzeOwdAiXb3iibPhCL+h4lpjpmxy8yCyD7CatlnUICfbDdiY59X5qKJMgA==
dependencies:
"@thi.ng/api" "^8.11.19"
"@thi.ng/errors" "^2.5.25"

"@thi.ng/strings@^3.9.4":
version "3.9.4"
resolved "https://registry.yarnpkg.com/@thi.ng/strings/-/strings-3.9.4.tgz#782bbf81ea441c0d2671ca54654cf4c639762879"
integrity sha512-Ut9Elrp5HHiQjtJALjqKljzhDZYEgVMgwjN3EuEgHwBcrtvgthuhK6gKf2cGr0O8sqIjcctnhWqu7nE4QLuVaQ==
dependencies:
"@thi.ng/api" "^8.11.19"
"@thi.ng/errors" "^2.5.25"
"@thi.ng/hex" "^2.3.63"
"@thi.ng/memoize" "^4.0.9"

"@thi.ng/timestamp@^1.1.4":
version "1.1.4"
resolved "https://registry.yarnpkg.com/@thi.ng/timestamp/-/timestamp-1.1.4.tgz#6800c1fd8f9fc349e3d601a445707f52f1fc7d97"
integrity sha512-Rsfa1ypD3Ulkh2RDbj19hb8hCXRzUjy+1gpbovy2Bnys7VPNXRyHEaEZvqRNzj+jTzylvFNbi8QLArX7RXzeqw==

"@thi.ng/transducers-binary@^2.1.152":
version "2.1.152"
resolved "https://registry.yarnpkg.com/@thi.ng/transducers-binary/-/transducers-binary-2.1.152.tgz#320c4875f73ce31e9bcca5b2481ef5e4365636a8"
integrity sha512-0QG5cTheIZGcIaDDsaCaSSYvDXhFqbmdFng8HNLzl5EIcSecRC0R3rT7N0SxN+JxGMDRmZFQk/vFHlqulxaTew==
dependencies:
"@thi.ng/binary" "^3.4.42"
"@thi.ng/compose" "^3.0.22"
"@thi.ng/errors" "^2.5.25"
"@thi.ng/hex" "^2.3.63"
"@thi.ng/random" "^4.1.10"
"@thi.ng/strings" "^3.9.4"
"@thi.ng/transducers" "^9.2.17"

"@thi.ng/transducers@^9.2.17":
version "9.2.17"
resolved "https://registry.yarnpkg.com/@thi.ng/transducers/-/transducers-9.2.17.tgz#8504f45178c3875841c9afcb9dcd68a3966c4b22"
integrity sha512-LjbAbRAcpHi0gv6aW7+5ijJYJjhQtJoszEvjCC025RQ3pjXXD3gkRs8nnJULk6ibkcEcCoP5Q0WBWNAXusInQg==
dependencies:
"@thi.ng/api" "^8.11.19"
"@thi.ng/arrays" "^2.10.14"
"@thi.ng/checks" "^3.6.22"
"@thi.ng/compare" "^2.4.11"
"@thi.ng/compose" "^3.0.22"
"@thi.ng/errors" "^2.5.25"
"@thi.ng/math" "^5.11.19"
"@thi.ng/random" "^4.1.10"
"@thi.ng/timestamp" "^1.1.4"

"@types/eslint-scope@^3.7.7":
version "3.7.7"
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.7.tgz#3108bd5f18b0cdb277c867b3dd449c9ed7079ac5"
Expand Down Expand Up @@ -1568,6 +1704,11 @@ ts-loader@^9.2.6:
semver "^7.3.4"
source-map "^0.7.4"

tslib@^2.8.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==

tslog@^4.9.3:
version "4.9.3"
resolved "https://registry.yarnpkg.com/tslog/-/tslog-4.9.3.tgz#d4167d5f51748bdeab593945bc2d8f9827ea0dba"
Expand Down
2 changes: 1 addition & 1 deletion zenoh-ts/examples/deno/src/z_bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function main() {
{
let input = new MyStruct(1234n, "test", [1, 2, 3, 4])
let payload = zserialize(input)
let output = zdeserialize(ZSerDe.object(new MyStruct), payload)
let output = zdeserialize(ZSerDe.object(MyStruct), payload)
console.log(`Input: ${input.to_string()}, Output: ${output.to_string()}`)
}
}
Expand Down
11 changes: 6 additions & 5 deletions zenoh-ts/src/ext/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ export namespace ZSerDe{

/**
* Indicates that data should be deserialized as an object.
* @param proto An eventually empty object instance, used as an initial value for deserialization.
* @param create A new function to create an object instance where data will be deserialized.
* @returns Object deserialization tag.
*/
export function object<T extends ZDeserializeable>(proto: T): ZPartialDeserializer<T> {
return new ZPartialDeserializer((z: ZBytesDeserializer) => { return z.deserialize_object(proto)})
export function object<T extends ZDeserializeable>(create: new() => T): ZPartialDeserializer<T> {
return new ZPartialDeserializer((z: ZBytesDeserializer) => { return z.deserialize_object(create)})
}

/**
Expand Down Expand Up @@ -376,9 +376,10 @@ export class ZBytesDeserializer {

/**
* Deserializes next portion of data as an object of specified type and advance the reading position.
* @param o An eventually empty object instance to deserialize into.
* @param create A new function to create an object instance where data will be deserialized.
*/
public deserialize_object<T extends ZDeserializeable>(o: T): T {
public deserialize_object<T extends ZDeserializeable>(create: new () => T): T {
let o = new create()
o.deserialize_with_zdeserializer(this)
return o
}
Expand Down

0 comments on commit 36e8d33

Please sign in to comment.