Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: protoCache map key support Buffer type #1106

Merged
merged 2 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class GrpcClient {
authClient?: AuthClient;
fallback: boolean | 'rest' | 'proto';
grpcVersion: string;
private static protoCache = new Map<string, protobuf.Root>();
private static protoCache = new Map<string | Buffer, protobuf.Root>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to be more confident in the types of the internal data structure and ensure we always have a string key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative way is to turn the hash value from Buffer to string. At line
const hash = objectHash(json).toString();


/**
* In rare cases users might need to deallocate all memory consumed by loaded protos.
Expand Down
2 changes: 1 addition & 1 deletion src/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class GrpcClient {
grpc: GrpcModule;
grpcVersion: string;
fallback: boolean | 'rest' | 'proto';
private static protoCache = new Map<string, grpc.GrpcObject>();
private static protoCache = new Map<string | Buffer, grpc.GrpcObject>();

/**
* Key for proto cache map. We are doing our best to make sure we respect
Expand Down