Added page to test encoding of proto
This commit is contained in:
@@ -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<IMUReport> = {
|
||||||
|
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 extends Exact<DeepPartial<IMUReport>, I>>(base?: I): IMUReport {
|
||||||
|
return IMUReport.fromPartial(base ?? ({} as any));
|
||||||
|
},
|
||||||
|
fromPartial<I extends Exact<DeepPartial<IMUReport>, 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> = T extends Builtin ? T
|
||||||
|
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
|
||||||
|
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
|
||||||
|
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
|
||||||
|
: Partial<T>;
|
||||||
|
|
||||||
|
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
||||||
|
export type Exact<P, I extends P> = P extends Builtin ? P
|
||||||
|
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
|
||||||
|
|
||||||
|
function isSet(value: any): boolean {
|
||||||
|
return value !== null && value !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MessageFns<T> {
|
||||||
|
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
||||||
|
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
||||||
|
fromJSON(object: any): T;
|
||||||
|
toJSON(message: T): unknown;
|
||||||
|
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
|
||||||
|
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
|
||||||
|
}
|
||||||
@@ -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<IMUReport> = {
|
||||||
|
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 extends Exact<DeepPartial<IMUReport>, I>>(base?: I): IMUReport {
|
||||||
|
return IMUReport.fromPartial(base ?? ({} as any));
|
||||||
|
},
|
||||||
|
fromPartial<I extends Exact<DeepPartial<IMUReport>, 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> = T extends Builtin ? T
|
||||||
|
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
|
||||||
|
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
|
||||||
|
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
|
||||||
|
: Partial<T>;
|
||||||
|
|
||||||
|
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
||||||
|
export type Exact<P, I extends P> = P extends Builtin ? P
|
||||||
|
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
|
||||||
|
|
||||||
|
function isSet(value: any): boolean {
|
||||||
|
return value !== null && value !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MessageFns<T> {
|
||||||
|
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
||||||
|
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
||||||
|
fromJSON(object: any): T;
|
||||||
|
toJSON(message: T): unknown;
|
||||||
|
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
|
||||||
|
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { IMUReport, IMUType } from '$lib/platform_shared/example';
|
||||||
|
|
||||||
|
const imu_report: IMUReport = {type: IMUType.IMU_ACCEL, xVal: 4}
|
||||||
|
const writer = IMUReport.encode(imu_report);
|
||||||
|
const bytes = writer.finish();
|
||||||
|
// Convert bytes to hex
|
||||||
|
const hex = Array.from(bytes)
|
||||||
|
.map((b) => b.toString(16).padStart(2, '0'))
|
||||||
|
.join(' ');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>Hexadecimal Output</h1>
|
||||||
|
|
||||||
|
<p><strong>Hex output:</strong> {hex}</p>
|
||||||
@@ -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"
|
||||||
Reference in New Issue
Block a user