mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 16:40:02 +00:00
Updating working code (#6441)
Fixes issues with namespaces in grpc ts Renamed welcome -> models
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -139,3 +139,4 @@ yarn-error.log
|
|||||||
.cache/
|
.cache/
|
||||||
/flatbuffers.lib
|
/flatbuffers.lib
|
||||||
.cmake/
|
.cmake/
|
||||||
|
**/dist
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
import grpc from 'grpc';
|
import grpc from 'grpc';
|
||||||
import { HelloRequest } from './greeter_generated';
|
import { HelloReply } from './models/hello-reply';
|
||||||
|
import { HelloRequest } from './models/hello-request';
|
||||||
import { GreeterClient } from './greeter_grpc';
|
import { GreeterClient } from './greeter_grpc';
|
||||||
import { flatbuffers } from 'flatbuffers';
|
import { flatbuffers } from 'flatbuffers';
|
||||||
|
|
||||||
async function main() {
|
async function main(PORT: Number) {
|
||||||
const _server = new GreeterClient('localhost:3000', grpc.credentials.createInsecure());
|
const _server = new GreeterClient(`localhost:${PORT}`, grpc.credentials.createInsecure());
|
||||||
const builder = new flatbuffers.Builder();
|
const builder = new flatbuffers.Builder();
|
||||||
const offset = builder.createString('mustii');
|
const offset = builder.createString('mustii');
|
||||||
const root = HelloRequest.createHelloRequest(builder, offset);
|
const root = HelloRequest.createHelloRequest(builder, offset);
|
||||||
@@ -25,4 +26,9 @@ async function main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
var PORT = Number(process.argv.slice(2));
|
||||||
|
if (PORT) {
|
||||||
|
main(PORT);
|
||||||
|
} else {
|
||||||
|
throw new Error("Requires a valid port number.")
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
namespace models;
|
||||||
|
|
||||||
table HelloReply {
|
table HelloReply {
|
||||||
message:string;
|
message:string;
|
||||||
}
|
}
|
||||||
@@ -7,6 +9,6 @@ table HelloRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rpc_service Greeter {
|
rpc_service Greeter {
|
||||||
SayHello(HelloRequest):HelloReply;
|
SayHello(models.HelloRequest):models.HelloReply;
|
||||||
SayManyHellos(HelloRequest):HelloReply (streaming: "server");
|
SayManyHellos(models.HelloRequest):models.HelloReply (streaming: "server");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,174 +0,0 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
export class HelloReply {
|
|
||||||
bb: flatbuffers.ByteBuffer|null = null;
|
|
||||||
|
|
||||||
bb_pos:number = 0;
|
|
||||||
/**
|
|
||||||
* @param number i
|
|
||||||
* @param flatbuffers.ByteBuffer bb
|
|
||||||
* @returns HelloReply
|
|
||||||
*/
|
|
||||||
__init(i:number, bb:flatbuffers.ByteBuffer):HelloReply {
|
|
||||||
this.bb_pos = i;
|
|
||||||
this.bb = bb;
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.ByteBuffer bb
|
|
||||||
* @param HelloReply= obj
|
|
||||||
* @returns HelloReply
|
|
||||||
*/
|
|
||||||
static getRootAsHelloReply(bb:flatbuffers.ByteBuffer, obj?:HelloReply):HelloReply {
|
|
||||||
return (obj || new HelloReply()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.ByteBuffer bb
|
|
||||||
* @param HelloReply= obj
|
|
||||||
* @returns HelloReply
|
|
||||||
*/
|
|
||||||
static getSizePrefixedRootAsHelloReply(bb:flatbuffers.ByteBuffer, obj?:HelloReply):HelloReply {
|
|
||||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
|
||||||
return (obj || new HelloReply()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.Encoding= optionalEncoding
|
|
||||||
* @returns string|Uint8Array|null
|
|
||||||
*/
|
|
||||||
message():string|null
|
|
||||||
message(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
|
||||||
message(optionalEncoding?:any):string|Uint8Array|null {
|
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 4);
|
|
||||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.Builder builder
|
|
||||||
*/
|
|
||||||
static startHelloReply(builder:flatbuffers.Builder) {
|
|
||||||
builder.startObject(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.Builder builder
|
|
||||||
* @param flatbuffers.Offset messageOffset
|
|
||||||
*/
|
|
||||||
static addMessage(builder:flatbuffers.Builder, messageOffset:flatbuffers.Offset) {
|
|
||||||
builder.addFieldOffset(0, messageOffset, 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.Builder builder
|
|
||||||
* @returns flatbuffers.Offset
|
|
||||||
*/
|
|
||||||
static endHelloReply(builder:flatbuffers.Builder):flatbuffers.Offset {
|
|
||||||
var offset = builder.endObject();
|
|
||||||
return offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
static createHelloReply(builder:flatbuffers.Builder, messageOffset:flatbuffers.Offset):flatbuffers.Offset {
|
|
||||||
HelloReply.startHelloReply(builder);
|
|
||||||
HelloReply.addMessage(builder, messageOffset);
|
|
||||||
return HelloReply.endHelloReply(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
serialize():Uint8Array {
|
|
||||||
return this.bb!.bytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
static deserialize(buffer: Uint8Array):HelloReply {
|
|
||||||
return HelloReply.getRootAsHelloReply(new flatbuffers.ByteBuffer(buffer))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
export class HelloRequest {
|
|
||||||
bb: flatbuffers.ByteBuffer|null = null;
|
|
||||||
|
|
||||||
bb_pos:number = 0;
|
|
||||||
/**
|
|
||||||
* @param number i
|
|
||||||
* @param flatbuffers.ByteBuffer bb
|
|
||||||
* @returns HelloRequest
|
|
||||||
*/
|
|
||||||
__init(i:number, bb:flatbuffers.ByteBuffer):HelloRequest {
|
|
||||||
this.bb_pos = i;
|
|
||||||
this.bb = bb;
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.ByteBuffer bb
|
|
||||||
* @param HelloRequest= obj
|
|
||||||
* @returns HelloRequest
|
|
||||||
*/
|
|
||||||
static getRootAsHelloRequest(bb:flatbuffers.ByteBuffer, obj?:HelloRequest):HelloRequest {
|
|
||||||
return (obj || new HelloRequest()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.ByteBuffer bb
|
|
||||||
* @param HelloRequest= obj
|
|
||||||
* @returns HelloRequest
|
|
||||||
*/
|
|
||||||
static getSizePrefixedRootAsHelloRequest(bb:flatbuffers.ByteBuffer, obj?:HelloRequest):HelloRequest {
|
|
||||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
|
||||||
return (obj || new HelloRequest()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.Encoding= optionalEncoding
|
|
||||||
* @returns string|Uint8Array|null
|
|
||||||
*/
|
|
||||||
name():string|null
|
|
||||||
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
|
||||||
name(optionalEncoding?:any):string|Uint8Array|null {
|
|
||||||
var offset = this.bb!.__offset(this.bb_pos, 4);
|
|
||||||
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.Builder builder
|
|
||||||
*/
|
|
||||||
static startHelloRequest(builder:flatbuffers.Builder) {
|
|
||||||
builder.startObject(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.Builder builder
|
|
||||||
* @param flatbuffers.Offset nameOffset
|
|
||||||
*/
|
|
||||||
static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) {
|
|
||||||
builder.addFieldOffset(0, nameOffset, 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param flatbuffers.Builder builder
|
|
||||||
* @returns flatbuffers.Offset
|
|
||||||
*/
|
|
||||||
static endHelloRequest(builder:flatbuffers.Builder):flatbuffers.Offset {
|
|
||||||
var offset = builder.endObject();
|
|
||||||
return offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
static createHelloRequest(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):flatbuffers.Offset {
|
|
||||||
HelloRequest.startHelloRequest(builder);
|
|
||||||
HelloRequest.addName(builder, nameOffset);
|
|
||||||
return HelloRequest.endHelloRequest(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
serialize():Uint8Array {
|
|
||||||
return this.bb!.bytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
static deserialize(buffer: Uint8Array):HelloRequest {
|
|
||||||
return HelloRequest.getRootAsHelloRequest(new flatbuffers.ByteBuffer(buffer))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
51
grpc/flatbuffers-js-grpc/src/greeter_grpc.d.ts
vendored
51
grpc/flatbuffers-js-grpc/src/greeter_grpc.d.ts
vendored
@@ -1,6 +1,7 @@
|
|||||||
// Generated GRPC code for FlatBuffers TS *** DO NOT EDIT ***
|
// Generated GRPC code for FlatBuffers TS *** DO NOT EDIT ***
|
||||||
import { flatbuffers } from 'flatbuffers';
|
import { flatbuffers } from 'flatbuffers';
|
||||||
import * as Greeter_fbs from './greeter_generated';
|
import { HelloReply as models_HelloReply } from './models/hello-reply';
|
||||||
|
import { HelloRequest as models_HelloRequest } from './models/hello-request';
|
||||||
|
|
||||||
import * as grpc from 'grpc';
|
import * as grpc from 'grpc';
|
||||||
|
|
||||||
@@ -8,47 +9,47 @@ interface IGreeterService extends grpc.ServiceDefinition<grpc.UntypedServiceImpl
|
|||||||
SayHello: IGreeterService_ISayHello;
|
SayHello: IGreeterService_ISayHello;
|
||||||
SayManyHellos: IGreeterService_ISayManyHellos;
|
SayManyHellos: IGreeterService_ISayManyHellos;
|
||||||
}
|
}
|
||||||
interface IGreeterService_ISayHello extends grpc.MethodDefinition<Greeter_fbs.HelloRequest, Greeter_fbs.HelloReply> {
|
interface IGreeterService_ISayHello extends grpc.MethodDefinition<models_HelloRequest, models_HelloReply> {
|
||||||
path: string; // /Greeter/SayHello
|
path: string; // /models.Greeter/SayHello
|
||||||
requestStream: boolean; // false
|
requestStream: boolean; // false
|
||||||
responseStream: boolean; // false
|
responseStream: boolean; // false
|
||||||
requestSerialize: grpc.serialize<Greeter_fbs.HelloRequest>;
|
requestSerialize: grpc.serialize<models_HelloRequest>;
|
||||||
requestDeserialize: grpc.deserialize<Greeter_fbs.HelloRequest>;
|
requestDeserialize: grpc.deserialize<models_HelloRequest>;
|
||||||
responseSerialize: grpc.serialize<Greeter_fbs.HelloReply>;
|
responseSerialize: grpc.serialize<models_HelloReply>;
|
||||||
responseDeserialize: grpc.deserialize<Greeter_fbs.HelloReply>;
|
responseDeserialize: grpc.deserialize<models_HelloReply>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IGreeterService_ISayManyHellos extends grpc.MethodDefinition<Greeter_fbs.HelloRequest, Greeter_fbs.HelloReply> {
|
interface IGreeterService_ISayManyHellos extends grpc.MethodDefinition<models_HelloRequest, models_HelloReply> {
|
||||||
path: string; // /Greeter/SayManyHellos
|
path: string; // /models.Greeter/SayManyHellos
|
||||||
requestStream: boolean; // false
|
requestStream: boolean; // false
|
||||||
responseStream: boolean; // true
|
responseStream: boolean; // true
|
||||||
requestSerialize: grpc.serialize<Greeter_fbs.HelloRequest>;
|
requestSerialize: grpc.serialize<models_HelloRequest>;
|
||||||
requestDeserialize: grpc.deserialize<Greeter_fbs.HelloRequest>;
|
requestDeserialize: grpc.deserialize<models_HelloRequest>;
|
||||||
responseSerialize: grpc.serialize<Greeter_fbs.HelloReply>;
|
responseSerialize: grpc.serialize<models_HelloReply>;
|
||||||
responseDeserialize: grpc.deserialize<Greeter_fbs.HelloReply>;
|
responseDeserialize: grpc.deserialize<models_HelloReply>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const GreeterService: IGreeterService;
|
export const GreeterService: IGreeterService;
|
||||||
|
|
||||||
export interface IGreeterServer {
|
export interface IGreeterServer {
|
||||||
SayHello: grpc.handleUnaryCall<Greeter_fbs.HelloRequest, Greeter_fbs.HelloReply>;
|
SayHello: grpc.handleUnaryCall<models_HelloRequest, models_HelloReply>;
|
||||||
SayManyHellos: grpc.handleServerStreamingCall<Greeter_fbs.HelloRequest, Greeter_fbs.HelloReply>;
|
SayManyHellos: grpc.handleServerStreamingCall<models_HelloRequest, models_HelloReply>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IGreeterClient {
|
export interface IGreeterClient {
|
||||||
SayHello(request: Greeter_fbs.HelloRequest, callback: (error: grpc.ServiceError | null, response: Greeter_fbs.HelloReply) => void): grpc.ClientUnaryCall;
|
SayHello(request: models_HelloRequest, callback: (error: grpc.ServiceError | null, response: models_HelloReply) => void): grpc.ClientUnaryCall;
|
||||||
SayHello(request: Greeter_fbs.HelloRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: Greeter_fbs.HelloReply) => void): grpc.ClientUnaryCall;
|
SayHello(request: models_HelloRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: models_HelloReply) => void): grpc.ClientUnaryCall;
|
||||||
SayHello(request: Greeter_fbs.HelloRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: Greeter_fbs.HelloReply) => void): grpc.ClientUnaryCall;
|
SayHello(request: models_HelloRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: models_HelloReply) => void): grpc.ClientUnaryCall;
|
||||||
SayManyHellos(request: Greeter_fbs.HelloRequest, metadata: grpc.Metadata): grpc.ClientReadableStream<Greeter_fbs.HelloReply>;
|
SayManyHellos(request: models_HelloRequest, metadata: grpc.Metadata): grpc.ClientReadableStream<models_HelloReply>;
|
||||||
SayManyHellos(request: Greeter_fbs.HelloRequest, options: Partial<grpc.CallOptions>): grpc.ClientReadableStream<Greeter_fbs.HelloReply>;
|
SayManyHellos(request: models_HelloRequest, options: Partial<grpc.CallOptions>): grpc.ClientReadableStream<models_HelloReply>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GreeterClient extends grpc.Client implements IGreeterClient {
|
export class GreeterClient extends grpc.Client implements IGreeterClient {
|
||||||
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object); public SayHello(request: Greeter_fbs.HelloRequest, callback: (error: grpc.ServiceError | null, response: Greeter_fbs.HelloReply) => void): grpc.ClientUnaryCall;
|
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object); public SayHello(request: models_HelloRequest, callback: (error: grpc.ServiceError | null, response: models_HelloReply) => void): grpc.ClientUnaryCall;
|
||||||
public SayHello(request: Greeter_fbs.HelloRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: Greeter_fbs.HelloReply) => void): grpc.ClientUnaryCall;
|
public SayHello(request: models_HelloRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: models_HelloReply) => void): grpc.ClientUnaryCall;
|
||||||
public SayHello(request: Greeter_fbs.HelloRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: Greeter_fbs.HelloReply) => void): grpc.ClientUnaryCall;
|
public SayHello(request: models_HelloRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: models_HelloReply) => void): grpc.ClientUnaryCall;
|
||||||
public SayManyHellos(request: Greeter_fbs.HelloRequest, metadata: grpc.Metadata): grpc.ClientReadableStream<Greeter_fbs.HelloReply>;
|
public SayManyHellos(request: models_HelloRequest, metadata: grpc.Metadata): grpc.ClientReadableStream<models_HelloReply>;
|
||||||
public SayManyHellos(request: Greeter_fbs.HelloRequest, options: Partial<grpc.CallOptions>): grpc.ClientReadableStream<Greeter_fbs.HelloReply>;
|
public SayManyHellos(request: models_HelloRequest, options: Partial<grpc.CallOptions>): grpc.ClientReadableStream<models_HelloReply>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,55 +1,56 @@
|
|||||||
// Generated GRPC code for FlatBuffers TS *** DO NOT EDIT ***
|
// Generated GRPC code for FlatBuffers TS *** DO NOT EDIT ***
|
||||||
import { flatbuffers } from 'flatbuffers';
|
import { flatbuffers } from 'flatbuffers';
|
||||||
import * as Greeter_fbs from './greeter_generated';
|
import { HelloReply as models_HelloReply } from './models/hello-reply';
|
||||||
|
import { HelloRequest as models_HelloRequest } from './models/hello-request';
|
||||||
|
|
||||||
var grpc = require('grpc');
|
var grpc = require('grpc');
|
||||||
|
|
||||||
function serialize_HelloReply(buffer_args) {
|
function serialize_models_HelloReply(buffer_args) {
|
||||||
if (!(buffer_args instanceof Greeter_fbs.HelloReply)) {
|
if (!(buffer_args instanceof models_HelloReply)) {
|
||||||
throw new Error('Expected argument of type Greeter_fbs.HelloReply');
|
throw new Error('Expected argument of type HelloReply');
|
||||||
}
|
}
|
||||||
return buffer_args.serialize();
|
return buffer_args.serialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_HelloReply(buffer) {
|
function deserialize_models_HelloReply(buffer) {
|
||||||
return Greeter_fbs.HelloReply.getRootAsHelloReply(new flatbuffers.ByteBuffer(buffer))
|
return models_HelloReply.getRootAsHelloReply(new flatbuffers.ByteBuffer(buffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function serialize_HelloRequest(buffer_args) {
|
function serialize_models_HelloRequest(buffer_args) {
|
||||||
if (!(buffer_args instanceof Greeter_fbs.HelloRequest)) {
|
if (!(buffer_args instanceof models_HelloRequest)) {
|
||||||
throw new Error('Expected argument of type Greeter_fbs.HelloRequest');
|
throw new Error('Expected argument of type HelloRequest');
|
||||||
}
|
}
|
||||||
return buffer_args.serialize();
|
return buffer_args.serialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
function deserialize_HelloRequest(buffer) {
|
function deserialize_models_HelloRequest(buffer) {
|
||||||
return Greeter_fbs.HelloRequest.getRootAsHelloRequest(new flatbuffers.ByteBuffer(buffer))
|
return models_HelloRequest.getRootAsHelloRequest(new flatbuffers.ByteBuffer(buffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var GreeterService = exports.GreeterService = {
|
var GreeterService = exports.GreeterService = {
|
||||||
SayHello: {
|
SayHello: {
|
||||||
path: '/Greeter/SayHello',
|
path: '/models.Greeter/SayHello',
|
||||||
requestStream: false,
|
requestStream: false,
|
||||||
responseStream: false,
|
responseStream: false,
|
||||||
requestType: flatbuffers.ByteBuffer,
|
requestType: flatbuffers.ByteBuffer,
|
||||||
responseType: Greeter_fbs.HelloReply,
|
responseType: models_HelloReply,
|
||||||
requestSerialize: serialize_HelloRequest,
|
requestSerialize: serialize_models_HelloRequest,
|
||||||
requestDeserialize: deserialize_HelloRequest,
|
requestDeserialize: deserialize_models_HelloRequest,
|
||||||
responseSerialize: serialize_HelloReply,
|
responseSerialize: serialize_models_HelloReply,
|
||||||
responseDeserialize: deserialize_HelloReply,
|
responseDeserialize: deserialize_models_HelloReply,
|
||||||
},
|
},
|
||||||
SayManyHellos: {
|
SayManyHellos: {
|
||||||
path: '/Greeter/SayManyHellos',
|
path: '/models.Greeter/SayManyHellos',
|
||||||
requestStream: false,
|
requestStream: false,
|
||||||
responseStream: true,
|
responseStream: true,
|
||||||
requestType: flatbuffers.ByteBuffer,
|
requestType: flatbuffers.ByteBuffer,
|
||||||
responseType: Greeter_fbs.HelloReply,
|
responseType: models_HelloReply,
|
||||||
requestSerialize: serialize_HelloRequest,
|
requestSerialize: serialize_models_HelloRequest,
|
||||||
requestDeserialize: deserialize_HelloRequest,
|
requestDeserialize: deserialize_models_HelloRequest,
|
||||||
responseSerialize: serialize_HelloReply,
|
responseSerialize: serialize_models_HelloReply,
|
||||||
responseDeserialize: deserialize_HelloReply,
|
responseDeserialize: deserialize_models_HelloReply,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
exports.GreeterClient = grpc.makeGenericClientConstructor(GreeterService);
|
exports.GreeterClient = grpc.makeGenericClientConstructor(GreeterService);
|
||||||
|
|||||||
58
grpc/flatbuffers-js-grpc/src/models/hello-reply.ts
Normal file
58
grpc/flatbuffers-js-grpc/src/models/hello-reply.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
import * as flatbuffers from 'flatbuffers';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export class HelloReply {
|
||||||
|
bb: flatbuffers.ByteBuffer|null = null;
|
||||||
|
bb_pos = 0;
|
||||||
|
__init(i:number, bb:flatbuffers.ByteBuffer):HelloReply {
|
||||||
|
this.bb_pos = i;
|
||||||
|
this.bb = bb;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getRootAsHelloReply(bb:flatbuffers.ByteBuffer, obj?:HelloReply):HelloReply {
|
||||||
|
return (obj || new HelloReply()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||||
|
}
|
||||||
|
|
||||||
|
static getSizePrefixedRootAsHelloReply(bb:flatbuffers.ByteBuffer, obj?:HelloReply):HelloReply {
|
||||||
|
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||||
|
return (obj || new HelloReply()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||||
|
}
|
||||||
|
|
||||||
|
message():string|null
|
||||||
|
message(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||||
|
message(optionalEncoding?:any):string|Uint8Array|null {
|
||||||
|
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||||
|
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static startHelloReply(builder:flatbuffers.Builder) {
|
||||||
|
builder.startObject(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static addMessage(builder:flatbuffers.Builder, messageOffset:flatbuffers.Offset) {
|
||||||
|
builder.addFieldOffset(0, messageOffset, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static endHelloReply(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||||
|
const offset = builder.endObject();
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
static createHelloReply(builder:flatbuffers.Builder, messageOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||||
|
HelloReply.startHelloReply(builder);
|
||||||
|
HelloReply.addMessage(builder, messageOffset);
|
||||||
|
return HelloReply.endHelloReply(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
serialize():Uint8Array {
|
||||||
|
return this.bb!.bytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
static deserialize(buffer: Uint8Array):HelloReply {
|
||||||
|
return HelloReply.getRootAsHelloReply(new flatbuffers.ByteBuffer(buffer))
|
||||||
|
}
|
||||||
|
}
|
||||||
58
grpc/flatbuffers-js-grpc/src/models/hello-request.ts
Normal file
58
grpc/flatbuffers-js-grpc/src/models/hello-request.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
import * as flatbuffers from 'flatbuffers';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export class HelloRequest {
|
||||||
|
bb: flatbuffers.ByteBuffer|null = null;
|
||||||
|
bb_pos = 0;
|
||||||
|
__init(i:number, bb:flatbuffers.ByteBuffer):HelloRequest {
|
||||||
|
this.bb_pos = i;
|
||||||
|
this.bb = bb;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getRootAsHelloRequest(bb:flatbuffers.ByteBuffer, obj?:HelloRequest):HelloRequest {
|
||||||
|
return (obj || new HelloRequest()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||||
|
}
|
||||||
|
|
||||||
|
static getSizePrefixedRootAsHelloRequest(bb:flatbuffers.ByteBuffer, obj?:HelloRequest):HelloRequest {
|
||||||
|
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||||
|
return (obj || new HelloRequest()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||||
|
}
|
||||||
|
|
||||||
|
name():string|null
|
||||||
|
name(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
|
||||||
|
name(optionalEncoding?:any):string|Uint8Array|null {
|
||||||
|
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||||
|
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static startHelloRequest(builder:flatbuffers.Builder) {
|
||||||
|
builder.startObject(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static addName(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset) {
|
||||||
|
builder.addFieldOffset(0, nameOffset, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static endHelloRequest(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||||
|
const offset = builder.endObject();
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
static createHelloRequest(builder:flatbuffers.Builder, nameOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||||
|
HelloRequest.startHelloRequest(builder);
|
||||||
|
HelloRequest.addName(builder, nameOffset);
|
||||||
|
return HelloRequest.endHelloRequest(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
serialize():Uint8Array {
|
||||||
|
return this.bb!.bytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
static deserialize(buffer: Uint8Array):HelloRequest {
|
||||||
|
return HelloRequest.getRootAsHelloRequest(new flatbuffers.ByteBuffer(buffer))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
import grpc from 'grpc';
|
import grpc from 'grpc';
|
||||||
import { HelloReply, HelloRequest } from './greeter_generated';
|
import { HelloReply } from './models/hello-reply';
|
||||||
|
import { HelloRequest } from './models/hello-request';
|
||||||
import { IGreeterServer, GreeterService } from './greeter_grpc';
|
import { IGreeterServer, GreeterService } from './greeter_grpc';
|
||||||
import { flatbuffers } from 'flatbuffers';
|
import { flatbuffers } from 'flatbuffers';
|
||||||
|
|
||||||
class GreeterServer implements IGreeterServer {
|
class GreeterServer implements IGreeterServer {
|
||||||
|
|
||||||
SayHello(call: grpc.ServerUnaryCall<HelloRequest>, callback: grpc.sendUnaryData<HelloReply>): void {
|
SayHello(call: grpc.ServerUnaryCall<HelloRequest>, callback: grpc.sendUnaryData<HelloReply>): void {
|
||||||
console.log(`${call.request.name()}`);
|
console.log(`SayHello ${call.request.name()}`);
|
||||||
const builder = new flatbuffers.Builder();
|
const builder = new flatbuffers.Builder();
|
||||||
const offset = builder.createString(`welcome ${call.request.name()}`);
|
const offset = builder.createString(`welcome ${call.request.name()}`);
|
||||||
const root = HelloReply.createHelloReply(builder, offset);
|
const root = HelloReply.createHelloReply(builder, offset);
|
||||||
|
|||||||
@@ -30,17 +30,79 @@
|
|||||||
|
|
||||||
namespace grpc_ts_generator {
|
namespace grpc_ts_generator {
|
||||||
|
|
||||||
|
grpc::string ToDasherizedCase(const grpc::string pascal_case) {
|
||||||
|
std::string dasherized_case;
|
||||||
|
char p = 0;
|
||||||
|
for (size_t i = 0; i < pascal_case.length(); i++) {
|
||||||
|
char const &c = pascal_case[i];
|
||||||
|
if (flatbuffers::is_alpha_upper(c)) {
|
||||||
|
if (i > 0 && p != flatbuffers::kPathSeparator) dasherized_case += "-";
|
||||||
|
dasherized_case += flatbuffers::CharToLower(c);
|
||||||
|
} else {
|
||||||
|
dasherized_case += c;
|
||||||
|
}
|
||||||
|
p = c;
|
||||||
|
}
|
||||||
|
return dasherized_case;
|
||||||
|
}
|
||||||
|
|
||||||
|
grpc::string GenerateNamespace(const std::vector<std::string> namepsace,
|
||||||
|
const std::string filename,
|
||||||
|
const bool include_separator) {
|
||||||
|
grpc::string path = "";
|
||||||
|
if (include_separator) path += ".";
|
||||||
|
|
||||||
|
for (auto it = namepsace.begin(); it < namepsace.end(); it++) {
|
||||||
|
if (include_separator) path += "/";
|
||||||
|
path += include_separator ? ToDasherizedCase(*it) : *it + "_";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (include_separator) path += "/";
|
||||||
|
path += include_separator ? ToDasherizedCase(filename) : filename;
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Shared code
|
// MARK: - Shared code
|
||||||
|
|
||||||
void GenerateImports(grpc_generator::Printer *printer,
|
void GenerateImports(const grpc_generator::Service *service,
|
||||||
|
grpc_generator::Printer *printer,
|
||||||
std::map<grpc::string, grpc::string> *dictonary,
|
std::map<grpc::string, grpc::string> *dictonary,
|
||||||
const bool grpc_var_import) {
|
const bool grpc_var_import) {
|
||||||
auto vars = *dictonary;
|
auto vars = *dictonary;
|
||||||
printer->Print(
|
printer->Print(
|
||||||
"// Generated GRPC code for FlatBuffers TS *** DO NOT EDIT ***\n");
|
"// Generated GRPC code for FlatBuffers TS *** DO NOT EDIT ***\n");
|
||||||
printer->Print("import { flatbuffers } from 'flatbuffers';\n");
|
printer->Print("import { flatbuffers } from 'flatbuffers';\n");
|
||||||
printer->Print(vars,
|
|
||||||
"import * as $FBSFile$ from './$Filename$_generated';\n");
|
std::set<grpc::string> generated_imports;
|
||||||
|
|
||||||
|
for (auto it = 0; it < service->method_count(); it++) {
|
||||||
|
auto method = service->method(it);
|
||||||
|
auto output = method->get_output_type_name();
|
||||||
|
auto input = method->get_input_type_name();
|
||||||
|
auto input_namespace = method->get_input_namespace_parts();
|
||||||
|
|
||||||
|
vars["OUTPUT"] = output;
|
||||||
|
vars["INPUT"] = input;
|
||||||
|
|
||||||
|
if (generated_imports.find(output) == generated_imports.end()) {
|
||||||
|
generated_imports.insert(output);
|
||||||
|
vars["OUTPUT_DIR"] =
|
||||||
|
GenerateNamespace(method->get_output_namespace_parts(), output, true);
|
||||||
|
vars["Output_alias"] = GenerateNamespace(
|
||||||
|
method->get_output_namespace_parts(), output, false);
|
||||||
|
printer->Print(
|
||||||
|
vars, "import { $OUTPUT$ as $Output_alias$ } from '$OUTPUT_DIR$';\n");
|
||||||
|
}
|
||||||
|
if (generated_imports.find(input) == generated_imports.end()) {
|
||||||
|
generated_imports.insert(input);
|
||||||
|
vars["INPUT_DIR"] =
|
||||||
|
GenerateNamespace(method->get_output_namespace_parts(), input, true);
|
||||||
|
vars["Input_alias"] =
|
||||||
|
GenerateNamespace(method->get_output_namespace_parts(), input, false);
|
||||||
|
printer->Print(
|
||||||
|
vars, "import { $INPUT$ as $Input_alias$ } from '$INPUT_DIR$';\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
printer->Print("\n");
|
printer->Print("\n");
|
||||||
if (grpc_var_import)
|
if (grpc_var_import)
|
||||||
printer->Print("var grpc = require('grpc');\n");
|
printer->Print("var grpc = require('grpc');\n");
|
||||||
@@ -68,10 +130,10 @@ void GenerateSerializeMethod(grpc_generator::Printer *printer,
|
|||||||
auto vars = *dictonary;
|
auto vars = *dictonary;
|
||||||
printer->Print(vars, "function serialize_$Type$(buffer_args) {\n");
|
printer->Print(vars, "function serialize_$Type$(buffer_args) {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
printer->Print(vars, "if (!(buffer_args instanceof $FBSFile$.$Type$)) {\n");
|
printer->Print(vars, "if (!(buffer_args instanceof $Type$)) {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
printer->Print(
|
printer->Print(vars,
|
||||||
vars, "throw new Error('Expected argument of type $FBSFile$.$Type$');\n");
|
"throw new Error('Expected argument of type $VALUE$');\n");
|
||||||
printer->Outdent();
|
printer->Outdent();
|
||||||
printer->Print("}\n");
|
printer->Print("}\n");
|
||||||
printer->Print(vars, "return buffer_args.serialize();\n");
|
printer->Print(vars, "return buffer_args.serialize();\n");
|
||||||
@@ -86,7 +148,7 @@ void GenerateDeserializeMethod(
|
|||||||
printer->Print(vars, "function deserialize_$Type$(buffer) {\n");
|
printer->Print(vars, "function deserialize_$Type$(buffer) {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
printer->Print(vars,
|
printer->Print(vars,
|
||||||
"return $FBSFile$.$Type$.getRootAs$Type$(new "
|
"return $Type$.getRootAs$VALUE$(new "
|
||||||
"flatbuffers.ByteBuffer(buffer))\n");
|
"flatbuffers.ByteBuffer(buffer))\n");
|
||||||
printer->Outdent();
|
printer->Outdent();
|
||||||
printer->Print("}\n\n");
|
printer->Print("}\n\n");
|
||||||
@@ -106,14 +168,18 @@ void GenerateMethods(const grpc_generator::Service *service,
|
|||||||
|
|
||||||
if (generated_functions.find(output) == generated_functions.end()) {
|
if (generated_functions.find(output) == generated_functions.end()) {
|
||||||
generated_functions.insert(output);
|
generated_functions.insert(output);
|
||||||
vars["Type"] = output;
|
vars["VALUE"] = output;
|
||||||
|
vars["Type"] = GenerateNamespace(method->get_output_namespace_parts(),
|
||||||
|
output, false);
|
||||||
GenerateSerializeMethod(printer, &vars);
|
GenerateSerializeMethod(printer, &vars);
|
||||||
GenerateDeserializeMethod(printer, &vars);
|
GenerateDeserializeMethod(printer, &vars);
|
||||||
}
|
}
|
||||||
printer->Print("\n");
|
printer->Print("\n");
|
||||||
if (generated_functions.find(input) == generated_functions.end()) {
|
if (generated_functions.find(input) == generated_functions.end()) {
|
||||||
generated_functions.insert(input);
|
generated_functions.insert(input);
|
||||||
vars["Type"] = input;
|
vars["VALUE"] = input;
|
||||||
|
vars["Type"] =
|
||||||
|
GenerateNamespace(method->get_input_namespace_parts(), input, false);
|
||||||
GenerateSerializeMethod(printer, &vars);
|
GenerateSerializeMethod(printer, &vars);
|
||||||
GenerateDeserializeMethod(printer, &vars);
|
GenerateDeserializeMethod(printer, &vars);
|
||||||
}
|
}
|
||||||
@@ -131,18 +197,20 @@ void GenerateService(const grpc_generator::Service *service,
|
|||||||
for (auto it = 0; it < service->method_count(); it++) {
|
for (auto it = 0; it < service->method_count(); it++) {
|
||||||
auto method = service->method(it);
|
auto method = service->method(it);
|
||||||
vars["MethodName"] = method->name();
|
vars["MethodName"] = method->name();
|
||||||
vars["Output"] = method->get_output_type_name();
|
vars["OUTPUT"] = GenerateNamespace(method->get_output_namespace_parts(),
|
||||||
vars["Input"] = method->get_input_type_name();
|
method->get_output_type_name(), false);
|
||||||
|
vars["INPUT"] = GenerateNamespace(method->get_input_namespace_parts(),
|
||||||
|
method->get_input_type_name(), false);
|
||||||
printer->Print(vars, "$MethodName$: {\n");
|
printer->Print(vars, "$MethodName$: {\n");
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
printer->Print(vars, "path: '/$PATH$$ServiceName$/$MethodName$',\n");
|
printer->Print(vars, "path: '/$PATH$$ServiceName$/$MethodName$',\n");
|
||||||
GetStreamType(printer, &*method, &vars);
|
GetStreamType(printer, &*method, &vars);
|
||||||
printer->Print(vars, "requestType: flatbuffers.ByteBuffer,\n");
|
printer->Print(vars, "requestType: flatbuffers.ByteBuffer,\n");
|
||||||
printer->Print(vars, "responseType: $FBSFile$.$Output$,\n");
|
printer->Print(vars, "responseType: $OUTPUT$,\n");
|
||||||
printer->Print(vars, "requestSerialize: serialize_$Input$,\n");
|
printer->Print(vars, "requestSerialize: serialize_$INPUT$,\n");
|
||||||
printer->Print(vars, "requestDeserialize: deserialize_$Input$,\n");
|
printer->Print(vars, "requestDeserialize: deserialize_$INPUT$,\n");
|
||||||
printer->Print(vars, "responseSerialize: serialize_$Output$,\n");
|
printer->Print(vars, "responseSerialize: serialize_$OUTPUT$,\n");
|
||||||
printer->Print(vars, "responseDeserialize: deserialize_$Output$,\n");
|
printer->Print(vars, "responseDeserialize: deserialize_$OUTPUT$,\n");
|
||||||
printer->Outdent();
|
printer->Outdent();
|
||||||
printer->Print("},\n");
|
printer->Print("},\n");
|
||||||
}
|
}
|
||||||
@@ -168,7 +236,7 @@ grpc::string Generate(grpc_generator::File *file,
|
|||||||
vars["Filename"] = filename;
|
vars["Filename"] = filename;
|
||||||
auto printer = file->CreatePrinter(&output);
|
auto printer = file->CreatePrinter(&output);
|
||||||
|
|
||||||
GenerateImports(&*printer, &vars, true);
|
GenerateImports(service, &*printer, &vars, true);
|
||||||
GenerateMethods(service, &*printer, &vars);
|
GenerateMethods(service, &*printer, &vars);
|
||||||
GenerateService(service, &*printer, &vars);
|
GenerateService(service, &*printer, &vars);
|
||||||
return output;
|
return output;
|
||||||
@@ -179,22 +247,17 @@ grpc::string Generate(grpc_generator::File *file,
|
|||||||
void FillInterface(grpc_generator::Printer *printer,
|
void FillInterface(grpc_generator::Printer *printer,
|
||||||
std::map<grpc::string, grpc::string> *dictonary) {
|
std::map<grpc::string, grpc::string> *dictonary) {
|
||||||
auto vars = *dictonary;
|
auto vars = *dictonary;
|
||||||
printer->Print(
|
printer->Print(vars,
|
||||||
vars,
|
"interface I$ServiceName$Service_I$MethodName$ extends "
|
||||||
"interface I$ServiceName$Service_I$MethodName$ extends "
|
"grpc.MethodDefinition<$INPUT$, $OUTPUT$> {\n");
|
||||||
"grpc.MethodDefinition<$FBSFile$.$INPUT$, $FBSFile$.$OUTPUT$> {\n");
|
|
||||||
printer->Indent();
|
printer->Indent();
|
||||||
printer->Print(vars, "path: string; // /$PATH$$ServiceName$/$MethodName$\n");
|
printer->Print(vars, "path: string; // /$PATH$$ServiceName$/$MethodName$\n");
|
||||||
printer->Print(vars, "requestStream: boolean; // $ClientStreaming$\n");
|
printer->Print(vars, "requestStream: boolean; // $ClientStreaming$\n");
|
||||||
printer->Print(vars, "responseStream: boolean; // $ServerStreaming$\n");
|
printer->Print(vars, "responseStream: boolean; // $ServerStreaming$\n");
|
||||||
printer->Print(vars,
|
printer->Print(vars, "requestSerialize: grpc.serialize<$INPUT$>;\n");
|
||||||
"requestSerialize: grpc.serialize<$FBSFile$.$INPUT$>;\n");
|
printer->Print(vars, "requestDeserialize: grpc.deserialize<$INPUT$>;\n");
|
||||||
printer->Print(vars,
|
printer->Print(vars, "responseSerialize: grpc.serialize<$OUTPUT$>;\n");
|
||||||
"requestDeserialize: grpc.deserialize<$FBSFile$.$INPUT$>;\n");
|
printer->Print(vars, "responseDeserialize: grpc.deserialize<$OUTPUT$>;\n");
|
||||||
printer->Print(vars,
|
|
||||||
"responseSerialize: grpc.serialize<$FBSFile$.$OUTPUT$>;\n");
|
|
||||||
printer->Print(
|
|
||||||
vars, "responseDeserialize: grpc.deserialize<$FBSFile$.$OUTPUT$>;\n");
|
|
||||||
printer->Outdent();
|
printer->Outdent();
|
||||||
printer->Print("}\n");
|
printer->Print("}\n");
|
||||||
}
|
}
|
||||||
@@ -212,8 +275,10 @@ void GenerateInterfaces(const grpc_generator::Service *service,
|
|||||||
vars["ClientStreaming"] = client_streaming ? "true" : "false";
|
vars["ClientStreaming"] = client_streaming ? "true" : "false";
|
||||||
vars["ServerStreaming"] = server_streaming ? "true" : "false";
|
vars["ServerStreaming"] = server_streaming ? "true" : "false";
|
||||||
vars["MethodName"] = method->name();
|
vars["MethodName"] = method->name();
|
||||||
vars["INPUT"] = method->get_input_type_name();
|
vars["OUTPUT"] = GenerateNamespace(method->get_output_namespace_parts(),
|
||||||
vars["OUTPUT"] = method->get_output_type_name();
|
method->get_output_type_name(), false);
|
||||||
|
vars["INPUT"] = GenerateNamespace(method->get_input_namespace_parts(),
|
||||||
|
method->get_input_type_name(), false);
|
||||||
FillInterface(printer, &vars);
|
FillInterface(printer, &vars);
|
||||||
printer->Print("\n");
|
printer->Print("\n");
|
||||||
}
|
}
|
||||||
@@ -228,32 +293,32 @@ void GenerateExportedInterface(
|
|||||||
for (auto it = 0; it < service->method_count(); it++) {
|
for (auto it = 0; it < service->method_count(); it++) {
|
||||||
auto method = service->method(it);
|
auto method = service->method(it);
|
||||||
vars["Name"] = method->name();
|
vars["Name"] = method->name();
|
||||||
vars["INPUT"] = method->get_input_type_name();
|
vars["OUTPUT"] = GenerateNamespace(method->get_output_namespace_parts(),
|
||||||
vars["OUTPUT"] = method->get_output_type_name();
|
method->get_output_type_name(), false);
|
||||||
|
vars["INPUT"] = GenerateNamespace(method->get_input_namespace_parts(),
|
||||||
|
method->get_input_type_name(), false);
|
||||||
if (method->BidiStreaming()) {
|
if (method->BidiStreaming()) {
|
||||||
printer->Print(vars,
|
printer->Print(vars,
|
||||||
"$Name$: grpc.handleBidiStreamingCall<$FBSFile$.$INPUT$, "
|
"$Name$: grpc.handleBidiStreamingCall<$INPUT$, "
|
||||||
"$FBSFile$.$OUTPUT$>;\n");
|
"$OUTPUT$>;\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (method->NoStreaming()) {
|
if (method->NoStreaming()) {
|
||||||
printer->Print(vars,
|
printer->Print(vars,
|
||||||
"$Name$: grpc.handleUnaryCall<$FBSFile$.$INPUT$, "
|
"$Name$: grpc.handleUnaryCall<$INPUT$, "
|
||||||
"$FBSFile$.$OUTPUT$>;\n");
|
"$OUTPUT$>;\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (method->ClientStreaming()) {
|
if (method->ClientStreaming()) {
|
||||||
printer->Print(
|
printer->Print(vars,
|
||||||
vars,
|
"$Name$: grpc.handleClientStreamingCall<$INPUT$, "
|
||||||
"$Name$: grpc.handleClientStreamingCall<$FBSFile$.$INPUT$, "
|
"$OUTPUT$>;\n");
|
||||||
"$FBSFile$.$OUTPUT$>;\n");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (method->ServerStreaming()) {
|
if (method->ServerStreaming()) {
|
||||||
printer->Print(
|
printer->Print(vars,
|
||||||
vars,
|
"$Name$: grpc.handleServerStreamingCall<$INPUT$, "
|
||||||
"$Name$: grpc.handleServerStreamingCall<$FBSFile$.$INPUT$, "
|
"$OUTPUT$>;\n");
|
||||||
"$FBSFile$.$OUTPUT$>;\n");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,10 +359,10 @@ void GenerateUnaryClientInterface(
|
|||||||
grpc_generator::Printer *printer,
|
grpc_generator::Printer *printer,
|
||||||
std::map<grpc::string, grpc::string> *dictonary) {
|
std::map<grpc::string, grpc::string> *dictonary) {
|
||||||
auto vars = *dictonary;
|
auto vars = *dictonary;
|
||||||
grpc::string main = "$ISPUBLIC$$MethodName$(request: $FBSFile$.$INPUT$, ";
|
grpc::string main = "$ISPUBLIC$$MethodName$(request: $INPUT$, ";
|
||||||
grpc::string callback =
|
grpc::string callback =
|
||||||
"callback: (error: grpc.ServiceError | null, response: "
|
"callback: (error: grpc.ServiceError | null, response: "
|
||||||
"$FBSFile$.$OUTPUT$) => void): grpc.ClientUnaryCall;\n";
|
"$OUTPUT$) => void): grpc.ClientUnaryCall;\n";
|
||||||
auto meta_data = GenerateMetaData() + ", ";
|
auto meta_data = GenerateMetaData() + ", ";
|
||||||
auto options = GenerateOptions() + ", ";
|
auto options = GenerateOptions() + ", ";
|
||||||
printer->Print(vars, (main + callback).c_str());
|
printer->Print(vars, (main + callback).c_str());
|
||||||
@@ -312,8 +377,8 @@ void GenerateClientWriteStreamInterface(
|
|||||||
grpc::string main = "$ISPUBLIC$$MethodName$(";
|
grpc::string main = "$ISPUBLIC$$MethodName$(";
|
||||||
grpc::string callback =
|
grpc::string callback =
|
||||||
"callback: (error: grpc.ServiceError | null, response: "
|
"callback: (error: grpc.ServiceError | null, response: "
|
||||||
"$FBSFile$.$INPUT$) => void): "
|
"$INPUT$) => void): "
|
||||||
"grpc.ClientWritableStream<$FBSFile$.$OUTPUT$>;\n";
|
"grpc.ClientWritableStream<$OUTPUT$>;\n";
|
||||||
auto meta_data = GenerateMetaData() + ", ";
|
auto meta_data = GenerateMetaData() + ", ";
|
||||||
auto options = GenerateOptions() + ", ";
|
auto options = GenerateOptions() + ", ";
|
||||||
printer->Print(vars, (main + callback).c_str());
|
printer->Print(vars, (main + callback).c_str());
|
||||||
@@ -326,9 +391,8 @@ void GenerateClientReadableStreamInterface(
|
|||||||
grpc_generator::Printer *printer,
|
grpc_generator::Printer *printer,
|
||||||
std::map<grpc::string, grpc::string> *dictonary) {
|
std::map<grpc::string, grpc::string> *dictonary) {
|
||||||
auto vars = *dictonary;
|
auto vars = *dictonary;
|
||||||
grpc::string main = "$ISPUBLIC$$MethodName$(request: $FBSFile$.$INPUT$, ";
|
grpc::string main = "$ISPUBLIC$$MethodName$(request: $INPUT$, ";
|
||||||
grpc::string end_function =
|
grpc::string end_function = "): grpc.ClientReadableStream<$OUTPUT$>;\n";
|
||||||
"): grpc.ClientReadableStream<$FBSFile$.$OUTPUT$>;\n";
|
|
||||||
auto meta_data = GenerateMetaData();
|
auto meta_data = GenerateMetaData();
|
||||||
auto options = GenerateOptions();
|
auto options = GenerateOptions();
|
||||||
printer->Print(vars, (main + meta_data + end_function).c_str());
|
printer->Print(vars, (main + meta_data + end_function).c_str());
|
||||||
@@ -341,7 +405,7 @@ void GenerateDepluxStreamInterface(
|
|||||||
auto vars = *dictonary;
|
auto vars = *dictonary;
|
||||||
grpc::string main = "$ISPUBLIC$$MethodName$(";
|
grpc::string main = "$ISPUBLIC$$MethodName$(";
|
||||||
grpc::string end_function =
|
grpc::string end_function =
|
||||||
"): grpc.ClientDuplexStream<$FBSFile$.$INPUT$, $FBSFile$.$OUTPUT$>;\n";
|
"): grpc.ClientDuplexStream<$INPUT$, $OUTPUT$>;\n";
|
||||||
auto meta_data = GenerateMetaData();
|
auto meta_data = GenerateMetaData();
|
||||||
auto options = GenerateOptions();
|
auto options = GenerateOptions();
|
||||||
printer->Print(vars, (main + end_function).c_str());
|
printer->Print(vars, (main + end_function).c_str());
|
||||||
@@ -360,8 +424,10 @@ void GenerateClientInterface(const grpc_generator::Service *service,
|
|||||||
for (auto it = 0; it < service->method_count(); it++) {
|
for (auto it = 0; it < service->method_count(); it++) {
|
||||||
auto method = service->method(it);
|
auto method = service->method(it);
|
||||||
vars["MethodName"] = method->name();
|
vars["MethodName"] = method->name();
|
||||||
vars["INPUT"] = method->get_input_type_name();
|
vars["OUTPUT"] = GenerateNamespace(method->get_output_namespace_parts(),
|
||||||
vars["OUTPUT"] = method->get_output_type_name();
|
method->get_output_type_name(), false);
|
||||||
|
vars["INPUT"] = GenerateNamespace(method->get_input_namespace_parts(),
|
||||||
|
method->get_input_type_name(), false);
|
||||||
vars["ISPUBLIC"] = "";
|
vars["ISPUBLIC"] = "";
|
||||||
|
|
||||||
if (method->NoStreaming()) {
|
if (method->NoStreaming()) {
|
||||||
@@ -401,8 +467,10 @@ void GenerateClientClassInterface(
|
|||||||
for (auto it = 0; it < service->method_count(); it++) {
|
for (auto it = 0; it < service->method_count(); it++) {
|
||||||
auto method = service->method(it);
|
auto method = service->method(it);
|
||||||
vars["MethodName"] = method->name();
|
vars["MethodName"] = method->name();
|
||||||
vars["INPUT"] = method->get_input_type_name();
|
vars["OUTPUT"] = GenerateNamespace(method->get_output_namespace_parts(),
|
||||||
vars["OUTPUT"] = method->get_output_type_name();
|
method->get_output_type_name(), false);
|
||||||
|
vars["INPUT"] = GenerateNamespace(method->get_input_namespace_parts(),
|
||||||
|
method->get_input_type_name(), false);
|
||||||
vars["ISPUBLIC"] = "public ";
|
vars["ISPUBLIC"] = "public ";
|
||||||
if (method->NoStreaming()) {
|
if (method->NoStreaming()) {
|
||||||
GenerateUnaryClientInterface(printer, &vars);
|
GenerateUnaryClientInterface(printer, &vars);
|
||||||
@@ -444,7 +512,7 @@ grpc::string GenerateInterface(grpc_generator::File *file,
|
|||||||
vars["Filename"] = filename;
|
vars["Filename"] = filename;
|
||||||
auto printer = file->CreatePrinter(&output);
|
auto printer = file->CreatePrinter(&output);
|
||||||
|
|
||||||
GenerateImports(&*printer, &vars, false);
|
GenerateImports(service, &*printer, &vars, false);
|
||||||
GenerateMainInterface(service, &*printer, &vars);
|
GenerateMainInterface(service, &*printer, &vars);
|
||||||
printer->Print("\n");
|
printer->Print("\n");
|
||||||
GenerateClientInterface(service, &*printer, &vars);
|
GenerateClientInterface(service, &*printer, &vars);
|
||||||
|
|||||||
Reference in New Issue
Block a user