From 48edc0e2bec035a8edbba4e37f0e25bad92f2fbd Mon Sep 17 00:00:00 2001 From: DmitryAstafyev Date: Fri, 27 Sep 2024 09:39:18 +0200 Subject: [PATCH] Update build script for protobuf --- .../apps/protocol/binding/proto/Cargo.lock | 4 +- .../apps/protocol/binding/proto/build.rs | 1 + .../binding/proto/output/attachment.ts | 6 +- .../protocol/binding/proto/output/commands.ts | 24 +-- .../protocol/binding/proto/output/common.ts | 10 +- .../protocol/binding/proto/output/error.ts | 136 ++++++++-------- .../protocol/binding/proto/output/event.ts | 46 +++--- .../protocol/binding/proto/output/grabbing.ts | 6 +- .../protocol/binding/proto/output/index.ts | 2 +- .../protocol/binding/proto/output/observe.ts | 98 +++++------ .../protocol/binding/proto/output/progress.ts | 16 +- .../apps/protocol/binding/wasm/Cargo.lock | 4 +- .../apps/rustcore/rs-bindings/Cargo.lock | 4 +- .../ts-bindings/spec/session.protocol.spec.ts | 2 +- .../ts-bindings/src/api/session.provider.ts | 4 +- .../ts-bindings/src/api/tracker.provider.ts | 4 +- .../ts-bindings/src/native/native.session.ts | 22 +-- .../ts-bindings/src/protocol/commands.ts | 26 +-- .../ts-bindings/src/protocol/common.ts | 10 +- .../ts-bindings/src/protocol/error.ts | 152 +++++++++--------- .../ts-bindings/src/protocol/event.ts | 70 ++++---- .../ts-bindings/src/protocol/index.ts | 2 +- .../ts-bindings/src/protocol/observe.ts | 124 +++++++------- .../ts-bindings/src/protocol/progress.ts | 18 +-- .../src/{protocol => util}/convertor.ts | 4 +- scripts/elements/protocol.rb | 38 +++-- scripts/env/paths.rb | 1 + 27 files changed, 426 insertions(+), 408 deletions(-) rename application/apps/rustcore/ts-bindings/src/{protocol => util}/convertor.ts (99%) diff --git a/application/apps/protocol/binding/proto/Cargo.lock b/application/apps/protocol/binding/proto/Cargo.lock index f098bf758c..b1a813f661 100644 --- a/application/apps/protocol/binding/proto/Cargo.lock +++ b/application/apps/protocol/binding/proto/Cargo.lock @@ -414,7 +414,9 @@ dependencies = [ [[package]] name = "tslink" -version = "0.1.6" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7af33803ca4ffb62ac69c1230f7610ac0bc8a5b5a28dfb4d584bea0674ec416" dependencies = [ "convert_case", "lazy_static", diff --git a/application/apps/protocol/binding/proto/build.rs b/application/apps/protocol/binding/proto/build.rs index e285e3a4e8..7c92ba48a7 100644 --- a/application/apps/protocol/binding/proto/build.rs +++ b/application/apps/protocol/binding/proto/build.rs @@ -19,6 +19,7 @@ fn main() { }) .collect(); let binding = prost_build::Config::new(); + let mut cfg = binding; cfg.type_attribute(".", r#"#[derive(serde::Serialize, serde::Deserialize)]"#); for proto in protos.iter() { diff --git a/application/apps/protocol/binding/proto/output/attachment.ts b/application/apps/protocol/binding/proto/output/attachment.ts index d3741b3cba..a6ab0db257 100644 --- a/application/apps/protocol/binding/proto/output/attachment.ts +++ b/application/apps/protocol/binding/proto/output/attachment.ts @@ -1,6 +1,3 @@ -export interface AttachmentInfoList { - elements: AttachmentInfo[]; -} export interface AttachmentInfo { uuid: string; filepath: string; @@ -10,3 +7,6 @@ export interface AttachmentInfo { mime: string; messages: number[]; } +export interface AttachmentInfoList { + elements: AttachmentInfo[]; +} diff --git a/application/apps/protocol/binding/proto/output/commands.ts b/application/apps/protocol/binding/proto/output/commands.ts index 9639be75ef..35dd5a4556 100644 --- a/application/apps/protocol/binding/proto/output/commands.ts +++ b/application/apps/protocol/binding/proto/output/commands.ts @@ -1,12 +1,18 @@ +export interface Finished { + result: Output | null; +} export interface StringVec { values: string[]; } +export interface Cancelled { +} export interface CommandOutcome { outcome_oneof: OutcomeOneof | null; } -export interface OutcomeOneof { - Finished?: Finished; - Cancelled?: Cancelled; +export interface Empty { +} +export interface Output { + output_oneof: OutputOneof | null; } export interface OutputOneof { StringValue?: string; @@ -16,13 +22,7 @@ export interface OutputOneof { Int64Value?: number; EmptyValue?: Empty; } -export interface Output { - output_oneof: OutputOneof | null; -} -export interface Cancelled { -} -export interface Finished { - result: Output | null; -} -export interface Empty { +export interface OutcomeOneof { + Finished?: Finished; + Cancelled?: Cancelled; } diff --git a/application/apps/protocol/binding/proto/output/common.ts b/application/apps/protocol/binding/proto/output/common.ts index 234f58e40f..87c5b82762 100644 --- a/application/apps/protocol/binding/proto/output/common.ts +++ b/application/apps/protocol/binding/proto/output/common.ts @@ -1,11 +1,11 @@ -export interface RangeInclusive { - start: number; - end: number; +export interface RangeInclusiveList { + elements: RangeInclusive[]; } export interface Range { start: number; end: number; } -export interface RangeInclusiveList { - elements: RangeInclusive[]; +export interface RangeInclusive { + start: number; + end: number; } diff --git a/application/apps/protocol/binding/proto/output/error.ts b/application/apps/protocol/binding/proto/output/error.ts index 70a60b15af..9fa227e391 100644 --- a/application/apps/protocol/binding/proto/output/error.ts +++ b/application/apps/protocol/binding/proto/output/error.ts @@ -1,33 +1,14 @@ -export interface Unsupported { - message: string; -} -export interface NativeError { - severity: number; - kind: number; - message: string; -} -export interface InvalidArgs { - message: string; -} -export interface Protocol { +export interface Aborted { message: string; } -export interface SessionUnavailable { -} -export interface InvalidData { +export interface SessionCreatingFail { } -export interface Sde { +export interface Unsupported { message: string; } export interface SearchError { search_error_oneof: SearchErrorOneof | null; } -export interface SearchIoOperation { - message: string; -} -export interface CompCommunication { - message: string; -} export interface CompErrorOneof { DestinationPath?: DestinationPath; SessionCreatingFail?: SessionCreatingFail; @@ -45,64 +26,73 @@ export interface CompErrorOneof { Grabbing?: Grabbing; Sde?: Sde; } +export interface Interrupted { +} +export interface InvalidArgs { + message: string; +} import { RangeInclusive } from "./common"; export interface InvalidRange { range: RangeInclusive | null; context: string; } +export interface NotInitialize { +} +export interface SessionUnavailable { +} +export interface Process { + message: string; +} +export interface NativeError { + severity: number; + kind: number; + message: string; +} +export interface Input { + message: string; +} +export interface CompCommunication { + message: string; +} export interface SearchCommunication { message: string; } -export enum NativeErrorKind { - FileNotFound, - UnsupportedFileType, - ComputationFailed, - Configuration, - Interrupted, - OperationSearch, - NotYetImplemented, - ChannelError, - Io, - Grabber, +export interface Sde { + message: string; } export enum Severity { Warning, Error, } -export interface Input { - message: string; +export interface DestinationPath { } -export interface Interrupted { +export interface ComputationError { + comp_error_oneof: CompErrorOneof | null; } -export interface CompIoOperation { +export interface SearchConfig { message: string; } -export interface SearchErrorOneof { - SearchConfig?: SearchConfig; - SearchCommunication?: SearchCommunication; - SearchIoOperation?: SearchIoOperation; - Regex?: Regex; - Input?: Input; - Grab?: Grab; - Aborted?: Aborted; +export interface SearchIoOperation { + message: string; } -export interface ComputationError { - comp_error_oneof: CompErrorOneof | null; +export interface InvalidData { } -export interface GrabCommunication { +export interface GrabConfig { message: string; } -export interface MultipleInitCall { +export interface Grab { + error: GrabError | null; } -export interface GrabIoOperation { +export interface CompIoOperation { message: string; } -export interface SearchConfig { +export interface GrabIoOperation { message: string; } -export interface SessionCreatingFail { +export interface MultipleInitCall { } -export interface DestinationPath { +export interface GrabCommunication { + message: string; } export interface GrabErrorOneof { GrabConfig?: GrabConfig; @@ -113,29 +103,39 @@ export interface GrabErrorOneof { NotInitialize?: NotInitialize; Unsupported?: Unsupported; } -export interface OperationNotSupported { - message: string; -} -export interface NotInitialize { -} -export interface Grabbing { - error: GrabError | null; -} export interface GrabError { grab_error_oneof: GrabErrorOneof | null; } -export interface Grab { - error: GrabError | null; +export interface SearchErrorOneof { + SearchConfig?: SearchConfig; + SearchCommunication?: SearchCommunication; + SearchIoOperation?: SearchIoOperation; + Regex?: Regex; + Input?: Input; + Grab?: Grab; + Aborted?: Aborted; } -export interface Aborted { +export interface Regex { message: string; } -export interface Process { +export interface Protocol { message: string; } -export interface GrabConfig { +export interface OperationNotSupported { message: string; } -export interface Regex { - message: string; +export interface Grabbing { + error: GrabError | null; +} +export enum NativeErrorKind { + FileNotFound, + UnsupportedFileType, + ComputationFailed, + Configuration, + Interrupted, + OperationSearch, + NotYetImplemented, + ChannelError, + Io, + Grabber, } diff --git a/application/apps/protocol/binding/proto/output/event.ts b/application/apps/protocol/binding/proto/output/event.ts index 1b1478a9ea..5f7b9ad4f7 100644 --- a/application/apps/protocol/binding/proto/output/event.ts +++ b/application/apps/protocol/binding/proto/output/event.ts @@ -1,10 +1,11 @@ -export interface ValueRange { - min: number; - max: number; +import { Ticks } from "./progress"; +export interface DetailOneof { + Ticks?: Ticks; + Notification?: Notification; + Stopped?: boolean; } -export interface OperationDone { - uuid: string; - result: string; +export interface SearchMapUpdated { + update: string; } import { NativeError } from "./error"; export interface EventOneof { @@ -23,31 +24,23 @@ export interface EventOneof { OperationDone?: OperationDone; SessionDestroyed?: boolean; } -import { Ticks } from "./progress"; -export interface DetailOneof { - Ticks?: Ticks; - Notification?: Notification; - Stopped?: boolean; -} -export interface SearchMapUpdated { - update: string; +export interface IndexedMapUpdated { + len: number; } export interface CallbackEvent { event_oneof: EventOneof | null; } -export interface SearchValuesUpdated { - values: Map; -} export interface ProgressDetail { detail_oneof: DetailOneof | null; } +export interface OperationDone { + uuid: string; + result: string; +} export interface OperationError { uuid: string; error: NativeError | null; } -export interface IndexedMapUpdated { - len: number; -} export interface Notification { severity: number; content: string; @@ -57,12 +50,19 @@ export interface SearchUpdated { found: number; stat: Map; } -export interface Progress { - uuid: string; - detail: ProgressDetail | null; +export interface SearchValuesUpdated { + values: Map; +} +export interface ValueRange { + min: number; + max: number; } import { AttachmentInfo } from "./attachment"; export interface AttachmentsUpdated { len: number; attachment: AttachmentInfo | null; } +export interface Progress { + uuid: string; + detail: ProgressDetail | null; +} diff --git a/application/apps/protocol/binding/proto/output/grabbing.ts b/application/apps/protocol/binding/proto/output/grabbing.ts index feea02c52b..4c8fc5f115 100644 --- a/application/apps/protocol/binding/proto/output/grabbing.ts +++ b/application/apps/protocol/binding/proto/output/grabbing.ts @@ -1,9 +1,9 @@ +export interface GrabbedElementList { + elements: GrabbedElement[]; +} export interface GrabbedElement { source_id: number; content: string; pos: number; nature: number; } -export interface GrabbedElementList { - elements: GrabbedElement[]; -} diff --git a/application/apps/protocol/binding/proto/output/index.ts b/application/apps/protocol/binding/proto/output/index.ts index 0cb37c0bfd..d8bd37e6af 100644 --- a/application/apps/protocol/binding/proto/output/index.ts +++ b/application/apps/protocol/binding/proto/output/index.ts @@ -1,5 +1,5 @@ -export { Range } from "./common"; export { RangeInclusive } from "./common"; +export { Range } from "./common"; export { RangeInclusiveList } from "./common"; export { AttachmentInfo } from "./attachment"; export { AttachmentInfoList } from "./attachment"; diff --git a/application/apps/protocol/binding/proto/output/observe.ts b/application/apps/protocol/binding/proto/output/observe.ts index 7752660d5a..90c5a2b39b 100644 --- a/application/apps/protocol/binding/proto/output/observe.ts +++ b/application/apps/protocol/binding/proto/output/observe.ts @@ -1,49 +1,63 @@ +export interface SerialTransportConfig { + path: string; + baud_rate: number; + data_bits: number; + flow_control: number; + parity: number; + stop_bits: number; + send_data_delay: number; + exclusive: boolean; +} +export interface FileFormat { +} export interface MulticastInfo { multiaddr: string; interface: string; } +export interface Concat { + files: File[]; +} +export interface TypeOneof { + Dlt?: DltParserSettings; + SomeIp?: SomeIpParserSettings; + Text?: boolean; +} export interface ProcessTransportConfig { cwd: string; command: string; envs: Map; } -export interface File { - name: string; - format: number; - path: string; -} -export interface SomeIpParserSettings { - fibex_file_paths: string[]; +export interface DltFilterConfig { + min_log_level: number; + app_ids: string[]; + ecu_ids: string[]; + context_ids: string[]; + app_id_count: number; + context_id_count: number; } export interface OriginOneof { File?: File; Concat?: Concat; Stream?: Stream; } +export interface ObserveOptions { + origin: ObserveOrigin | null; + parser: ParserType | null; +} +export interface TransportOneof { + Process?: ProcessTransportConfig; + Tcp?: TcpTransportConfig; + Udp?: UdpTransportConfig; + Serial?: SerialTransportConfig; +} export interface Stream { name: string; transport: Transport | null; } -export interface ObserveOrigin { - origin_oneof: OriginOneof | null; -} -export interface Transport { - transport_oneof: TransportOneof | null; -} -export interface SerialTransportConfig { +export interface File { + name: string; + format: number; path: string; - baud_rate: number; - data_bits: number; - flow_control: number; - parity: number; - stop_bits: number; - send_data_delay: number; - exclusive: boolean; -} -export interface TypeOneof { - Dlt?: DltParserSettings; - SomeIp?: SomeIpParserSettings; - Text?: boolean; } export interface DltParserSettings { filter_config: DltFilterConfig | null; @@ -51,20 +65,11 @@ export interface DltParserSettings { with_storage_header: boolean; tz: string; } -export interface ObserveOptions { - origin: ObserveOrigin | null; - parser: ParserType | null; -} -export interface DltFilterConfig { - min_log_level: number; - app_ids: string[]; - ecu_ids: string[]; - context_ids: string[]; - app_id_count: number; - context_id_count: number; +export interface SomeIpParserSettings { + fibex_file_paths: string[]; } -export interface Concat { - files: File[]; +export interface ParserType { + type_oneof: TypeOneof | null; } export enum Type { PcapNg, @@ -72,6 +77,9 @@ export enum Type { Text, Binary, } +export interface ObserveOrigin { + origin_oneof: OriginOneof | null; +} export interface TcpTransportConfig { bind_addr: string; } @@ -79,14 +87,6 @@ export interface UdpTransportConfig { bind_addr: string; multicast: MulticastInfo[]; } -export interface FileFormat { -} -export interface ParserType { - type_oneof: TypeOneof | null; -} -export interface TransportOneof { - Process?: ProcessTransportConfig; - Tcp?: TcpTransportConfig; - Udp?: UdpTransportConfig; - Serial?: SerialTransportConfig; +export interface Transport { + transport_oneof: TransportOneof | null; } diff --git a/application/apps/protocol/binding/proto/output/progress.ts b/application/apps/protocol/binding/proto/output/progress.ts index 412ee5fa2f..44f8fe8d64 100644 --- a/application/apps/protocol/binding/proto/output/progress.ts +++ b/application/apps/protocol/binding/proto/output/progress.ts @@ -3,22 +3,22 @@ export interface TransitionOneof { Ticks?: TicksWithUuid; Stopped?: Stopped; } -export interface Stopped { - uuid: string; +export interface LifecycleTransition { + transition_oneof: TransitionOneof | null; } -export interface Started { +export interface TicksWithUuid { uuid: string; - alias: string; + ticks: Ticks | null; } export interface Ticks { count: number; state: string; total: number; } -export interface TicksWithUuid { +export interface Stopped { uuid: string; - ticks: Ticks | null; } -export interface LifecycleTransition { - transition_oneof: TransitionOneof | null; +export interface Started { + uuid: string; + alias: string; } diff --git a/application/apps/protocol/binding/wasm/Cargo.lock b/application/apps/protocol/binding/wasm/Cargo.lock index 07f030816f..cd2500497b 100644 --- a/application/apps/protocol/binding/wasm/Cargo.lock +++ b/application/apps/protocol/binding/wasm/Cargo.lock @@ -480,7 +480,9 @@ dependencies = [ [[package]] name = "tslink" -version = "0.1.6" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7af33803ca4ffb62ac69c1230f7610ac0bc8a5b5a28dfb4d584bea0674ec416" dependencies = [ "convert_case", "lazy_static", diff --git a/application/apps/rustcore/rs-bindings/Cargo.lock b/application/apps/rustcore/rs-bindings/Cargo.lock index 1ae4a99417..8713807167 100644 --- a/application/apps/rustcore/rs-bindings/Cargo.lock +++ b/application/apps/rustcore/rs-bindings/Cargo.lock @@ -2783,7 +2783,9 @@ dependencies = [ [[package]] name = "tslink" -version = "0.1.6" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7af33803ca4ffb62ac69c1230f7610ac0bc8a5b5a28dfb4d584bea0674ec416" dependencies = [ "convert_case 0.6.0", "lazy_static", diff --git a/application/apps/rustcore/ts-bindings/spec/session.protocol.spec.ts b/application/apps/rustcore/ts-bindings/spec/session.protocol.spec.ts index 8c3ac1e4be..0839e343ee 100644 --- a/application/apps/rustcore/ts-bindings/spec/session.protocol.spec.ts +++ b/application/apps/rustcore/ts-bindings/spec/session.protocol.spec.ts @@ -11,7 +11,7 @@ import { readConfigurationFile } from './config'; import * as proto from 'protocol'; import * as $ from 'platform/types/observe'; -import * as convertor from '../src/protocol/convertor'; +import * as convertor from '../src/util/convertor'; import * as runners from './runners'; const config = readConfigurationFile().get().tests.protocol; diff --git a/application/apps/rustcore/ts-bindings/src/api/session.provider.ts b/application/apps/rustcore/ts-bindings/src/api/session.provider.ts index f2d0f885f6..ddcb29c5f7 100644 --- a/application/apps/rustcore/ts-bindings/src/api/session.provider.ts +++ b/application/apps/rustcore/ts-bindings/src/api/session.provider.ts @@ -5,7 +5,7 @@ import { EErrorKind, EErrorSeverity } from '../provider/provider.errors'; import { IMapEntity, IMatchEntity, IValuesMinMaxMap } from 'platform/types/filter'; import { IAttachment } from 'platform/types/content'; -import * as Types from '../protocol/convertor'; +import * as convertor from '../util/convertor'; export interface IProgressState { total: number; @@ -196,7 +196,7 @@ export class EventProvider extends Computation< private readonly _convertors: ISessionEventsConvertors = {}; constructor(uuid: string) { - super(uuid, Types.decodeCallbackEvent); + super(uuid, convertor.decodeCallbackEvent); } public getName(): string { diff --git a/application/apps/rustcore/ts-bindings/src/api/tracker.provider.ts b/application/apps/rustcore/ts-bindings/src/api/tracker.provider.ts index 08efb747cc..d9e71cf355 100644 --- a/application/apps/rustcore/ts-bindings/src/api/tracker.provider.ts +++ b/application/apps/rustcore/ts-bindings/src/api/tracker.provider.ts @@ -1,7 +1,7 @@ import { Subject } from 'platform/env/subscription'; import { Computation } from '../provider/provider'; -import * as Types from '../protocol/convertor'; +import * as convertor from '../util/convertor'; export interface Job { alias: string; @@ -76,7 +76,7 @@ export class EventProvider extends Computation< private readonly _convertors = {}; constructor(uuid: string) { - super(uuid, Types.decodeLifecycleTransition); + super(uuid, convertor.decodeLifecycleTransition); } public getName(): string { diff --git a/application/apps/rustcore/ts-bindings/src/native/native.session.ts b/application/apps/rustcore/ts-bindings/src/native/native.session.ts index d84d0a64c2..9c6ac3cf56 100644 --- a/application/apps/rustcore/ts-bindings/src/native/native.session.ts +++ b/application/apps/rustcore/ts-bindings/src/native/native.session.ts @@ -18,7 +18,7 @@ import { SdeRequest, SdeResponse } from 'platform/types/sde'; import { getValidNum } from '../util/numbers'; import * as proto from 'protocol'; -import * as Types from '../protocol/convertor'; +import * as convertor from '../util/convertor'; export type RustSessionConstructorImpl = new ( uuid: string, @@ -443,7 +443,7 @@ export class RustSessionWrapper extends RustSession { this._provider.debug().emit.operation('grab'); this._native .grab(start, len) - .then((buf: number[]) => resolve(Types.decodeGrabbedElementList(buf))) + .then((buf: number[]) => resolve(convertor.decodeGrabbedElementList(buf))) .catch((err) => reject(NativeError.from(err))); }); } @@ -454,7 +454,7 @@ export class RustSessionWrapper extends RustSession { this._native .grabIndexed(start, len) .then((buf: number[]) => { - resolve(Types.decodeGrabbedElementList(buf)); + resolve(convertor.decodeGrabbedElementList(buf)); }) .catch((err) => reject(NativeError.from(err))); }); @@ -542,7 +542,7 @@ export class RustSessionWrapper extends RustSession { this._provider.debug().emit.operation('grabRanges'); this._native .grabRanges(ranges.map((r) => [r.from, r.to])) - .then((buf: number[]) => resolve(Types.decodeGrabbedElementList(buf))) + .then((buf: number[]) => resolve(convertor.decodeGrabbedElementList(buf))) .catch((err: Error) => reject(NativeError.from(err))); }); } @@ -553,7 +553,7 @@ export class RustSessionWrapper extends RustSession { this._native .grabSearch(start, len) .then((buf: number[]) => { - resolve(Types.decodeGrabbedElementList(buf)); + resolve(convertor.decodeGrabbedElementList(buf)); }) .catch((err: Error) => reject(NativeError.from(err))); }); @@ -602,7 +602,7 @@ export class RustSessionWrapper extends RustSession { this._native .observe( Buffer.copyBytesFrom( - proto.ObserveOptions.encode(Types.toObserveOptions(source)), + proto.ObserveOptions.encode(convertor.toObserveOptions(source)), ), operationUuid, ) @@ -758,9 +758,9 @@ export class RustSessionWrapper extends RustSession { this._native .sendIntoSde( targetOperationUuid, - Buffer.copyBytesFrom(Types.encodeSdeRequest(request)), + Buffer.copyBytesFrom(convertor.encodeSdeRequest(request)), ) - .then((buf: number[]) => resolve(Types.decodeSdeResponse(buf))) + .then((buf: number[]) => resolve(convertor.decodeSdeResponse(buf))) .catch((err: Error) => reject(NativeError.from(err))); }); } @@ -769,7 +769,7 @@ export class RustSessionWrapper extends RustSession { return new Promise((resolve, reject) => { this._native .getAttachments() - .then((buf: number[]) => resolve(Types.decodeAttachmentInfoList(buf))) + .then((buf: number[]) => resolve(convertor.decodeAttachmentInfoList(buf))) .catch((err: Error) => reject(NativeError.from(err))); }); } @@ -778,7 +778,7 @@ export class RustSessionWrapper extends RustSession { return new Promise((resolve, reject) => { this._native .getIndexedRanges() - .then((buf: number[]) => resolve(Types.decodeIRanges(buf))) + .then((buf: number[]) => resolve(convertor.decodeIRanges(buf))) .catch((err: Error) => reject(NativeError.from(err))); }); } @@ -894,7 +894,7 @@ export class RustSessionWrapper extends RustSession { if (decode === false) { return []; } - return Types.decodeGrabbedElementList(received); + return convertor.decodeGrabbedElementList(received); } catch (err) { return new NativeError(new Error(utils.error(err)), Type.Other, Source.Other); } diff --git a/application/apps/rustcore/ts-bindings/src/protocol/commands.ts b/application/apps/rustcore/ts-bindings/src/protocol/commands.ts index 5ffe9412d9..35dd5a4556 100644 --- a/application/apps/rustcore/ts-bindings/src/protocol/commands.ts +++ b/application/apps/rustcore/ts-bindings/src/protocol/commands.ts @@ -1,3 +1,16 @@ +export interface Finished { + result: Output | null; +} +export interface StringVec { + values: string[]; +} +export interface Cancelled { +} +export interface CommandOutcome { + outcome_oneof: OutcomeOneof | null; +} +export interface Empty { +} export interface Output { output_oneof: OutputOneof | null; } @@ -9,20 +22,7 @@ export interface OutputOneof { Int64Value?: number; EmptyValue?: Empty; } -export interface Cancelled { -} -export interface CommandOutcome { - outcome_oneof: OutcomeOneof | null; -} export interface OutcomeOneof { Finished?: Finished; Cancelled?: Cancelled; } -export interface Empty { -} -export interface StringVec { - values: string[]; -} -export interface Finished { - result: Output | null; -} diff --git a/application/apps/rustcore/ts-bindings/src/protocol/common.ts b/application/apps/rustcore/ts-bindings/src/protocol/common.ts index 234f58e40f..87c5b82762 100644 --- a/application/apps/rustcore/ts-bindings/src/protocol/common.ts +++ b/application/apps/rustcore/ts-bindings/src/protocol/common.ts @@ -1,11 +1,11 @@ -export interface RangeInclusive { - start: number; - end: number; +export interface RangeInclusiveList { + elements: RangeInclusive[]; } export interface Range { start: number; end: number; } -export interface RangeInclusiveList { - elements: RangeInclusive[]; +export interface RangeInclusive { + start: number; + end: number; } diff --git a/application/apps/rustcore/ts-bindings/src/protocol/error.ts b/application/apps/rustcore/ts-bindings/src/protocol/error.ts index 01ed06183f..9fa227e391 100644 --- a/application/apps/rustcore/ts-bindings/src/protocol/error.ts +++ b/application/apps/rustcore/ts-bindings/src/protocol/error.ts @@ -1,74 +1,14 @@ -export interface SearchIoOperation { - message: string; -} -export interface InvalidArgs { - message: string; -} -export interface GrabErrorOneof { - GrabConfig?: GrabConfig; - GrabCommunication?: GrabCommunication; - GrabIoOperation?: GrabIoOperation; - InvalidRange?: InvalidRange; - Interrupted?: Interrupted; - NotInitialize?: NotInitialize; - Unsupported?: Unsupported; -} -export interface NativeError { - severity: number; - kind: number; - message: string; -} -export interface SessionUnavailable { -} -export interface ComputationError { - comp_error_oneof: CompErrorOneof | null; -} -export interface Protocol { - message: string; -} -export interface CompIoOperation { - message: string; -} -export interface GrabCommunication { - message: string; -} -export interface InvalidData { -} -export interface Process { - message: string; -} -export interface GrabConfig { +export interface Aborted { message: string; } -export interface DestinationPath { -} export interface SessionCreatingFail { } -export interface MultipleInitCall { -} -export interface Grabbing { - error: GrabError | null; -} -export interface NotInitialize { -} -export interface Grab { - error: GrabError | null; -} -export enum NativeErrorKind { - FileNotFound, - UnsupportedFileType, - ComputationFailed, - Configuration, - Interrupted, - OperationSearch, - NotYetImplemented, - ChannelError, - Io, - Grabber, -} export interface Unsupported { message: string; } +export interface SearchError { + search_error_oneof: SearchErrorOneof | null; +} export interface CompErrorOneof { DestinationPath?: DestinationPath; SessionCreatingFail?: SessionCreatingFail; @@ -86,17 +26,35 @@ export interface CompErrorOneof { Grabbing?: Grabbing; Sde?: Sde; } +export interface Interrupted { +} +export interface InvalidArgs { + message: string; +} import { RangeInclusive } from "./common"; export interface InvalidRange { range: RangeInclusive | null; context: string; } -export interface Interrupted { +export interface NotInitialize { } -export interface GrabError { - grab_error_oneof: GrabErrorOneof | null; +export interface SessionUnavailable { } -export interface Aborted { +export interface Process { + message: string; +} +export interface NativeError { + severity: number; + kind: number; + message: string; +} +export interface Input { + message: string; +} +export interface CompCommunication { + message: string; +} +export interface SearchCommunication { message: string; } export interface Sde { @@ -106,18 +64,48 @@ export enum Severity { Warning, Error, } -export interface Regex { +export interface DestinationPath { +} +export interface ComputationError { + comp_error_oneof: CompErrorOneof | null; +} +export interface SearchConfig { message: string; } -export interface Input { +export interface SearchIoOperation { + message: string; +} +export interface InvalidData { +} +export interface GrabConfig { + message: string; +} +export interface Grab { + error: GrabError | null; +} +export interface CompIoOperation { message: string; } export interface GrabIoOperation { message: string; } -export interface SearchConfig { +export interface MultipleInitCall { +} +export interface GrabCommunication { message: string; } +export interface GrabErrorOneof { + GrabConfig?: GrabConfig; + GrabCommunication?: GrabCommunication; + GrabIoOperation?: GrabIoOperation; + InvalidRange?: InvalidRange; + Interrupted?: Interrupted; + NotInitialize?: NotInitialize; + Unsupported?: Unsupported; +} +export interface GrabError { + grab_error_oneof: GrabErrorOneof | null; +} export interface SearchErrorOneof { SearchConfig?: SearchConfig; SearchCommunication?: SearchCommunication; @@ -127,15 +115,27 @@ export interface SearchErrorOneof { Grab?: Grab; Aborted?: Aborted; } -export interface CompCommunication { +export interface Regex { message: string; } -export interface SearchError { - search_error_oneof: SearchErrorOneof | null; +export interface Protocol { + message: string; } export interface OperationNotSupported { message: string; } -export interface SearchCommunication { - message: string; +export interface Grabbing { + error: GrabError | null; +} +export enum NativeErrorKind { + FileNotFound, + UnsupportedFileType, + ComputationFailed, + Configuration, + Interrupted, + OperationSearch, + NotYetImplemented, + ChannelError, + Io, + Grabber, } diff --git a/application/apps/rustcore/ts-bindings/src/protocol/event.ts b/application/apps/rustcore/ts-bindings/src/protocol/event.ts index 5813833786..5f7b9ad4f7 100644 --- a/application/apps/rustcore/ts-bindings/src/protocol/event.ts +++ b/application/apps/rustcore/ts-bindings/src/protocol/event.ts @@ -4,39 +4,10 @@ export interface DetailOneof { Notification?: Notification; Stopped?: boolean; } -import { NativeError } from "./error"; -export interface OperationError { - uuid: string; - error: NativeError | null; -} export interface SearchMapUpdated { update: string; } -import { AttachmentInfo } from "./attachment"; -export interface AttachmentsUpdated { - len: number; - attachment: AttachmentInfo | null; -} -export interface Progress { - uuid: string; - detail: ProgressDetail | null; -} -export interface SearchUpdated { - found: number; - stat: Map; -} -export interface ValueRange { - min: number; - max: number; -} -export interface Notification { - severity: number; - content: string; - line: number; -} -export interface SearchValuesUpdated { - values: Map; -} +import { NativeError } from "./error"; export interface EventOneof { StreamUpdated?: number; FileRead?: boolean; @@ -53,16 +24,45 @@ export interface EventOneof { OperationDone?: OperationDone; SessionDestroyed?: boolean; } -export interface ProgressDetail { - detail_oneof: DetailOneof | null; -} export interface IndexedMapUpdated { len: number; } +export interface CallbackEvent { + event_oneof: EventOneof | null; +} +export interface ProgressDetail { + detail_oneof: DetailOneof | null; +} export interface OperationDone { uuid: string; result: string; } -export interface CallbackEvent { - event_oneof: EventOneof | null; +export interface OperationError { + uuid: string; + error: NativeError | null; +} +export interface Notification { + severity: number; + content: string; + line: number; +} +export interface SearchUpdated { + found: number; + stat: Map; +} +export interface SearchValuesUpdated { + values: Map; +} +export interface ValueRange { + min: number; + max: number; +} +import { AttachmentInfo } from "./attachment"; +export interface AttachmentsUpdated { + len: number; + attachment: AttachmentInfo | null; +} +export interface Progress { + uuid: string; + detail: ProgressDetail | null; } diff --git a/application/apps/rustcore/ts-bindings/src/protocol/index.ts b/application/apps/rustcore/ts-bindings/src/protocol/index.ts index 0cb37c0bfd..d8bd37e6af 100644 --- a/application/apps/rustcore/ts-bindings/src/protocol/index.ts +++ b/application/apps/rustcore/ts-bindings/src/protocol/index.ts @@ -1,5 +1,5 @@ -export { Range } from "./common"; export { RangeInclusive } from "./common"; +export { Range } from "./common"; export { RangeInclusiveList } from "./common"; export { AttachmentInfo } from "./attachment"; export { AttachmentInfoList } from "./attachment"; diff --git a/application/apps/rustcore/ts-bindings/src/protocol/observe.ts b/application/apps/rustcore/ts-bindings/src/protocol/observe.ts index a2b4d53820..90c5a2b39b 100644 --- a/application/apps/rustcore/ts-bindings/src/protocol/observe.ts +++ b/application/apps/rustcore/ts-bindings/src/protocol/observe.ts @@ -1,57 +1,32 @@ -export interface DltParserSettings { - filter_config: DltFilterConfig | null; - fibex_file_paths: string[]; - with_storage_header: boolean; - tz: string; +export interface SerialTransportConfig { + path: string; + baud_rate: number; + data_bits: number; + flow_control: number; + parity: number; + stop_bits: number; + send_data_delay: number; + exclusive: boolean; } -export interface ObserveOptions { - origin: ObserveOrigin | null; - parser: ParserType | null; +export interface FileFormat { } -export interface TransportOneof { - Process?: ProcessTransportConfig; - Tcp?: TcpTransportConfig; - Udp?: UdpTransportConfig; - Serial?: SerialTransportConfig; +export interface MulticastInfo { + multiaddr: string; + interface: string; } -export interface TcpTransportConfig { - bind_addr: string; +export interface Concat { + files: File[]; } -export interface Transport { - transport_oneof: TransportOneof | null; +export interface TypeOneof { + Dlt?: DltParserSettings; + SomeIp?: SomeIpParserSettings; + Text?: boolean; } export interface ProcessTransportConfig { cwd: string; command: string; envs: Map; } -export enum Type { - PcapNg, - PcapLegacy, - Text, - Binary, -} -export interface SomeIpParserSettings { - fibex_file_paths: string[]; -} -export interface ObserveOrigin { - origin_oneof: OriginOneof | null; -} -export interface File { - name: string; - format: number; - path: string; -} -export interface MulticastInfo { - multiaddr: string; - interface: string; -} -export interface FileFormat { -} -export interface UdpTransportConfig { - bind_addr: string; - multicast: MulticastInfo[]; -} export interface DltFilterConfig { min_log_level: number; app_ids: string[]; @@ -65,28 +40,53 @@ export interface OriginOneof { Concat?: Concat; Stream?: Stream; } +export interface ObserveOptions { + origin: ObserveOrigin | null; + parser: ParserType | null; +} +export interface TransportOneof { + Process?: ProcessTransportConfig; + Tcp?: TcpTransportConfig; + Udp?: UdpTransportConfig; + Serial?: SerialTransportConfig; +} +export interface Stream { + name: string; + transport: Transport | null; +} +export interface File { + name: string; + format: number; + path: string; +} +export interface DltParserSettings { + filter_config: DltFilterConfig | null; + fibex_file_paths: string[]; + with_storage_header: boolean; + tz: string; +} +export interface SomeIpParserSettings { + fibex_file_paths: string[]; +} export interface ParserType { type_oneof: TypeOneof | null; } -export interface TypeOneof { - Dlt?: DltParserSettings; - SomeIp?: SomeIpParserSettings; - Text?: boolean; +export enum Type { + PcapNg, + PcapLegacy, + Text, + Binary, } -export interface SerialTransportConfig { - path: string; - baud_rate: number; - data_bits: number; - flow_control: number; - parity: number; - stop_bits: number; - send_data_delay: number; - exclusive: boolean; +export interface ObserveOrigin { + origin_oneof: OriginOneof | null; } -export interface Concat { - files: File[]; +export interface TcpTransportConfig { + bind_addr: string; } -export interface Stream { - name: string; - transport: Transport | null; +export interface UdpTransportConfig { + bind_addr: string; + multicast: MulticastInfo[]; +} +export interface Transport { + transport_oneof: TransportOneof | null; } diff --git a/application/apps/rustcore/ts-bindings/src/protocol/progress.ts b/application/apps/rustcore/ts-bindings/src/protocol/progress.ts index 56b4bf1125..44f8fe8d64 100644 --- a/application/apps/rustcore/ts-bindings/src/protocol/progress.ts +++ b/application/apps/rustcore/ts-bindings/src/protocol/progress.ts @@ -1,17 +1,8 @@ -export interface Started { - uuid: string; - alias: string; -} export interface TransitionOneof { Started?: Started; Ticks?: TicksWithUuid; Stopped?: Stopped; } -export interface Ticks { - count: number; - state: string; - total: number; -} export interface LifecycleTransition { transition_oneof: TransitionOneof | null; } @@ -19,6 +10,15 @@ export interface TicksWithUuid { uuid: string; ticks: Ticks | null; } +export interface Ticks { + count: number; + state: string; + total: number; +} export interface Stopped { uuid: string; } +export interface Started { + uuid: string; + alias: string; +} diff --git a/application/apps/rustcore/ts-bindings/src/protocol/convertor.ts b/application/apps/rustcore/ts-bindings/src/util/convertor.ts similarity index 99% rename from application/apps/rustcore/ts-bindings/src/protocol/convertor.ts rename to application/apps/rustcore/ts-bindings/src/util/convertor.ts index de3d450471..414f1f43c0 100644 --- a/application/apps/rustcore/ts-bindings/src/protocol/convertor.ts +++ b/application/apps/rustcore/ts-bindings/src/util/convertor.ts @@ -2,11 +2,11 @@ import { IObserve, Observe } from 'platform/types/observe'; import { Attachment, IGrabbedElement } from 'platform/types/content'; -import { getValidNum } from '../util/numbers'; +import { getValidNum } from './numbers'; import { IRange } from 'platform/types/range'; import * as proto from 'protocol'; -import * as ty from './index'; +import * as ty from '../protocol/index'; import * as $ from 'platform/types/observe'; import * as sde from 'platform/types/sde'; diff --git a/scripts/elements/protocol.rb b/scripts/elements/protocol.rb index ec555b7f19..0d47461969 100644 --- a/scripts/elements/protocol.rb +++ b/scripts/elements/protocol.rb @@ -3,9 +3,12 @@ require './scripts/env/paths' require './scripts/tools/change_checker' require './scripts/tools/reporter' +require 'fileutils' module Protocol PKG = "#{Paths::PROTOCOL_WASM}/pkg" + OUTPUT = "#{Paths::PROTOCOL_GEN}/output" + TS_DEST = "#{Paths::TS_BINDINGS}/src/protocol" TARGET = "#{Paths::PROTOCOL_WASM}/target" TARGETS = [PKG, TARGET].freeze end @@ -23,21 +26,28 @@ module Protocol desc 'Build protocol' task build: ['environment:check'] do - changes_to_files = ChangeChecker.changes?('protocol', Paths::PROTOCOL_WASM) - if changes_to_files || !File.exist?(Protocol::PKG) - duration = 0 - [Protocol::PKG, Protocol::TARGET].each do |path| - Shell.rm_rf(path) - Reporter.removed('protocol', File.basename(path), '') - end - Shell.chdir(Paths::PROTOCOL_WASM) do - duration += Shell.timed_sh 'wasm-pack build --target nodejs', 'wasm-pack build --target nodejs' - ChangeChecker.reset('protocol', Paths::PROTOCOL_WASM, Protocol::TARGETS) - end - Reporter.done('protocol', "build #{Protocol::TARGET}", '', duration) - else - Reporter.skipped('protocol', 'already built', '') + duration = 0 + # Cleanup + [Protocol::PKG, Protocol::TARGET, Protocol::OUTPUT, Protocol::TS_DEST].each do |path| + Shell.rm_rf(path) + Reporter.removed('protocol', File.basename(path), '') + end + # Generate *.ts files based on protobuf scheme + Shell.chdir(Paths::PROTOCOL_GEN) do + ENV['TSLINK_BUILD'] = 'true' + duration += Shell.timed_sh 'cargo clean', 'cleaning proto' + duration += Shell.timed_sh 'cargo build', 'generating proto' + ENV['TSLINK_BUILD'] = 'false' + end + # Copy *.ts files into ts-bindings + FileUtils.mkdir_p "#{Protocol::TS_DEST}" + FileUtils.cp_r("#{Protocol::OUTPUT}/.", "#{Protocol::TS_DEST}/.", verbose: true) + # Generate wasm module + Shell.chdir(Paths::PROTOCOL_WASM) do + duration += Shell.timed_sh 'wasm-pack build --target nodejs', 'wasm-pack build --target nodejs' + ChangeChecker.reset('protocol', Paths::PROTOCOL_WASM, Protocol::TARGETS) end + Reporter.done('protocol', "build #{Protocol::TARGET}", '', duration) Reporter.print end diff --git a/scripts/env/paths.rb b/scripts/env/paths.rb index 4768ee454e..8edf592bae 100644 --- a/scripts/env/paths.rb +++ b/scripts/env/paths.rb @@ -74,4 +74,5 @@ def self.release_resources_folder UPDATER = "#{APPS}/precompiled/updater" PROTOCOL_WASM = "#{APPS}/protocol/binding/wasm" + PROTOCOL_GEN = "#{APPS}/protocol/binding/proto" end