Skip to content

Commit

Permalink
Fix parsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Sep 11, 2024
1 parent 49657e1 commit 92fc528
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions application/apps/rustcore/ts-bindings/src/protocol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export function toObserveOptions(source: IObserve): ObserveOptions {
return { origin: { origin }, parser };
}

export function decodeLifecycleTransition(buf: number[]): any {
export function decodeLifecycleTransition(buf: number[] | Buffer): any {
const event: LifecycleTransition = proto.LifecycleTransition.decode(Uint8Array.from(buf));
if (!event.transition) {
return {};
Expand Down Expand Up @@ -316,7 +316,7 @@ export function decodeLifecycleTransition(buf: number[]): any {
throw new Error(`Fail to parse event: ${JSON.stringify(event)}`);
}
}
export function decodeCallbackEvent(buf: number[]): any {
export function decodeCallbackEvent(buf: number[] | Buffer): any {
const event: CallbackEvent = proto.CallbackEvent.decode(Uint8Array.from(buf));
if (!event.event) {
return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface IOrderStat {
duration: number;
}

export type Decoder = (buf: number[]) => any;
export type Decoder = (buf: number[] | Buffer) => any;

export abstract class Computation<TEvents, IEventsSignatures, IEventsInterfaces> {
private _destroyed: boolean = false;
Expand Down Expand Up @@ -233,7 +233,7 @@ export abstract class Computation<TEvents, IEventsSignatures, IEventsInterfaces>
private _emitter(data: TEventData) {
function dataAsStr(data: TEventData): { debug: string; verb?: string } {
let message = '';
if (data instanceof Array) {
if (data instanceof Array || data instanceof Buffer) {
message = `(as bytes): ${data.join(',')}`;
} else if (typeof data === 'string') {
message = `(as string): ${data}`;
Expand All @@ -254,7 +254,7 @@ export abstract class Computation<TEvents, IEventsSignatures, IEventsInterfaces>
logs.verb !== undefined && this.logger.verbose(`Event from rust:\n\t${logs.verb}`);
let event: Required<IEventData>;
try {
if (data instanceof Array) {
if (data instanceof Array || data instanceof Buffer) {
event = this._decoder(data);
} else if (typeof data === 'string') {
try {
Expand All @@ -280,7 +280,7 @@ export abstract class Computation<TEvents, IEventsSignatures, IEventsInterfaces>
event === null ||
Object.keys(event).length !== 1
) {
const msg: string = `Has been gotten incorrect event data: ${data}. No any props field found.\nExpecting type (JSON string): { [type: string]: string | undefined }`;
const msg: string = `Has been gotten incorrect event data: ${data} (type: ${typeof data}). No any props field found.\nExpecting type (JSON string): { [type: string]: string | undefined }`;
this.debug().emit.error(msg);
this.logger.error(msg);
} else {
Expand Down

0 comments on commit 92fc528

Please sign in to comment.