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
ff6466b7
Commit
ff6466b7
authored
9 years ago
by
Jorge Canizales
Browse files
Options
Downloads
Patches
Plain Diff
Add header manipulation examples
With both raw and codegen’d library
parent
4682f8f9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/objective-c/examples/SwiftSample/Bridging-Header.h
+1
-0
1 addition, 0 deletions
src/objective-c/examples/SwiftSample/Bridging-Header.h
src/objective-c/examples/SwiftSample/ViewController.swift
+32
-10
32 additions, 10 deletions
src/objective-c/examples/SwiftSample/ViewController.swift
with
33 additions
and
10 deletions
src/objective-c/examples/SwiftSample/Bridging-Header.h
+
1
−
0
View file @
ff6466b7
...
...
@@ -39,6 +39,7 @@
#import <RxLibrary/GRXWriter+Immediate.h>
#import <GRPCClient/GRPCCall.h>
#import <ProtoRPC/ProtoMethod.h>
#import <ProtoRPC/ProtoRPC.h>
#import <RemoteTest/Test.pbrpc.h>
#endif
This diff is collapsed.
Click to expand it.
src/objective-c/examples/SwiftSample/ViewController.swift
+
32
−
10
View file @
ff6466b7
...
...
@@ -45,17 +45,37 @@ class ViewController: UIViewController {
request
.
fillUsername
=
true
request
.
fillOauthScope
=
true
// Example gRPC call using a generated proto client library:
let
service
=
RMTTestService
(
host
:
RemoteHost
)
service
.
unaryCallWithRequest
(
request
)
{
(
response
:
RMTSimpleResponse
?,
error
:
NSError
?)
in
service
.
unaryCallWithRequest
(
request
)
{
response
,
error
in
if
let
response
=
response
{
NSLog
(
"1. Finished successfully with response:
\n\(
response
)
"
)
}
else
{
NSLog
(
"1. Finished with error:
\(
error
!
)
"
)
}
}
// Same but manipulating headers:
var
RPC
:
ProtoRPC
!
// Needed to convince Swift to capture by reference (__block)
RPC
=
service
.
RPCToUnaryCallWithRequest
(
request
)
{
response
,
error
in
if
let
response
=
response
{
NSLog
(
"Finished successfully with response:
\n\(
response
)
"
)
NSLog
(
"
2.
Finished successfully with response:
\n\(
response
)
"
)
}
else
{
NSLog
(
"Finished with error:
\(
error
!
)
"
)
NSLog
(
"
2.
Finished with error:
\(
error
!
)
"
)
}
NSLog
(
"2. Response headers:
\(
RPC
.
responseHeaders
)
"
)
NSLog
(
"2. Response trailers:
\(
RPC
.
responseTrailers
)
"
)
}
RPC
.
requestHeaders
[
"My-Header"
]
=
"My value"
RPC
.
start
()
// Same example call using the generic gRPC client library:
let
method
=
ProtoMethod
(
package
:
"grpc.testing"
,
service
:
"TestService"
,
method
:
"UnaryCall"
)
...
...
@@ -64,14 +84,16 @@ class ViewController: UIViewController {
let
call
=
GRPCCall
(
host
:
RemoteHost
,
path
:
method
.
HTTPPath
,
requestsWriter
:
requestsWriter
)
let
responsesWriteable
=
GRXWriteable
{
(
value
:
AnyObject
?,
error
:
NSError
?)
in
if
let
value
=
value
as?
NSData
{
NSLog
(
"Received response:
\n\(
RMTSimpleResponse
(
data
:
value
,
error
:
nil
)
)
"
)
call
.
requestHeaders
[
"My-Header"
]
=
"My value"
call
.
startWithWriteable
(
GRXWriteable
{
response
,
error
in
if
let
response
=
response
as?
NSData
{
NSLog
(
"3. Received response:
\n\(
RMTSimpleResponse
(
data
:
response
,
error
:
nil
)
)
"
)
}
else
{
NSLog
(
"Finished with error:
\(
error
!
)
"
)
NSLog
(
"
3.
Finished with error:
\(
error
!
)
"
)
}
}
call
.
startWithWriteable
(
responsesWriteable
)
NSLog
(
"3. Response headers:
\(
call
.
responseHeaders
)
"
)
NSLog
(
"3. Response trailers:
\(
call
.
responseTrailers
)
"
)
}
)
}
}
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