-
Notifications
You must be signed in to change notification settings - Fork 19
/
PomeloProtocol.m
35 lines (28 loc) · 951 Bytes
/
PomeloProtocol.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// PomeloProtocol.m
// iOS client for Pomelo
//
// Created by Johnny on 12-12-24.
// Copyright (c) 2012 netease pomelo team. All rights reserved.
//
#import "PomeloProtocol.h"
NSString* const PomeloException = @"PomeloException";
@implementation PomeloProtocol
+ (NSString *)encodeWithId:(NSInteger)id andRoute:(NSString *)route andBody:(NSString *)body
{
if ([route length] > 255) {
[NSException raise:PomeloException format:@"Pomelo: route length is too long!"];
return nil;
}
NSString *msg = [NSString stringWithFormat:@"%C%C%C%C%C%@%@",
(id >> 24) & 0xFF,
(id >> 16) & 0xFF,
(id >> 8) & 0xFF,
id & 0xFF,
[route length],
route,
body];
// NSLog(@"send msg,%d, %d, %@",[route length] + [body length],[msg length],msg);
return msg;
}
@end