First Commit
Yes, that is what I do at 31.12.2021 at 22:39 local time...
This commit is contained in:
33
examples/example.binc
Normal file
33
examples/example.binc
Normal file
@ -0,0 +1,33 @@
|
||||
import "./import.binc";
|
||||
|
||||
enum TestEnum {
|
||||
VAL1,
|
||||
VAL2,
|
||||
VAL10 = 10,
|
||||
VAL11,
|
||||
VAL12
|
||||
}
|
||||
|
||||
type Test {
|
||||
atom: TestAtom;
|
||||
array: TestAtom[];
|
||||
enumValue: TestEnum;
|
||||
map: {number, TestAtom};
|
||||
}
|
||||
|
||||
|
||||
type AddValueRequest {
|
||||
value1: number;
|
||||
value2: number;
|
||||
}
|
||||
|
||||
type AddValueResponse {
|
||||
value: number;
|
||||
}
|
||||
|
||||
service TestService {
|
||||
AddValuesSingleParam(request: AddValueRequest): AddValueResponse;
|
||||
AddValuesMultipleParams(value1: number, value2: number): number;
|
||||
|
||||
notification OnEvent(param1: string);
|
||||
}
|
5
examples/import.binc
Normal file
5
examples/import.binc
Normal file
@ -0,0 +1,5 @@
|
||||
type TestAtom {
|
||||
val_number: number;
|
||||
val_boolean: boolean;
|
||||
val_string: string;
|
||||
}
|
54
examples/test.ts
Normal file
54
examples/test.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { AddValueRequest, AddValueResponse, Logging } from "./out/index"
|
||||
|
||||
|
||||
// Logging.verbose = false;
|
||||
|
||||
import * as Client from "./out/index_client"
|
||||
import * as Server from "./out/index_server"
|
||||
|
||||
const client = new Client.ServiceProvider(msg=>{
|
||||
session.onMessage(msg);
|
||||
})
|
||||
|
||||
const server = new Server.ServiceProvider()
|
||||
|
||||
const session = server.getSession((msg) => {
|
||||
client.onPacket(msg);
|
||||
})
|
||||
|
||||
class TestService extends Server.TestService<undefined> {
|
||||
async AddValuesSingleParam(request: AddValueRequest, ctx: undefined): Promise<AddValueResponse> {
|
||||
return {
|
||||
value: request.value1 + request.value2
|
||||
}
|
||||
}
|
||||
async AddValuesMultipleParams(value1: number, value2: number, ctx: undefined): Promise<number> {
|
||||
return value1 + value2;
|
||||
}
|
||||
|
||||
OnEvent(param1: string, ctx: undefined): void {
|
||||
console.log("Received notification", param1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
server.addService(new TestService())
|
||||
|
||||
const test = new Client.TestService(client);
|
||||
|
||||
async function run() {
|
||||
console.log("Testing AddValuesSingleParam")
|
||||
console.log(await test.AddValuesSingleParam({
|
||||
value1: 1,
|
||||
value2: 2
|
||||
}));
|
||||
|
||||
console.log("Testing AddValuesMultipleParams")
|
||||
console.log(await test.AddValuesMultipleParams(1,2));
|
||||
|
||||
console.log("Testing Notification")
|
||||
test.OnEvent("Hi, this is an event");
|
||||
}
|
||||
|
||||
run();
|
||||
|
Reference in New Issue
Block a user