diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2015-10-05 14:29:07 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2015-10-05 14:29:07 -0400 |
commit | 714466f0b6f4e052368f3450bda1f266f202c61f (patch) | |
tree | ec5e828cd20fc22434cad42552237c8d6ab4d972 | |
parent | 95c7ecaf18e1f06b135e4a01e40689258b761900 (diff) | |
download | sdl_ios-714466f0b6f4e052368f3450bda1f266f202c61f.tar.gz |
Format files
-rw-r--r-- | SmartDeviceLink-iOS/SmartDeviceLink/SDLHexUtility.m | 32 | ||||
-rw-r--r-- | SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m | 2 |
2 files changed, 19 insertions, 15 deletions
diff --git a/SmartDeviceLink-iOS/SmartDeviceLink/SDLHexUtility.m b/SmartDeviceLink-iOS/SmartDeviceLink/SDLHexUtility.m index 3de052a84..0787d804a 100644 --- a/SmartDeviceLink-iOS/SmartDeviceLink/SDLHexUtility.m +++ b/SmartDeviceLink-iOS/SmartDeviceLink/SDLHexUtility.m @@ -13,38 +13,42 @@ for (int i = 0; i < length; i++) { [ret appendFormat:@"%02X", ((Byte *)bytes)[i]]; } + return ret; } static inline char itoh(int i) { - if (i > 9) return 'A' + (i - 10); + if (i > 9) { + return 'A' + (i - 10); + } + return '0' + i; } -NSString* getHexString(NSData *data) { +NSString *getHexString(NSData *data) { NSUInteger length; unsigned char *buffer, *bytes; - + length = data.length; - bytes = (unsigned char*)data.bytes; - buffer = malloc(length*2); - + bytes = (unsigned char *)data.bytes; + buffer = malloc(length * 2); + for (NSUInteger i = 0; i < length; i++) { - buffer[i*2] = itoh((bytes[i] >> 4) & 0xF); - buffer[i*2+1] = itoh(bytes[i] & 0xF); + buffer[i * 2] = itoh((bytes[i] >> 4) & 0xF); + buffer[(i * 2) + 1] = itoh(bytes[i] & 0xF); } - - NSString* hexString = [[NSString alloc] initWithBytesNoCopy:buffer - length:length*2 + + NSString *hexString = [[NSString alloc] initWithBytesNoCopy:buffer + length:length * 2 encoding:NSASCIIStringEncoding freeWhenDone:YES]; - // HAX : https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/#//apple_ref/occ/instm/NSString/initWithBytesNoCopy:length:encoding:freeWhenDone: + // HAX: https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/#//apple_ref/occ/instm/NSString/initWithBytesNoCopy:length:encoding:freeWhenDone: // If there is an error allocating the string, we must free the buffer and fall back to the less performant method. if (!hexString) { free(buffer); - hexString = [SDLHexUtility getHexString:bytes - length:length]; + hexString = [SDLHexUtility getHexString:bytes length:length]; } + return hexString; } diff --git a/SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m b/SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m index 8829550df..9a2501a1e 100644 --- a/SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m +++ b/SmartDeviceLink-iOS/SmartDeviceLink/SDLTCPTransport.m @@ -82,7 +82,7 @@ static void TCPCallback(CFSocketRef socket, CFSocketCallBackType type, CFDataRef } [SDLDebugTool logInfo:[NSString stringWithFormat:@"Socket sendData error: %@", errorCause] withType:SDLDebugType_Transport_TCP toOutput:SDLDebugOutput_DeviceConsole]; - } + } } }); } |