Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
b1a02311
Commit
b1a02311
authored
8 years ago
by
murgatroid99
Browse files
Options
Downloads
Patches
Plain Diff
Autodetect ProtoBuf.js version in grpc.loadObject
parent
b5b5f020
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/node/index.js
+11
-7
11 additions, 7 deletions
src/node/index.js
src/node/test/surface_test.js
+9
-10
9 additions, 10 deletions
src/node/test/surface_test.js
with
20 additions
and
17 deletions
src/node/index.js
+
11
−
7
View file @
b1a02311
...
...
@@ -58,12 +58,17 @@ var protobuf_js_6_common = require('./src/protobuf_js_6_common');
grpc
.
setDefaultRootsPem
(
fs
.
readFileSync
(
SSL_ROOTS_PATH
,
'
ascii
'
));
exports
.
loadObject
=
function
loadObject
(
value
,
options
)
{
options
=
_
.
defaults
(
options
,
{
'
protobufjs_version
'
:
5
});
switch
(
options
.
protobufjs_version
)
{
case
5
:
return
protobuf_js_5_common
.
loadObject
(
value
,
options
);
case
6
:
return
protobuf_js_6_common
.
loadObject
(
value
,
options
);
default
:
throw
new
Error
(
'
Unrecognized protobufjs_version:
'
,
options
.
protobufjs_version
);
options
=
_
.
defaults
(
options
,
common
.
defaultGrpcOptions
);
if
(
value
instanceof
ProtoBuf
.
ReflectionObject
)
{
return
protobuf_js_6_common
.
loadObject
(
value
,
options
);
}
else
{
/* If value is not a ProtoBuf.js 6 reflection object, we assume that it is
a ProtoBuf.js 5 reflection object, for backwards compatibility */
var
deprecation_message
=
'
Calling grpc.loadObject with an object
'
+
'
generated by ProtoBuf.js 5 is deprecated. Please upgrade to
'
+
'
ProtoBuf.js 6.
'
;
common
.
log
(
grpc
.
logVerbosity
.
INFO
,
deprecation_message
);
return
protobuf_js_5_common
.
loadObject
(
value
,
options
);
}
};
...
...
@@ -108,7 +113,6 @@ exports.load = function load(filename, format, options) {
still the possibility of adding other formats that would be loaded
differently */
options
=
_
.
defaults
(
options
,
common
.
defaultGrpcOptions
);
options
.
protobufjs_version
=
6
;
var
root
=
new
ProtoBuf
.
Root
();
var
parse_options
=
{
keepCase
:
!
options
.
convertFieldsToCamelCase
};
return
loadObject
(
root
.
loadSync
(
applyProtoRoot
(
filename
,
root
),
...
...
This diff is collapsed.
Click to expand it.
src/node/test/surface_test.js
+
9
−
10
View file @
b1a02311
...
...
@@ -49,8 +49,7 @@ math_proto = math_proto.loadSync(__dirname +
var
mathService
=
math_proto
.
lookup
(
'
math.Math
'
);
var
mathServiceAttrs
=
grpc
.
loadObject
(
mathService
,
_
.
defaults
({
protobufjs_version
:
6
},
common
.
defaultGrpcOptions
)).
service
;
mathService
,
common
.
defaultGrpcOptions
).
service
;
/**
* This is used for testing functions with multiple asynchronous calls that
...
...
@@ -178,7 +177,7 @@ describe('Server.prototype.addService', function() {
beforeEach
(
function
()
{
server
.
addService
(
mathServiceAttrs
,
{});
var
port
=
server
.
bind
(
'
localhost:0
'
,
server_insecure_creds
);
var
Client
=
grpc
.
loadObject
(
mathService
,
{
protobufjs_version
:
6
}
);
var
Client
=
grpc
.
loadObject
(
mathService
);
client
=
new
Client
(
'
localhost:
'
+
port
,
grpc
.
credentials
.
createInsecure
());
server
.
start
();
...
...
@@ -250,7 +249,7 @@ describe('waitForClientReady', function() {
server
=
new
grpc
.
Server
();
port
=
server
.
bind
(
'
localhost:0
'
,
grpc
.
ServerCredentials
.
createInsecure
());
server
.
start
();
Client
=
grpc
.
loadObject
(
mathService
,
{
protobufjs_version
:
6
}
);
Client
=
grpc
.
loadObject
(
mathService
);
});
beforeEach
(
function
()
{
client
=
new
Client
(
'
localhost:
'
+
port
,
grpc
.
credentials
.
createInsecure
());
...
...
@@ -311,7 +310,7 @@ describe('Echo service', function() {
test_proto
=
test_proto
.
loadSync
(
__dirname
+
'
/echo_service.proto
'
,
{
keepCase
:
true
});
var
echo_service
=
test_proto
.
lookup
(
'
EchoService
'
);
var
Client
=
grpc
.
loadObject
(
echo_service
,
{
protobufjs_version
:
6
}
);
var
Client
=
grpc
.
loadObject
(
echo_service
);
server
=
new
grpc
.
Server
();
server
.
addService
(
Client
.
service
,
{
echo
:
function
(
call
,
callback
)
{
...
...
@@ -436,7 +435,7 @@ describe('Echo metadata', function() {
test_proto
=
test_proto
.
loadSync
(
__dirname
+
'
/test_service.proto
'
,
{
keepCase
:
true
});
var
test_service
=
test_proto
.
lookup
(
'
TestService
'
);
var
Client
=
grpc
.
loadObject
(
test_service
,
{
protobufjs_version
:
6
}
);
var
Client
=
grpc
.
loadObject
(
test_service
);
server
=
new
grpc
.
Server
();
server
.
addService
(
Client
.
service
,
{
unary
:
function
(
call
,
cb
)
{
...
...
@@ -595,7 +594,7 @@ describe('Client malformed response handling', function() {
}
});
var
port
=
server
.
bind
(
'
localhost:0
'
,
server_insecure_creds
);
var
Client
=
grpc
.
loadObject
(
test_service
,
{
protobufjs_version
:
6
}
);
var
Client
=
grpc
.
loadObject
(
test_service
);
client
=
new
Client
(
'
localhost:
'
+
port
,
grpc
.
credentials
.
createInsecure
());
server
.
start
();
});
...
...
@@ -704,7 +703,7 @@ describe('Server serialization failure handling', function() {
}
});
var
port
=
server
.
bind
(
'
localhost:0
'
,
server_insecure_creds
);
var
Client
=
grpc
.
loadObject
(
test_service
,
{
protobufjs_version
:
6
}
);
var
Client
=
grpc
.
loadObject
(
test_service
);
client
=
new
Client
(
'
localhost:
'
+
port
,
grpc
.
credentials
.
createInsecure
());
server
.
start
();
});
...
...
@@ -757,7 +756,7 @@ describe('Other conditions', function() {
test_proto
=
test_proto
.
loadSync
(
__dirname
+
'
/test_service.proto
'
,
{
keepCase
:
true
});
test_service
=
test_proto
.
lookup
(
'
TestService
'
);
Client
=
grpc
.
loadObject
(
test_service
,
{
protobufjs_version
:
6
}
);
Client
=
grpc
.
loadObject
(
test_service
);
server
=
new
grpc
.
Server
();
var
trailer_metadata
=
new
grpc
.
Metadata
();
trailer_metadata
.
add
(
'
trailer-present
'
,
'
yes
'
);
...
...
@@ -1106,7 +1105,7 @@ describe('Call propagation', function() {
{
keepCase
:
true
});
test_service
=
test_proto
.
lookup
(
'
TestService
'
);
server
=
new
grpc
.
Server
();
Client
=
grpc
.
loadObject
(
test_service
,
{
protobufjs_version
:
6
}
);
Client
=
grpc
.
loadObject
(
test_service
);
server
.
addService
(
Client
.
service
,
{
unary
:
function
(
call
)
{},
clientStream
:
function
(
stream
)
{},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment