blob: 5838c576b052d053265bfcf9ce9996316e19b68f [file] [log] [blame]
Jens Geyeraa99e0e2014-09-29 22:09:15 +02001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#import "TMultiplexedProtocol.h"
21
22#import "TProtocol.h"
Jens Geyeraa99e0e2014-09-29 22:09:15 +020023
Jens Geyer56e5b9b2015-10-09 22:01:55 +020024NSString *TMultiplexedProtocolSeperator = @":";
25
26
27@interface TMultiplexedProtocol ()
28
29@property(strong, nonatomic) NSString *serviceName;
30
31@end
32
Jens Geyeraa99e0e2014-09-29 22:09:15 +020033
34@implementation TMultiplexedProtocol
35
Jens Geyer56e5b9b2015-10-09 22:01:55 +020036-(id) initWithProtocol:(id <TProtocol>)protocol
37 serviceName:(NSString *)name
Jens Geyeraa99e0e2014-09-29 22:09:15 +020038{
Jens Geyer56e5b9b2015-10-09 22:01:55 +020039 self = [super initWithProtocol:protocol];
40 if (self) {
41 _serviceName = name;
42 }
43 return self;
Jens Geyeraa99e0e2014-09-29 22:09:15 +020044}
45
Jens Geyer56e5b9b2015-10-09 22:01:55 +020046-(BOOL) writeMessageBeginWithName:(NSString *)name
47 type:(SInt32)messageType
48 sequenceID:(SInt32)sequenceID
49 error:(NSError *__autoreleasing *)error
Jens Geyeraa99e0e2014-09-29 22:09:15 +020050{
Jens Geyer56e5b9b2015-10-09 22:01:55 +020051 switch (messageType) {
52 case TMessageTypeCALL:
53 case TMessageTypeONEWAY: {
54 NSMutableString *serviceFunction = [[NSMutableString alloc] initWithString:_serviceName];
55 [serviceFunction appendString:TMultiplexedProtocolSeperator];
56 [serviceFunction appendString:name];
57 return [super writeMessageBeginWithName:serviceFunction type:messageType sequenceID:sequenceID error:error];
58 }
59 break;
Jens Geyeraa99e0e2014-09-29 22:09:15 +020060
Jens Geyer56e5b9b2015-10-09 22:01:55 +020061 default:
62 return [super writeMessageBeginWithName:name type:messageType sequenceID:sequenceID error:error];
63 }
Jens Geyeraa99e0e2014-09-29 22:09:15 +020064}
65
66@end