From 2a25851fb6f122a3a39c04807d69a130bd0ed26d Mon Sep 17 00:00:00 2001 From: Niklas Jensen Date: Sun, 28 Dec 2025 22:27:15 +0100 Subject: [PATCH] Added page to test encoding of proto --- app/proto/platform_shared/example.ts | 155 +++++++++++++++++++++++++ app/src/lib/platform_shared/example.ts | 155 +++++++++++++++++++++++++ app/src/routes/prototest/+page.svelte | 15 +++ compile_proto_TEMP | 3 + 4 files changed, 328 insertions(+) create mode 100644 app/proto/platform_shared/example.ts create mode 100644 app/src/lib/platform_shared/example.ts create mode 100644 app/src/routes/prototest/+page.svelte create mode 100644 compile_proto_TEMP diff --git a/app/proto/platform_shared/example.ts b/app/proto/platform_shared/example.ts new file mode 100644 index 0000000..cc45c9b --- /dev/null +++ b/app/proto/platform_shared/example.ts @@ -0,0 +1,155 @@ +// Code generated by protoc-gen-ts_proto. DO NOT EDIT. +// versions: +// protoc-gen-ts_proto v2.10.1 +// protoc v6.33.2 +// source: platform_shared/example.proto + +/* eslint-disable */ +import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; + +export const protobufPackage = ""; + +export enum IMUType { + IMU_NONE = 0, + IMU_ACCEL = 1, + IMU_GYRO = 2, + UNRECOGNIZED = -1, +} + +export function iMUTypeFromJSON(object: any): IMUType { + switch (object) { + case 0: + case "IMU_NONE": + return IMUType.IMU_NONE; + case 1: + case "IMU_ACCEL": + return IMUType.IMU_ACCEL; + case 2: + case "IMU_GYRO": + return IMUType.IMU_GYRO; + case -1: + case "UNRECOGNIZED": + default: + return IMUType.UNRECOGNIZED; + } +} + +export function iMUTypeToJSON(object: IMUType): string { + switch (object) { + case IMUType.IMU_NONE: + return "IMU_NONE"; + case IMUType.IMU_ACCEL: + return "IMU_ACCEL"; + case IMUType.IMU_GYRO: + return "IMU_GYRO"; + case IMUType.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} + +export interface IMUReport { + type: IMUType; + xVal: number; +} + +function createBaseIMUReport(): IMUReport { + return { type: 0, xVal: 0 }; +} + +export const IMUReport: MessageFns = { + encode(message: IMUReport, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { + if (message.type !== 0) { + writer.uint32(8).int32(message.type); + } + if (message.xVal !== 0) { + writer.uint32(17).double(message.xVal); + } + return writer; + }, + + decode(input: BinaryReader | Uint8Array, length?: number): IMUReport { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseIMUReport(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + if (tag !== 8) { + break; + } + + message.type = reader.int32() as any; + continue; + } + case 2: { + if (tag !== 17) { + break; + } + + message.xVal = reader.double(); + continue; + } + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skip(tag & 7); + } + return message; + }, + + fromJSON(object: any): IMUReport { + return { + type: isSet(object.type) ? iMUTypeFromJSON(object.type) : 0, + xVal: isSet(object.xVal) ? globalThis.Number(object.xVal) : 0, + }; + }, + + toJSON(message: IMUReport): unknown { + const obj: any = {}; + if (message.type !== 0) { + obj.type = iMUTypeToJSON(message.type); + } + if (message.xVal !== 0) { + obj.xVal = message.xVal; + } + return obj; + }, + + create, I>>(base?: I): IMUReport { + return IMUReport.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): IMUReport { + const message = createBaseIMUReport(); + message.type = object.type ?? 0; + message.xVal = object.xVal ?? 0; + return message; + }, +}; + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends globalThis.Array ? globalThis.Array> + : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/app/src/lib/platform_shared/example.ts b/app/src/lib/platform_shared/example.ts new file mode 100644 index 0000000..cc45c9b --- /dev/null +++ b/app/src/lib/platform_shared/example.ts @@ -0,0 +1,155 @@ +// Code generated by protoc-gen-ts_proto. DO NOT EDIT. +// versions: +// protoc-gen-ts_proto v2.10.1 +// protoc v6.33.2 +// source: platform_shared/example.proto + +/* eslint-disable */ +import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; + +export const protobufPackage = ""; + +export enum IMUType { + IMU_NONE = 0, + IMU_ACCEL = 1, + IMU_GYRO = 2, + UNRECOGNIZED = -1, +} + +export function iMUTypeFromJSON(object: any): IMUType { + switch (object) { + case 0: + case "IMU_NONE": + return IMUType.IMU_NONE; + case 1: + case "IMU_ACCEL": + return IMUType.IMU_ACCEL; + case 2: + case "IMU_GYRO": + return IMUType.IMU_GYRO; + case -1: + case "UNRECOGNIZED": + default: + return IMUType.UNRECOGNIZED; + } +} + +export function iMUTypeToJSON(object: IMUType): string { + switch (object) { + case IMUType.IMU_NONE: + return "IMU_NONE"; + case IMUType.IMU_ACCEL: + return "IMU_ACCEL"; + case IMUType.IMU_GYRO: + return "IMU_GYRO"; + case IMUType.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} + +export interface IMUReport { + type: IMUType; + xVal: number; +} + +function createBaseIMUReport(): IMUReport { + return { type: 0, xVal: 0 }; +} + +export const IMUReport: MessageFns = { + encode(message: IMUReport, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { + if (message.type !== 0) { + writer.uint32(8).int32(message.type); + } + if (message.xVal !== 0) { + writer.uint32(17).double(message.xVal); + } + return writer; + }, + + decode(input: BinaryReader | Uint8Array, length?: number): IMUReport { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + const end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseIMUReport(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + if (tag !== 8) { + break; + } + + message.type = reader.int32() as any; + continue; + } + case 2: { + if (tag !== 17) { + break; + } + + message.xVal = reader.double(); + continue; + } + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skip(tag & 7); + } + return message; + }, + + fromJSON(object: any): IMUReport { + return { + type: isSet(object.type) ? iMUTypeFromJSON(object.type) : 0, + xVal: isSet(object.xVal) ? globalThis.Number(object.xVal) : 0, + }; + }, + + toJSON(message: IMUReport): unknown { + const obj: any = {}; + if (message.type !== 0) { + obj.type = iMUTypeToJSON(message.type); + } + if (message.xVal !== 0) { + obj.xVal = message.xVal; + } + return obj; + }, + + create, I>>(base?: I): IMUReport { + return IMUReport.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): IMUReport { + const message = createBaseIMUReport(); + message.type = object.type ?? 0; + message.xVal = object.xVal ?? 0; + return message; + }, +}; + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends globalThis.Array ? globalThis.Array> + : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/app/src/routes/prototest/+page.svelte b/app/src/routes/prototest/+page.svelte new file mode 100644 index 0000000..d535f45 --- /dev/null +++ b/app/src/routes/prototest/+page.svelte @@ -0,0 +1,15 @@ + + +

Hexadecimal Output

+ +

Hex output: {hex}

diff --git a/compile_proto_TEMP b/compile_proto_TEMP new file mode 100644 index 0000000..910992a --- /dev/null +++ b/compile_proto_TEMP @@ -0,0 +1,3 @@ +This file is temporary, just to show how ot compile the proto files + +protoc --plugin="protoc-gen-ts_proto=$(Resolve-Path app\node_modules\.bin\protoc-gen-ts_proto.CMD)" --ts_proto_out="./app/src/lib" "platform_shared\example.proto" \ No newline at end of file