Skip to content

Commit

Permalink
Merge pull request #246 from ably/enhancement/log-level-enum
Browse files Browse the repository at this point in the history
Use Objective-C standard style for LogLevel enum
  • Loading branch information
QuintinWillison committed Nov 29, 2021
2 parents 40f9578 + 40ffbf0 commit 89cc7b2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 78 deletions.
7 changes: 5 additions & 2 deletions bin/templates/platformconstants.h.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
String $(Map<String, dynamic> c) => '''
@import Foundation;
typedef NS_ENUM(UInt8, _Value) {
\t${c['types'].map((_) => '${_['name']}CodecType = ${_['value']},').join('\n\t')}
typedef NS_ENUM(UInt8, CodecType) {
\t${c['types'].map((_) => 'CodecType${_capitalize(_['name'] as String)} = ${_['value']},').join('\n\t')}
};
Expand All @@ -13,3 +13,6 @@ ${c['objects'].map((_) => '''
// key constants for ${_['name']}
${_['properties'].map((name) => 'extern NSString *const Tx${_['name']}_$name;').join('\n')}
''').join('\n')}''';

String _capitalize(String sentence) =>
'${sentence[0].toUpperCase()}${sentence.substring(1)}';
34 changes: 17 additions & 17 deletions ios/Classes/codec/AblyFlutterReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ @implementation AblyFlutterReader

+ (AblyCodecDecoder) getDecoder:(const NSString*)type {
NSDictionary<NSString *, AblyCodecDecoder>* _handlers = @{
[NSString stringWithFormat:@"%d", ablyMessageCodecType]: readAblyFlutterMessage,
[NSString stringWithFormat:@"%d", ablyEventMessageCodecType ]: readAblyFlutterEventMessage,
[NSString stringWithFormat:@"%d", clientOptionsCodecType]: readClientOptions,
[NSString stringWithFormat:@"%d", messageExtrasCodecType]: readChannelMessageExtras,
[NSString stringWithFormat:@"%d", messageCodecType]: readChannelMessage,
[NSString stringWithFormat:@"%d", tokenDetailsCodecType]: readTokenDetails,
[NSString stringWithFormat:@"%d", tokenRequestCodecType]: readTokenRequest,
[NSString stringWithFormat:@"%d", restChannelOptionsCodecType]: CryptoCodec.readRestChannelOptions,
[NSString stringWithFormat:@"%d", realtimeChannelOptionsCodecType]: CryptoCodec.readRealtimeChannelOptions,
[NSString stringWithFormat:@"%d", restHistoryParamsCodecType]: readRestHistoryParams,
[NSString stringWithFormat:@"%d", realtimeHistoryParamsCodecType]: readRealtimeHistoryParams,
[NSString stringWithFormat:@"%d", restPresenceParamsCodecType]: readRestPresenceParams,
[NSString stringWithFormat:@"%d", realtimePresenceParamsCodecType]: readRealtimePresenceParams,
[NSString stringWithFormat:@"%d", messageDataCodecType]: readMessageData,
[NSString stringWithFormat:@"%d", cipherParamsCodecType]: CryptoCodec.readCipherParams,
[NSString stringWithFormat:@"%d", CodecTypeAblyMessage]: readAblyFlutterMessage,
[NSString stringWithFormat:@"%d", CodecTypeAblyEventMessage ]: readAblyFlutterEventMessage,
[NSString stringWithFormat:@"%d", CodecTypeClientOptions]: readClientOptions,
[NSString stringWithFormat:@"%d", CodecTypeMessageExtras]: readChannelMessageExtras,
[NSString stringWithFormat:@"%d", CodecTypeMessage]: readChannelMessage,
[NSString stringWithFormat:@"%d", CodecTypeTokenDetails]: readTokenDetails,
[NSString stringWithFormat:@"%d", CodecTypeTokenRequest]: readTokenRequest,
[NSString stringWithFormat:@"%d", CodecTypeRestChannelOptions]: CryptoCodec.readRestChannelOptions,
[NSString stringWithFormat:@"%d", CodecTypeRealtimeChannelOptions]: CryptoCodec.readRealtimeChannelOptions,
[NSString stringWithFormat:@"%d", CodecTypeRestHistoryParams]: readRestHistoryParams,
[NSString stringWithFormat:@"%d", CodecTypeRealtimeHistoryParams]: readRealtimeHistoryParams,
[NSString stringWithFormat:@"%d", CodecTypeRestPresenceParams]: readRestPresenceParams,
[NSString stringWithFormat:@"%d", CodecTypeRealtimePresenceParams]: readRealtimePresenceParams,
[NSString stringWithFormat:@"%d", CodecTypeMessageData]: readMessageData,
[NSString stringWithFormat:@"%d", CodecTypeCipherParams]: CryptoCodec.readCipherParams,
};
return [_handlers objectForKey:[NSString stringWithFormat:@"%@", type]];
}
Expand Down Expand Up @@ -197,7 +197,7 @@ +(ARTTokenParams *)tokenParamsFromDictionary: (NSDictionary *) dictionary {
READ_VALUE(o, capability, dictionary, TxTokenParams_capability);
READ_VALUE(o, timestamp, dictionary, TxTokenParams_timestamp);
ON_VALUE(^(const id value) {
o.ttl = [NSNumber numberWithDouble:[value doubleValue]/1000];
o.ttl = @([value doubleValue] / 1000);
}, dictionary, TxTokenParams_ttl);
ON_VALUE(^(const id value) {
o.timestamp = [NSDate dateWithTimeIntervalSince1970:[value doubleValue]/1000];
Expand All @@ -206,7 +206,7 @@ +(ARTTokenParams *)tokenParamsFromDictionary: (NSDictionary *) dictionary {
}

static AblyCodecDecoder readChannelMessageExtras = ^id<ARTJsonCompatible>(NSDictionary *const dictionary) {
return [dictionary objectForKey: TxMessageExtras_extras];
return dictionary[TxMessageExtras_extras];
};

static AblyCodecDecoder readChannelMessage = ^ARTMessage*(NSDictionary *const dictionary) {
Expand Down
62 changes: 31 additions & 31 deletions ios/Classes/codec/AblyFlutterWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,59 @@ @implementation AblyFlutterWriter

+ (UInt8) getType:(id)value{
if([value isKindOfClass:[AblyFlutterMessage class]]){
return ablyMessageCodecType;
return CodecTypeAblyMessage;
}else if([value isKindOfClass:[ARTErrorInfo class]]){
return errorInfoCodecType;
return CodecTypeErrorInfo;
}else if([value isKindOfClass:[ARTConnectionStateChange class]]){
return connectionStateChangeCodecType;
return CodecTypeConnectionStateChange;
}else if([value isKindOfClass:[ARTChannelStateChange class]]){
return channelStateChangeCodecType;
return CodecTypeChannelStateChange;
}else if([value isKindOfClass:[ARTMessage class]]){
return messageCodecType;
return CodecTypeMessage;
}else if([value isKindOfClass:[ARTPresenceMessage class]]){
return presenceMessageCodecType;
return CodecTypePresenceMessage;
}else if([value isKindOfClass:[ARTTokenParams class]]){
return tokenParamsCodecType;
return CodecTypeTokenParams;
}else if([value isKindOfClass:[ARTPaginatedResult class]]){
return paginatedResultCodecType;
return CodecTypePaginatedResult;
} else if ([value isKindOfClass:[ARTLocalDevice class]]) {
// Check for ARTLocalDevice before ARTLocalDevice, since ARTLocalDevice extends ARTDeviceDetails.
// If deviceDetailsCodecType was used first, the ARTLocalDevice fields won't be serialized.
return localDeviceCodecType;
// If CodecTypeDeviceDetails was used first, the ARTLocalDevice fields won't be serialized.
return CodecTypeLocalDevice;
} else if([value isKindOfClass:[ARTDeviceDetails class]]) {
return deviceDetailsCodecType;
return CodecTypeDeviceDetails;
} else if ([value isKindOfClass:[ARTPushChannelSubscription class]]) {
return pushChannelSubscriptionCodecType;
return CodecTypePushChannelSubscription;
} else if ([value isKindOfClass:[UNNotificationSettings class]]) {
return unNotificationSettingsCodecType;
return CodecTypeUnNotificationSettings;
} else if ([value isKindOfClass:[RemoteMessage class]]) {
return remoteMessageCodecType;
return CodecTypeRemoteMessage;
} else if ([value isKindOfClass:[ARTRealtimeChannelOptions class]]) {
return realtimeChannelOptionsCodecType;
return CodecTypeRealtimeChannelOptions;
} else if ([value isKindOfClass:[ARTChannelOptions class]]) {
return restChannelOptionsCodecType;
return CodecTypeRestChannelOptions;
} else if ([value isKindOfClass:[ARTCipherParams class]]) {
return cipherParamsCodecType;
return CodecTypeCipherParams;
}
return 0;
}

+ (AblyCodecEncoder) getEncoder:(const NSString*)type {
NSDictionary<NSString *, AblyCodecEncoder>* _handlers = @{
[NSString stringWithFormat:@"%d", ablyMessageCodecType]: encodeAblyMessage,
[NSString stringWithFormat:@"%d", errorInfoCodecType]: encodeErrorInfo,
[NSString stringWithFormat:@"%d", connectionStateChangeCodecType]: encodeConnectionStateChange,
[NSString stringWithFormat:@"%d", channelStateChangeCodecType]: encodeChannelStateChange,
[NSString stringWithFormat:@"%d", messageCodecType]: encodeChannelMessage,
[NSString stringWithFormat:@"%d", presenceMessageCodecType]: encodePresenceMessage,
[NSString stringWithFormat:@"%d", tokenParamsCodecType]: encodeTokenParams,
[NSString stringWithFormat:@"%d", paginatedResultCodecType]: encodePaginatedResult,
[NSString stringWithFormat:@"%d", deviceDetailsCodecType]: PushNotificationEncoders.encodeDeviceDetails,
[NSString stringWithFormat:@"%d", localDeviceCodecType]: PushNotificationEncoders.encodeLocalDevice,
[NSString stringWithFormat:@"%d", pushChannelSubscriptionCodecType]: PushNotificationEncoders.encodePushChannelSubscription,
[NSString stringWithFormat:@"%d", unNotificationSettingsCodecType]: PushNotificationEncoders.encodeUNNotificationSettings,
[NSString stringWithFormat:@"%d", remoteMessageCodecType]: PushNotificationEncoders.encodeRemoteMessage,
[NSString stringWithFormat:@"%d", cipherParamsCodecType]: CryptoCodec.encodeCipherParams,
[NSString stringWithFormat:@"%d", CodecTypeAblyMessage]: encodeAblyMessage,
[NSString stringWithFormat:@"%d", CodecTypeErrorInfo]: encodeErrorInfo,
[NSString stringWithFormat:@"%d", CodecTypeConnectionStateChange]: encodeConnectionStateChange,
[NSString stringWithFormat:@"%d", CodecTypeChannelStateChange]: encodeChannelStateChange,
[NSString stringWithFormat:@"%d", CodecTypeMessage]: encodeChannelMessage,
[NSString stringWithFormat:@"%d", CodecTypePresenceMessage]: encodePresenceMessage,
[NSString stringWithFormat:@"%d", CodecTypeTokenParams]: encodeTokenParams,
[NSString stringWithFormat:@"%d", CodecTypePaginatedResult]: encodePaginatedResult,
[NSString stringWithFormat:@"%d", CodecTypeDeviceDetails]: PushNotificationEncoders.encodeDeviceDetails,
[NSString stringWithFormat:@"%d", CodecTypeLocalDevice]: PushNotificationEncoders.encodeLocalDevice,
[NSString stringWithFormat:@"%d", CodecTypePushChannelSubscription]: PushNotificationEncoders.encodePushChannelSubscription,
[NSString stringWithFormat:@"%d", CodecTypeUnNotificationSettings]: PushNotificationEncoders.encodeUNNotificationSettings,
[NSString stringWithFormat:@"%d", CodecTypeRemoteMessage]: PushNotificationEncoders.encodeRemoteMessage,
[NSString stringWithFormat:@"%d", CodecTypeCipherParams]: CryptoCodec.encodeCipherParams,
};
return [_handlers objectForKey:[NSString stringWithFormat:@"%@", type]];
}
Expand Down
56 changes: 28 additions & 28 deletions ios/Classes/codec/AblyPlatformConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@

@import Foundation;

typedef NS_ENUM(UInt8, _Value) {
ablyMessageCodecType = 128,
ablyEventMessageCodecType = 129,
clientOptionsCodecType = 130,
messageDataCodecType = 131,
messageExtrasCodecType = 132,
messageCodecType = 133,
tokenParamsCodecType = 134,
tokenDetailsCodecType = 135,
tokenRequestCodecType = 136,
restChannelOptionsCodecType = 137,
realtimeChannelOptionsCodecType = 138,
paginatedResultCodecType = 139,
restHistoryParamsCodecType = 140,
realtimeHistoryParamsCodecType = 141,
restPresenceParamsCodecType = 142,
presenceMessageCodecType = 143,
realtimePresenceParamsCodecType = 144,
deviceDetailsCodecType = 145,
localDeviceCodecType = 146,
pushChannelSubscriptionCodecType = 147,
unNotificationSettingsCodecType = 148,
remoteMessageCodecType = 149,
errorInfoCodecType = 150,
logLevelCodecType = 151,
connectionStateChangeCodecType = 152,
channelStateChangeCodecType = 153,
cipherParamsCodecType = 154,
typedef NS_ENUM(UInt8, CodecType) {
CodecTypeAblyMessage = 128,
CodecTypeAblyEventMessage = 129,
CodecTypeClientOptions = 130,
CodecTypeMessageData = 131,
CodecTypeMessageExtras = 132,
CodecTypeMessage = 133,
CodecTypeTokenParams = 134,
CodecTypeTokenDetails = 135,
CodecTypeTokenRequest = 136,
CodecTypeRestChannelOptions = 137,
CodecTypeRealtimeChannelOptions = 138,
CodecTypePaginatedResult = 139,
CodecTypeRestHistoryParams = 140,
CodecTypeRealtimeHistoryParams = 141,
CodecTypeRestPresenceParams = 142,
CodecTypePresenceMessage = 143,
CodecTypeRealtimePresenceParams = 144,
CodecTypeDeviceDetails = 145,
CodecTypeLocalDevice = 146,
CodecTypePushChannelSubscription = 147,
CodecTypeUnNotificationSettings = 148,
CodecTypeRemoteMessage = 149,
CodecTypeErrorInfo = 150,
CodecTypeLogLevel = 151,
CodecTypeConnectionStateChange = 152,
CodecTypeChannelStateChange = 153,
CodecTypeCipherParams = 154,
};


Expand Down

0 comments on commit 89cc7b2

Please sign in to comment.