Skip to content

Instantly share code, notes, and snippets.

@snluu
Created January 11, 2020 18:14
Show Gist options
  • Save snluu/f53da4960ab9305dfbdbe56ff423a585 to your computer and use it in GitHub Desktop.
Save snluu/f53da4960ab9305dfbdbe56ff423a585 to your computer and use it in GitHub Desktop.
"use strict";
class Test_Location {
get name() {
return this._name;
}
set name(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'name'";
}
this._name = val;
}
get lat() {
return this._lat;
}
set lat(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'lat'";
}
this._lat = val;
}
get lon() {
return this._lon;
}
set lon(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'lon'";
}
this._lon = val;
}
rpcSerialize() {
const sb = [];
sb.push("O3\n");
sb.push("p1\n");
sb.push(this._name.rpcSerialize());
sb.push("p2\n");
sb.push(this._lat.rpcSerialize());
sb.push("p3\n");
sb.push(this._lon.rpcSerialize());
return sb.join("");
}
constructor() {
this._name = "";
this._lat = 0;
this._lon = 0;
}
}
class Test_Animal {
get name() {
return this._name;
}
set name(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'name'";
}
this._name = val;
}
get maxSpeed() {
return this._maxSpeed;
}
set maxSpeed(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'maxSpeed'";
}
this._maxSpeed = val;
}
rpcSerialize() {
const sb = [];
sb.push("O2\n");
sb.push("p1\n");
sb.push(this._name.rpcSerialize());
sb.push("p2\n");
sb.push(this._maxSpeed.rpcSerialize());
return sb.join("");
}
constructor() {
this._name = "";
this._maxSpeed = 0;
}
}
class Test_Person {
get id() {
return this._id;
}
set id(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'id'";
}
this._id = val;
}
get age() {
return this._age;
}
set age(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'age'";
}
this._age = val;
}
get name() {
return this._name;
}
set name(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'name'";
}
this._name = val;
}
get leftHanded() {
return this._leftHanded;
}
set leftHanded(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'leftHanded'";
}
this._leftHanded = val;
}
get emails() {
return this._emails;
}
set emails(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'emails'";
}
this._emails = val;
}
get nicknames() {
return this._nicknames;
}
set nicknames(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'nicknames'";
}
this._nicknames = val;
}
get favNumbers() {
return this._favNumbers;
}
set favNumbers(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'favNumbers'";
}
this._favNumbers = val;
}
get jobs() {
return this._jobs;
}
set jobs(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'jobs'";
}
this._jobs = val;
}
get pets() {
return this._pets;
}
set pets(val) {
if (val === null || val === undefined) {
throw "Cannot set null or undefined value for 'pets'";
}
this._pets = val;
}
rpcSerialize() {
const sb = [];
sb.push("O9\n");
sb.push("p0\n");
sb.push(this._id.rpcSerialize());
sb.push("p5\n");
sb.push(this._age.rpcSerialize());
sb.push("p1\n");
sb.push(this._name.rpcSerialize());
sb.push("p2\n");
sb.push(this._leftHanded.rpcSerialize());
sb.push("p3\n");
sb.push(this._emails.rpcSerialize());
sb.push("p4\n");
sb.push(this._nicknames.rpcSerialize());
sb.push("p6\n");
sb.push(this._favNumbers.rpcSerialize());
sb.push("p7\n");
sb.push(this._jobs.rpcSerialize());
sb.push("p9\n");
sb.push(this._pets.rpcSerialize());
return sb.join("");
}
constructor() {
this._id = 0;
this._age = 0;
this._name = "";
this._leftHanded = false;
this._emails = [];
this._nicknames = new Set();
this._favNumbers = new Set();
this._jobs = new Map();
this._pets = new Map();
}
}
class Test_PeopleServiceClient {
async getName(payload) {
const url = this.host + "/get_name";
const req = new TxtRPC_Request(payload);
const httpResponse = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "plain/text; charset=UTF-8",
"Access-Control-Allow-Origin": "*",
},
body: req.rpcSerialize(),
});
if (httpResponse.status !== 200 && httpResponse.status !== 400 && httpResponse.status !== 500) {
console.log(httpResponse);
throw "Failed to perform request for /get_name";
}
const buff = await httpResponse.arrayBuffer();
const bytes = new Uint8Array(buff);
return TxtRPC_Response.fromRPC(bytes, String.rpcDeserialize);
}
async getNames(payload) {
const url = this.host + "/get_names";
const req = new TxtRPC_Request(payload);
const httpResponse = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "plain/text; charset=UTF-8",
"Access-Control-Allow-Origin": "*",
},
body: req.rpcSerialize(),
});
if (httpResponse.status !== 200 && httpResponse.status !== 400 && httpResponse.status !== 500) {
console.log(httpResponse);
throw "Failed to perform request for /get_names";
}
const buff = await httpResponse.arrayBuffer();
const bytes = new Uint8Array(buff);
return TxtRPC_Response.fromRPC(bytes, Map.buildRPCDeserializeFunc(Number.rpcDeserialize, String.rpcDeserialize));
}
async getPerson(payload) {
const url = this.host + "/get_person";
const req = new TxtRPC_Request(payload);
const httpResponse = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "plain/text; charset=UTF-8",
"Access-Control-Allow-Origin": "*",
},
body: req.rpcSerialize(),
});
if (httpResponse.status !== 200 && httpResponse.status !== 400 && httpResponse.status !== 500) {
console.log(httpResponse);
throw "Failed to perform request for /get_person";
}
const buff = await httpResponse.arrayBuffer();
const bytes = new Uint8Array(buff);
return TxtRPC_Response.fromRPC(bytes, Test_Person.rpcDeserialize);
}
async getManyPeople(payload) {
const url = this.host + "/get_many_people";
const req = new TxtRPC_Request(payload);
const httpResponse = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "plain/text; charset=UTF-8",
"Access-Control-Allow-Origin": "*",
},
body: req.rpcSerialize(),
});
if (httpResponse.status !== 200 && httpResponse.status !== 400 && httpResponse.status !== 500) {
console.log(httpResponse);
throw "Failed to perform request for /get_many_people";
}
const buff = await httpResponse.arrayBuffer();
const bytes = new Uint8Array(buff);
return TxtRPC_Response.fromRPC(bytes, Map.buildRPCDeserializeFunc(Number.rpcDeserialize, Test_Person.rpcDeserialize));
}
async searchByName(payload) {
const url = this.host + "/search_by_name";
const req = new TxtRPC_Request(payload);
const httpResponse = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "plain/text; charset=UTF-8",
"Access-Control-Allow-Origin": "*",
},
body: req.rpcSerialize(),
});
if (httpResponse.status !== 200 && httpResponse.status !== 400 && httpResponse.status !== 500) {
console.log(httpResponse);
throw "Failed to perform request for /search_by_name";
}
const buff = await httpResponse.arrayBuffer();
const bytes = new Uint8Array(buff);
return TxtRPC_Response.fromRPC(bytes, Array.buildRPCDeserializeFunc(Test_Person.rpcDeserialize));
}
constructor(host) {
if (!host || host === "") {
throw "Service host cannot be empty";
}
this.host = host;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment