-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* handle empty protobuf package * prettify changes * Add testcase * Use maybePrefixPackage to reduce copy/paste. Co-authored-by: Daniel Kilimnik <kaleb.dk@gmail.com>
- Loading branch information
Showing
10 changed files
with
179 additions
and
21 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "proto3"; | ||
|
||
service UserState { | ||
rpc GetUsers(Empty) returns (stream User); | ||
} | ||
|
||
message User { | ||
string name = 1; | ||
} | ||
|
||
message Empty {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* eslint-disable */ | ||
import { util, configure, Reader, Writer } from 'protobufjs/minimal'; | ||
import * as Long from 'long'; | ||
import { Observable } from 'rxjs'; | ||
|
||
export const protobufPackage = ''; | ||
|
||
export interface User { | ||
name: string; | ||
} | ||
|
||
export interface Empty {} | ||
|
||
const baseUser: object = { name: '' }; | ||
|
||
export const User = { | ||
encode(message: User, writer: Writer = Writer.create()): Writer { | ||
if (message.name !== '') { | ||
writer.uint32(10).string(message.name); | ||
} | ||
return writer; | ||
}, | ||
|
||
decode(input: Reader | Uint8Array, length?: number): User { | ||
const reader = input instanceof Reader ? input : new Reader(input); | ||
let end = length === undefined ? reader.len : reader.pos + length; | ||
const message = { ...baseUser } as User; | ||
while (reader.pos < end) { | ||
const tag = reader.uint32(); | ||
switch (tag >>> 3) { | ||
case 1: | ||
message.name = reader.string(); | ||
break; | ||
default: | ||
reader.skipType(tag & 7); | ||
break; | ||
} | ||
} | ||
return message; | ||
}, | ||
|
||
fromJSON(object: any): User { | ||
const message = { ...baseUser } as User; | ||
if (object.name !== undefined && object.name !== null) { | ||
message.name = String(object.name); | ||
} else { | ||
message.name = ''; | ||
} | ||
return message; | ||
}, | ||
|
||
toJSON(message: User): unknown { | ||
const obj: any = {}; | ||
message.name !== undefined && (obj.name = message.name); | ||
return obj; | ||
}, | ||
|
||
fromPartial(object: DeepPartial<User>): User { | ||
const message = { ...baseUser } as User; | ||
if (object.name !== undefined && object.name !== null) { | ||
message.name = object.name; | ||
} else { | ||
message.name = ''; | ||
} | ||
return message; | ||
}, | ||
}; | ||
|
||
const baseEmpty: object = {}; | ||
|
||
export const Empty = { | ||
encode(_: Empty, writer: Writer = Writer.create()): Writer { | ||
return writer; | ||
}, | ||
|
||
decode(input: Reader | Uint8Array, length?: number): Empty { | ||
const reader = input instanceof Reader ? input : new Reader(input); | ||
let end = length === undefined ? reader.len : reader.pos + length; | ||
const message = { ...baseEmpty } as Empty; | ||
while (reader.pos < end) { | ||
const tag = reader.uint32(); | ||
switch (tag >>> 3) { | ||
default: | ||
reader.skipType(tag & 7); | ||
break; | ||
} | ||
} | ||
return message; | ||
}, | ||
|
||
fromJSON(_: any): Empty { | ||
const message = { ...baseEmpty } as Empty; | ||
return message; | ||
}, | ||
|
||
toJSON(_: Empty): unknown { | ||
const obj: any = {}; | ||
return obj; | ||
}, | ||
|
||
fromPartial(_: DeepPartial<Empty>): Empty { | ||
const message = { ...baseEmpty } as Empty; | ||
return message; | ||
}, | ||
}; | ||
|
||
export interface UserState { | ||
GetUsers(request: Empty): Observable<User>; | ||
} | ||
|
||
export class UserStateClientImpl implements UserState { | ||
private readonly rpc: Rpc; | ||
constructor(rpc: Rpc) { | ||
this.rpc = rpc; | ||
} | ||
GetUsers(request: Empty): Promise<User> { | ||
const data = Empty.encode(request).finish(); | ||
const promise = this.rpc.request('UserState', 'GetUsers', data); | ||
return promise.then((data) => User.decode(new Reader(data))); | ||
} | ||
} | ||
|
||
interface Rpc { | ||
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>; | ||
} | ||
|
||
type Builtin = Date | Function | Uint8Array | string | number | undefined; | ||
export type DeepPartial<T> = T extends Builtin | ||
? T | ||
: T extends Array<infer U> | ||
? Array<DeepPartial<U>> | ||
: T extends ReadonlyArray<infer U> | ||
? ReadonlyArray<DeepPartial<U>> | ||
: T extends {} | ||
? { [K in keyof T]?: DeepPartial<T[K]> } | ||
: Partial<T>; | ||
|
||
// If you get a compile-error about 'Constructor<Long> and ... have no overlap', | ||
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'. | ||
if (util.Long !== Long) { | ||
util.Long = Long as any; | ||
configure(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters