diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-05-11 23:42:35 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-05-12 02:20:50 +0200 |
commit | 8b5b3dd00cc16c351670a25933f4b37a604abaf8 (patch) | |
tree | aa5b32286ed880440c697e3b7cb251d74ad30029 /protocol |
Diffstat (limited to 'protocol')
-rw-r--r-- | protocol/.gitignore | 2 | ||||
-rw-r--r-- | protocol/Cargo.toml | 10 | ||||
-rw-r--r-- | protocol/build.rs | 6 | ||||
-rw-r--r-- | protocol/compiled/protocol.d.ts | 205 | ||||
-rw-r--r-- | protocol/compiled/protocol.js | 461 | ||||
-rw-r--r-- | protocol/package.json | 13 | ||||
-rw-r--r-- | protocol/src/lib.rs | 3 | ||||
-rw-r--r-- | protocol/src/test.proto | 12 |
8 files changed, 712 insertions, 0 deletions
diff --git a/protocol/.gitignore b/protocol/.gitignore new file mode 100644 index 0000000..ee37d2b --- /dev/null +++ b/protocol/.gitignore @@ -0,0 +1,2 @@ +node_modules/
+target/
\ No newline at end of file diff --git a/protocol/Cargo.toml b/protocol/Cargo.toml new file mode 100644 index 0000000..4d85516 --- /dev/null +++ b/protocol/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "protocol" +version = "0.1.0" +edition = "2024" + +[dependencies] +prost = { version = "0.13.5", default-features = false, features = ["std"] } + +[build-dependencies] +prost-build = "0.13.5" diff --git a/protocol/build.rs b/protocol/build.rs new file mode 100644 index 0000000..f23f5ee --- /dev/null +++ b/protocol/build.rs @@ -0,0 +1,6 @@ +use std::io::Result;
+
+fn main() -> Result<()> {
+ prost_build::compile_protos(&["src/test.proto"], &["src/"])?;
+ Ok(())
+}
diff --git a/protocol/compiled/protocol.d.ts b/protocol/compiled/protocol.d.ts new file mode 100644 index 0000000..76e462d --- /dev/null +++ b/protocol/compiled/protocol.d.ts @@ -0,0 +1,205 @@ +import * as $protobuf from "protobufjs"; +import Long = require("long"); +/** Namespace todo. */ +export namespace todo { + + /** Properties of an Inner. */ + interface IInner { + + /** Inner value */ + value?: (number|null); + } + + /** Represents an Inner. */ + class Inner implements IInner { + + /** + * Constructs a new Inner. + * @param [properties] Properties to set + */ + constructor(properties?: todo.IInner); + + /** Inner value. */ + public value: number; + + /** + * Creates a new Inner instance using the specified properties. + * @param [properties] Properties to set + * @returns Inner instance + */ + public static create(properties?: todo.IInner): todo.Inner; + + /** + * Encodes the specified Inner message. Does not implicitly {@link todo.Inner.verify|verify} messages. + * @param message Inner message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: todo.IInner, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified Inner message, length delimited. Does not implicitly {@link todo.Inner.verify|verify} messages. + * @param message Inner message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: todo.IInner, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Inner message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns Inner + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): todo.Inner; + + /** + * Decodes an Inner message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns Inner + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): todo.Inner; + + /** + * Verifies an Inner message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates an Inner message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns Inner + */ + public static fromObject(object: { [k: string]: any }): todo.Inner; + + /** + * Creates a plain object from an Inner message. Also converts values to other types if specified. + * @param message Inner + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: todo.Inner, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Inner to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for Inner + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + /** Properties of a MyMessage. */ + interface IMyMessage { + + /** MyMessage inner */ + inner?: (todo.IInner|null); + + /** MyMessage value */ + value?: (number|null); + } + + /** Represents a MyMessage. */ + class MyMessage implements IMyMessage { + + /** + * Constructs a new MyMessage. + * @param [properties] Properties to set + */ + constructor(properties?: todo.IMyMessage); + + /** MyMessage inner. */ + public inner?: (todo.IInner|null); + + /** MyMessage value. */ + public value: number; + + /** + * Creates a new MyMessage instance using the specified properties. + * @param [properties] Properties to set + * @returns MyMessage instance + */ + public static create(properties?: todo.IMyMessage): todo.MyMessage; + + /** + * Encodes the specified MyMessage message. Does not implicitly {@link todo.MyMessage.verify|verify} messages. + * @param message MyMessage message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: todo.IMyMessage, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified MyMessage message, length delimited. Does not implicitly {@link todo.MyMessage.verify|verify} messages. + * @param message MyMessage message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: todo.IMyMessage, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a MyMessage message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns MyMessage + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): todo.MyMessage; + + /** + * Decodes a MyMessage message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns MyMessage + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): todo.MyMessage; + + /** + * Verifies a MyMessage message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a MyMessage message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns MyMessage + */ + public static fromObject(object: { [k: string]: any }): todo.MyMessage; + + /** + * Creates a plain object from a MyMessage message. Also converts values to other types if specified. + * @param message MyMessage + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: todo.MyMessage, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this MyMessage to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for MyMessage + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } +} diff --git a/protocol/compiled/protocol.js b/protocol/compiled/protocol.js new file mode 100644 index 0000000..45268ef --- /dev/null +++ b/protocol/compiled/protocol.js @@ -0,0 +1,461 @@ +/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ +import * as $protobuf from "protobufjs/minimal"; + +// Common aliases +const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + +// Exported root namespace +const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + +export const todo = $root.todo = (() => { + + /** + * Namespace todo. + * @exports todo + * @namespace + */ + const todo = {}; + + todo.Inner = (function() { + + /** + * Properties of an Inner. + * @memberof todo + * @interface IInner + * @property {number|null} [value] Inner value + */ + + /** + * Constructs a new Inner. + * @memberof todo + * @classdesc Represents an Inner. + * @implements IInner + * @constructor + * @param {todo.IInner=} [properties] Properties to set + */ + function Inner(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Inner value. + * @member {number} value + * @memberof todo.Inner + * @instance + */ + Inner.prototype.value = 0; + + /** + * Creates a new Inner instance using the specified properties. + * @function create + * @memberof todo.Inner + * @static + * @param {todo.IInner=} [properties] Properties to set + * @returns {todo.Inner} Inner instance + */ + Inner.create = function create(properties) { + return new Inner(properties); + }; + + /** + * Encodes the specified Inner message. Does not implicitly {@link todo.Inner.verify|verify} messages. + * @function encode + * @memberof todo.Inner + * @static + * @param {todo.IInner} message Inner message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Inner.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.value != null && Object.hasOwnProperty.call(message, "value")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.value); + return writer; + }; + + /** + * Encodes the specified Inner message, length delimited. Does not implicitly {@link todo.Inner.verify|verify} messages. + * @function encodeDelimited + * @memberof todo.Inner + * @static + * @param {todo.IInner} message Inner message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Inner.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an Inner message from the specified reader or buffer. + * @function decode + * @memberof todo.Inner + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {todo.Inner} Inner + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Inner.decode = function decode(reader, length, error) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.todo.Inner(); + while (reader.pos < end) { + let tag = reader.uint32(); + if (tag === error) + break; + switch (tag >>> 3) { + case 1: { + message.value = reader.int32(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes an Inner message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof todo.Inner + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {todo.Inner} Inner + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Inner.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies an Inner message. + * @function verify + * @memberof todo.Inner + * @static + * @param {Object.<string,*>} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Inner.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.value != null && message.hasOwnProperty("value")) + if (!$util.isInteger(message.value)) + return "value: integer expected"; + return null; + }; + + /** + * Creates an Inner message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof todo.Inner + * @static + * @param {Object.<string,*>} object Plain object + * @returns {todo.Inner} Inner + */ + Inner.fromObject = function fromObject(object) { + if (object instanceof $root.todo.Inner) + return object; + let message = new $root.todo.Inner(); + if (object.value != null) + message.value = object.value | 0; + return message; + }; + + /** + * Creates a plain object from an Inner message. Also converts values to other types if specified. + * @function toObject + * @memberof todo.Inner + * @static + * @param {todo.Inner} message Inner + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.<string,*>} Plain object + */ + Inner.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.defaults) + object.value = 0; + if (message.value != null && message.hasOwnProperty("value")) + object.value = message.value; + return object; + }; + + /** + * Converts this Inner to JSON. + * @function toJSON + * @memberof todo.Inner + * @instance + * @returns {Object.<string,*>} JSON object + */ + Inner.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for Inner + * @function getTypeUrl + * @memberof todo.Inner + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + Inner.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/todo.Inner"; + }; + + return Inner; + })(); + + todo.MyMessage = (function() { + + /** + * Properties of a MyMessage. + * @memberof todo + * @interface IMyMessage + * @property {todo.IInner|null} [inner] MyMessage inner + * @property {number|null} [value] MyMessage value + */ + + /** + * Constructs a new MyMessage. + * @memberof todo + * @classdesc Represents a MyMessage. + * @implements IMyMessage + * @constructor + * @param {todo.IMyMessage=} [properties] Properties to set + */ + function MyMessage(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * MyMessage inner. + * @member {todo.IInner|null|undefined} inner + * @memberof todo.MyMessage + * @instance + */ + MyMessage.prototype.inner = null; + + /** + * MyMessage value. + * @member {number} value + * @memberof todo.MyMessage + * @instance + */ + MyMessage.prototype.value = 0; + + /** + * Creates a new MyMessage instance using the specified properties. + * @function create + * @memberof todo.MyMessage + * @static + * @param {todo.IMyMessage=} [properties] Properties to set + * @returns {todo.MyMessage} MyMessage instance + */ + MyMessage.create = function create(properties) { + return new MyMessage(properties); + }; + + /** + * Encodes the specified MyMessage message. Does not implicitly {@link todo.MyMessage.verify|verify} messages. + * @function encode + * @memberof todo.MyMessage + * @static + * @param {todo.IMyMessage} message MyMessage message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + MyMessage.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.inner != null && Object.hasOwnProperty.call(message, "inner")) + $root.todo.Inner.encode(message.inner, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.value != null && Object.hasOwnProperty.call(message, "value")) + writer.uint32(/* id 2, wireType 0 =*/16).int32(message.value); + return writer; + }; + + /** + * Encodes the specified MyMessage message, length delimited. Does not implicitly {@link todo.MyMessage.verify|verify} messages. + * @function encodeDelimited + * @memberof todo.MyMessage + * @static + * @param {todo.IMyMessage} message MyMessage message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + MyMessage.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a MyMessage message from the specified reader or buffer. + * @function decode + * @memberof todo.MyMessage + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {todo.MyMessage} MyMessage + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + MyMessage.decode = function decode(reader, length, error) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.todo.MyMessage(); + while (reader.pos < end) { + let tag = reader.uint32(); + if (tag === error) + break; + switch (tag >>> 3) { + case 1: { + message.inner = $root.todo.Inner.decode(reader, reader.uint32()); + break; + } + case 2: { + message.value = reader.int32(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a MyMessage message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof todo.MyMessage + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {todo.MyMessage} MyMessage + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + MyMessage.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a MyMessage message. + * @function verify + * @memberof todo.MyMessage + * @static + * @param {Object.<string,*>} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + MyMessage.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.inner != null && message.hasOwnProperty("inner")) { + let error = $root.todo.Inner.verify(message.inner); + if (error) + return "inner." + error; + } + if (message.value != null && message.hasOwnProperty("value")) + if (!$util.isInteger(message.value)) + return "value: integer expected"; + return null; + }; + + /** + * Creates a MyMessage message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof todo.MyMessage + * @static + * @param {Object.<string,*>} object Plain object + * @returns {todo.MyMessage} MyMessage + */ + MyMessage.fromObject = function fromObject(object) { + if (object instanceof $root.todo.MyMessage) + return object; + let message = new $root.todo.MyMessage(); + if (object.inner != null) { + if (typeof object.inner !== "object") + throw TypeError(".todo.MyMessage.inner: object expected"); + message.inner = $root.todo.Inner.fromObject(object.inner); + } + if (object.value != null) + message.value = object.value | 0; + return message; + }; + + /** + * Creates a plain object from a MyMessage message. Also converts values to other types if specified. + * @function toObject + * @memberof todo.MyMessage + * @static + * @param {todo.MyMessage} message MyMessage + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.<string,*>} Plain object + */ + MyMessage.toObject = function toObject(message, options) { + if (!options) + options = {}; + let object = {}; + if (options.defaults) { + object.inner = null; + object.value = 0; + } + if (message.inner != null && message.hasOwnProperty("inner")) + object.inner = $root.todo.Inner.toObject(message.inner, options); + if (message.value != null && message.hasOwnProperty("value")) + object.value = message.value; + return object; + }; + + /** + * Converts this MyMessage to JSON. + * @function toJSON + * @memberof todo.MyMessage + * @instance + * @returns {Object.<string,*>} JSON object + */ + MyMessage.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for MyMessage + * @function getTypeUrl + * @memberof todo.MyMessage + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + MyMessage.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/todo.MyMessage"; + }; + + return MyMessage; + })(); + + return todo; +})(); + +export { $root as default }; diff --git a/protocol/package.json b/protocol/package.json new file mode 100644 index 0000000..205e496 --- /dev/null +++ b/protocol/package.json @@ -0,0 +1,13 @@ +{ + "name": "todo-protocol", + "main": "compiled/protocol", + "scripts": { + "build": "bunx pbjs -t static-module -w es6 --es6 -o compiled/protocol.js src/*.proto && bunx pbts -o compiled/protocol.d.ts compiled/protocol.js" + }, + "dependencies": { + "protobufjs": "^7.5.1" + }, + "devDependencies": { + "protobufjs-cli": "^1.1.3" + } +}
\ No newline at end of file diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs new file mode 100644 index 0000000..dea67bf --- /dev/null +++ b/protocol/src/lib.rs @@ -0,0 +1,3 @@ +pub mod todo { + include!(concat!(env!("OUT_DIR"), "/todo.rs")); +} diff --git a/protocol/src/test.proto b/protocol/src/test.proto new file mode 100644 index 0000000..776bf2a --- /dev/null +++ b/protocol/src/test.proto @@ -0,0 +1,12 @@ +syntax = "proto3";
+
+package todo;
+
+message Inner {
+ int32 value = 1;
+}
+
+message MyMessage {
+ Inner inner = 1;
+ int32 value = 2;
+}
|