summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-07-26 13:05:31 -0400
committerJoel Fischer <joeljfischer@gmail.com>2017-07-26 13:05:31 -0400
commit5dd7c586f823727e6950749eea536939cb683b1e (patch)
tree873eae6cf989b4fad743f59f8ac51c2dbb764d62
parentb651a9e0c579990e80f9c87df9e5f994e9030eda (diff)
downloadsdl_ios-5dd7c586f823727e6950749eea536939cb683b1e.tar.gz
Add documentation to control frame payload types
* Fix a bug in the start service ack v5 payload preventing the protocol version from being parsed * Add the Video service start service and start service ack payload objects
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj8
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadAudioStartServiceAck.h5
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadConstants.h4
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadConstants.m4
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadEndService.h1
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadNak.h1
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadRPCStartService.h1
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h5
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m2
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadVideoStartService.h16
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadVideoStartService.m101
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadVideoStartServiceAck.h34
-rw-r--r--SmartDeviceLink/SDLControlFramePayloadVideoStartServiceAck.m128
13 files changed, 307 insertions, 3 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index d50dca608..10da261ba 100644
--- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
+++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
@@ -905,6 +905,8 @@
5DB996581F268ECB002D8795 /* SDLControlFramePayloadAudioStartServiceAck.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DB996561F268ECB002D8795 /* SDLControlFramePayloadAudioStartServiceAck.m */; };
5DB9965C1F268F97002D8795 /* SDLControlFramePayloadVideoStartService.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DB9965A1F268F97002D8795 /* SDLControlFramePayloadVideoStartService.h */; };
5DB9965D1F268F97002D8795 /* SDLControlFramePayloadVideoStartService.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DB9965B1F268F97002D8795 /* SDLControlFramePayloadVideoStartService.m */; };
+ 5DB996601F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DB9965E1F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.h */; };
+ 5DB996611F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DB9965F1F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.m */; };
5DBAE0AB1D3588AC00CE00BF /* SDLNotificationDispatcherSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DBAE0AA1D3588AC00CE00BF /* SDLNotificationDispatcherSpec.m */; };
5DBAE0AD1D368D1A00CE00BF /* SDLResponseDispatcherSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DBAE0AC1D368D1A00CE00BF /* SDLResponseDispatcherSpec.m */; };
5DC978261B7A38640012C2F1 /* SDLGlobalsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DC978251B7A38640012C2F1 /* SDLGlobalsSpec.m */; };
@@ -1990,6 +1992,8 @@
5DB996561F268ECB002D8795 /* SDLControlFramePayloadAudioStartServiceAck.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLControlFramePayloadAudioStartServiceAck.m; sourceTree = "<group>"; };
5DB9965A1F268F97002D8795 /* SDLControlFramePayloadVideoStartService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLControlFramePayloadVideoStartService.h; sourceTree = "<group>"; };
5DB9965B1F268F97002D8795 /* SDLControlFramePayloadVideoStartService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLControlFramePayloadVideoStartService.m; sourceTree = "<group>"; };
+ 5DB9965E1F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLControlFramePayloadVideoStartServiceAck.h; sourceTree = "<group>"; };
+ 5DB9965F1F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLControlFramePayloadVideoStartServiceAck.m; sourceTree = "<group>"; };
5DBAE0AA1D3588AC00CE00BF /* SDLNotificationDispatcherSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLNotificationDispatcherSpec.m; path = DevAPISpecs/SDLNotificationDispatcherSpec.m; sourceTree = "<group>"; };
5DBAE0AC1D368D1A00CE00BF /* SDLResponseDispatcherSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLResponseDispatcherSpec.m; path = DevAPISpecs/SDLResponseDispatcherSpec.m; sourceTree = "<group>"; };
5DC978251B7A38640012C2F1 /* SDLGlobalsSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLGlobalsSpec.m; path = UtilitiesSpecs/SDLGlobalsSpec.m; sourceTree = "<group>"; };
@@ -3858,6 +3862,8 @@
children = (
5DB9965A1F268F97002D8795 /* SDLControlFramePayloadVideoStartService.h */,
5DB9965B1F268F97002D8795 /* SDLControlFramePayloadVideoStartService.m */,
+ 5DB9965E1F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.h */,
+ 5DB9965F1F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.m */,
);
name = "Video Service";
sourceTree = "<group>";
@@ -4235,6 +4241,7 @@
5D61FE091A84238C00846EE7 /* SDLVehicleDataType.h in Headers */,
5DCC19A01B8221F3004FFAD9 /* SDLURLSession.h in Headers */,
5D61FDB11A84238C00846EE7 /* SDLSubscribeVehicleData.h in Headers */,
+ 5DB996601F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.h in Headers */,
5DCF76F51ACDBAD300BB647B /* SDLSendLocation.h in Headers */,
5D61FC9E1A84238C00846EE7 /* SDLEncodedSyncPData.h in Headers */,
5D61FC291A84238C00846EE7 /* SDLAbstractProtocol.h in Headers */,
@@ -4781,6 +4788,7 @@
5D61FCFE1A84238C00846EE7 /* SDLObjectWithPriority.m in Sources */,
5D61FC401A84238C00846EE7 /* SDLAmbientLightStatus.m in Sources */,
5D61FC951A84238C00846EE7 /* SDLDriverDistractionState.m in Sources */,
+ 5DB996611F28C6ED002D8795 /* SDLControlFramePayloadVideoStartServiceAck.m in Sources */,
5D61FD961A84238C00846EE7 /* SDLShowResponse.m in Sources */,
5D61FD981A84238C00846EE7 /* SDLSingleTireStatus.m in Sources */,
5D61FD511A84238C00846EE7 /* SDLProxy.m in Sources */,
diff --git a/SmartDeviceLink/SDLControlFramePayloadAudioStartServiceAck.h b/SmartDeviceLink/SDLControlFramePayloadAudioStartServiceAck.h
index 4dbfe041b..eb54abaa0 100644
--- a/SmartDeviceLink/SDLControlFramePayloadAudioStartServiceAck.h
+++ b/SmartDeviceLink/SDLControlFramePayloadAudioStartServiceAck.h
@@ -12,9 +12,12 @@
NS_ASSUME_NONNULL_BEGIN
-@interface SDLControlFramePayloadAudioStartServiceAck : NSObject
+@interface SDLControlFramePayloadAudioStartServiceAck : NSObject <SDLControlFramePayloadType>
+/// Hash ID to identify this service and used when sending an EndService control frame
@property (assign, nonatomic, readonly) int32_t hashId;
+
+/// Max transport unit to be used for this service. If not included the client should use the one set via the RPC service or protocol version default.
@property (assign, nonatomic, readonly) int64_t mtu;
- (instancetype)initWithHashId:(int32_t)hashId mtu:(int64_t)mtu;
diff --git a/SmartDeviceLink/SDLControlFramePayloadConstants.h b/SmartDeviceLink/SDLControlFramePayloadConstants.h
index a207e9d0a..f95b90ef8 100644
--- a/SmartDeviceLink/SDLControlFramePayloadConstants.h
+++ b/SmartDeviceLink/SDLControlFramePayloadConstants.h
@@ -15,3 +15,7 @@ extern char *const SDLControlFrameProtocolVersionKey;
extern char *const SDLControlFrameHashIdKey;
extern char *const SDLControlFrameMTUKey;
extern char *const SDLControlFrameRejectedParams;
+extern char *const SDLControlFrameVideoProtocolKey;
+extern char *const SDLControlFrameVideoCodecKey;
+extern char *const SDLControlFrameHeightKey;
+extern char *const SDLControlFrameWidthKey;
diff --git a/SmartDeviceLink/SDLControlFramePayloadConstants.m b/SmartDeviceLink/SDLControlFramePayloadConstants.m
index 6dab9c2ca..8d9965f37 100644
--- a/SmartDeviceLink/SDLControlFramePayloadConstants.m
+++ b/SmartDeviceLink/SDLControlFramePayloadConstants.m
@@ -15,3 +15,7 @@ char *const SDLControlFrameProtocolVersionKey = "protocolVersion";
char *const SDLControlFrameHashIdKey = "hashId";
char *const SDLControlFrameMTUKey = "mtu";
char *const SDLControlFrameRejectedParams = "rejectedParams";
+char *const SDLControlFrameVideoProtocolKey = "videoProtocol";
+char *const SDLControlFrameVideoCodecKey = "videoCodec";
+char *const SDLControlFrameHeightKey = "height";
+char *const SDLControlFrameWidthKey = "width";
diff --git a/SmartDeviceLink/SDLControlFramePayloadEndService.h b/SmartDeviceLink/SDLControlFramePayloadEndService.h
index 5a06a4c21..17790ab9e 100644
--- a/SmartDeviceLink/SDLControlFramePayloadEndService.h
+++ b/SmartDeviceLink/SDLControlFramePayloadEndService.h
@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLControlFramePayloadEndService : NSObject <SDLControlFramePayloadType>
+/// Hash ID supplied in the StartServiceACK for this service type
@property (assign, nonatomic, readonly) int32_t hashId;
- (instancetype)initWithHashId:(int32_t)hashId;
diff --git a/SmartDeviceLink/SDLControlFramePayloadNak.h b/SmartDeviceLink/SDLControlFramePayloadNak.h
index 32879357b..41781cb2e 100644
--- a/SmartDeviceLink/SDLControlFramePayloadNak.h
+++ b/SmartDeviceLink/SDLControlFramePayloadNak.h
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLControlFramePayloadNak : NSObject <SDLControlFramePayloadType>
+/// An array of rejected parameters such as: [`hashId`]
@property (copy, nonatomic, readonly, nullable) NSArray<NSString *> *rejectedParams;
- (instancetype)initWithRejectedParams:(nullable NSArray<NSString *> *)rejectedParams;
diff --git a/SmartDeviceLink/SDLControlFramePayloadRPCStartService.h b/SmartDeviceLink/SDLControlFramePayloadRPCStartService.h
index 20acee9d1..7519e26f9 100644
--- a/SmartDeviceLink/SDLControlFramePayloadRPCStartService.h
+++ b/SmartDeviceLink/SDLControlFramePayloadRPCStartService.h
@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLControlFramePayloadRPCStartService : NSObject <SDLControlFramePayloadType>
+/// The max version of protocol version supported by client requesting service to start. Must be in the format "Major.Minor.Patch"
@property (copy, nonatomic, readonly, nullable) NSString *protocolVersion;
- (instancetype)initWithMajorVersion:(NSUInteger)majorVersion minorVersion:(NSUInteger)minorVersion patchVersion:(NSUInteger)patchVersion;
diff --git a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h
index 40b59980d..50ad5b1d0 100644
--- a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h
+++ b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.h
@@ -14,8 +14,13 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLControlFramePayloadRPCStartServiceAck : NSObject <SDLControlFramePayloadType>
+/// Hash ID to identify this service and used when sending an EndService control frame
@property (assign, nonatomic, readonly) int32_t hashId;
+
+/// Max transport unit to be used for this service
@property (assign, nonatomic, readonly) int64_t mtu;
+
+/// The negotiated version of the protocol. Must be in the format "Major.Minor.Patch"
@property (copy, nonatomic, readonly, nullable) NSString *protocolVersion;
- (instancetype)initWithHashId:(int32_t)hashId mtu:(int64_t)mtu majorVersion:(NSUInteger)major minorVersion:(NSUInteger)minor patchVersion:(NSUInteger)patch;
diff --git a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m
index dafcdfe8f..9d635de34 100644
--- a/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m
+++ b/SmartDeviceLink/SDLControlFramePayloadRPCStartServiceAck.m
@@ -68,7 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
bson_object_put_int64(&payloadObject, SDLControlFrameMTUKey, self.mtu);
}
- if (self.protocolVersion == nil) {
+ if (self.protocolVersion != nil) {
bson_object_put_string(&payloadObject, SDLControlFrameProtocolVersionKey, (char *)self.protocolVersion.UTF8String);
}
diff --git a/SmartDeviceLink/SDLControlFramePayloadVideoStartService.h b/SmartDeviceLink/SDLControlFramePayloadVideoStartService.h
index 5c37828b5..175ec1f72 100644
--- a/SmartDeviceLink/SDLControlFramePayloadVideoStartService.h
+++ b/SmartDeviceLink/SDLControlFramePayloadVideoStartService.h
@@ -8,6 +8,20 @@
#import <Foundation/Foundation.h>
-@interface SDLControlFramePayloadVideoStartService : NSObject
+#import "SDLControlFramePayloadType.h"
+
+@interface SDLControlFramePayloadVideoStartService : NSObject <SDLControlFramePayloadType>
+
+/// Desired height in pixels from the client requesting the video service to start
+@property (assign, nonatomic, readonly) int32_t height;
+
+/// Desired width in pixels from the client requesting the video service to start
+@property (assign, nonatomic, readonly) int32_t width;
+
+/// Desired video protocol to be used. See VideoStreamingProtocol RPC
+@property (copy, nonatomic, readonly) NSString *videoProtocol;
+
+/// Desired video codec to be used. See VideoStreamingCodec RPC
+@property (copy, nonatomic, readonly) NSString *videoCodec;
@end
diff --git a/SmartDeviceLink/SDLControlFramePayloadVideoStartService.m b/SmartDeviceLink/SDLControlFramePayloadVideoStartService.m
index a9e04986d..013f36dd2 100644
--- a/SmartDeviceLink/SDLControlFramePayloadVideoStartService.m
+++ b/SmartDeviceLink/SDLControlFramePayloadVideoStartService.m
@@ -8,6 +8,107 @@
#import "SDLControlFramePayloadVideoStartService.h"
+#import "bson_object.h"
+#import "SDLControlFramePayloadConstants.h"
+
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface SDLControlFramePayloadVideoStartService ()
+
+@property (assign, nonatomic, readwrite) int32_t height;
+@property (assign, nonatomic, readwrite) int32_t width;
+@property (copy, nonatomic, readwrite) NSString *videoProtocol;
+@property (copy, nonatomic, readwrite) NSString *videoCodec;
+
+@end
+
@implementation SDLControlFramePayloadVideoStartService
+- (instancetype)initWithVideoHeight:(int32_t)height width:(int32_t)width protocol:(NSString *)protocol codec:(NSString *)codec {
+ self = [super init];
+ if (!self) return nil;
+
+ _height = height;
+ _width = width;
+ _videoProtocol = protocol;
+ _videoCodec = codec;
+
+ return self;
+}
+
+- (instancetype)initWithData:(nullable NSData *)data {
+ self = [super init];
+ if (!self) return nil;
+
+ _height = SDLControlFrameInt32NotFound;
+ _width = SDLControlFrameInt32NotFound;
+
+ if (data != nil) {
+ [self sdl_parse:data];
+ }
+
+ return self;
+}
+
+- (nullable NSData *)data {
+ if (self.height == SDLControlFrameInt32NotFound
+ && self.width == SDLControlFrameInt32NotFound
+ && self.videoProtocol == nil
+ && self.videoCodec == nil) {
+ return nil;
+ }
+
+ BsonObject payloadObject;
+ bson_object_initialize_default(&payloadObject);
+
+ if (self.height != SDLControlFrameInt32NotFound) {
+ bson_object_put_int32(&payloadObject, SDLControlFrameHeightKey, self.height);
+ }
+
+ if (self.width != SDLControlFrameInt32NotFound) {
+ bson_object_put_int32(&payloadObject, SDLControlFrameWidthKey, self.width);
+ }
+
+ if (self.videoProtocol != nil) {
+ bson_object_put_string(&payloadObject, SDLControlFrameVideoProtocolKey, (char *)self.videoProtocol.UTF8String);
+ }
+
+ if (self.videoCodec != nil) {
+ bson_object_put_string(&payloadObject, SDLControlFrameVideoCodecKey, (char *)self.videoCodec.UTF8String);
+ }
+
+ BytePtr bsonData = bson_object_to_bytes(&payloadObject);
+ NSUInteger length = bson_object_size(&payloadObject);
+
+ bson_object_deinitialize(&payloadObject);
+
+ return [[NSData alloc] initWithBytes:bsonData length:length];
+}
+
+- (void)sdl_parse:(NSData *)data {
+ BsonObject payloadObject = bson_object_from_bytes((BytePtr)data.bytes);
+
+ self.height = bson_object_get_int32(&payloadObject, SDLControlFrameHeightKey);
+ self.width = bson_object_get_int32(&payloadObject, SDLControlFrameWidthKey);
+
+ char *utf8String = bson_object_get_string(&payloadObject, SDLControlFrameVideoProtocolKey);
+ if (utf8String != NULL) {
+ self.videoProtocol = [NSString stringWithUTF8String:utf8String];
+ }
+
+ utf8String = bson_object_get_string(&payloadObject, SDLControlFrameVideoCodecKey);
+ if (utf8String != NULL) {
+ self.videoCodec = [NSString stringWithUTF8String:utf8String];
+ }
+
+ bson_object_deinitialize(&payloadObject);
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@>: Width: %d, Height: %d, Protocol: %@, Codec: %@", NSStringFromClass(self.class), self.width, self.height, self.videoProtocol, self.videoCodec];
+}
+
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLControlFramePayloadVideoStartServiceAck.h b/SmartDeviceLink/SDLControlFramePayloadVideoStartServiceAck.h
new file mode 100644
index 000000000..a42aba2ee
--- /dev/null
+++ b/SmartDeviceLink/SDLControlFramePayloadVideoStartServiceAck.h
@@ -0,0 +1,34 @@
+//
+// SDLControlFramePayloadVideoStartServiceAck.h
+// SmartDeviceLink-iOS
+//
+// Created by Joel Fischer on 7/26/17.
+// Copyright © 2017 smartdevicelink. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+#import "SDLControlFramePayloadType.h"
+
+
+@interface SDLControlFramePayloadVideoStartServiceAck : NSObject <SDLControlFramePayloadType>
+
+/// Hash ID to identify this service and used when sending an EndService control frame
+@property (assign, nonatomic, readonly) int32_t hashId;
+
+/// Max transport unit to be used for this service
+@property (assign, nonatomic, readonly) int64_t mtu;
+
+/// Accepted height in pixels from the client requesting the video service to start
+@property (assign, nonatomic, readonly) int32_t height;
+
+/// Accepted width in pixels from the client requesting the video service to start
+@property (assign, nonatomic, readonly) int32_t width;
+
+/// Accepted video protocol to be used. See VideoStreamingProtocol RPC
+@property (copy, nonatomic, readonly) NSString *videoProtocol;
+
+/// Accepted video codec to be used. See VideoStreamingCodec RPC
+@property (copy, nonatomic, readonly) NSString *videoCodec;
+
+@end
diff --git a/SmartDeviceLink/SDLControlFramePayloadVideoStartServiceAck.m b/SmartDeviceLink/SDLControlFramePayloadVideoStartServiceAck.m
new file mode 100644
index 000000000..4aeed4a1a
--- /dev/null
+++ b/SmartDeviceLink/SDLControlFramePayloadVideoStartServiceAck.m
@@ -0,0 +1,128 @@
+//
+// SDLControlFramePayloadVideoStartServiceAck.m
+// SmartDeviceLink-iOS
+//
+// Created by Joel Fischer on 7/26/17.
+// Copyright © 2017 smartdevicelink. All rights reserved.
+//
+
+#import "SDLControlFramePayloadVideoStartServiceAck.h"
+
+#import "bson_object.h"
+#import "SDLControlFramePayloadConstants.h"
+
+
+@interface SDLControlFramePayloadVideoStartServiceAck ()
+
+@property (assign, nonatomic, readwrite) int32_t hashId;
+@property (assign, nonatomic, readwrite) int64_t mtu;
+@property (assign, nonatomic, readwrite) int32_t height;
+@property (assign, nonatomic, readwrite) int32_t width;
+@property (copy, nonatomic, readwrite) NSString *videoProtocol;
+@property (copy, nonatomic, readwrite) NSString *videoCodec;
+
+@end
+
+@implementation SDLControlFramePayloadVideoStartServiceAck
+
+- (instancetype)initWithHashId:(int32_t)hashId mtu:(int64_t)mtu videoHeight:(int32_t)height width:(int32_t)width protocol:(NSString *)protocol codec:(NSString *)codec {
+ self = [super init];
+ if (!self) return nil;
+
+ _hashId = hashId;
+ _mtu = mtu;
+ _height = height;
+ _width = width;
+ _videoProtocol = protocol;
+ _videoCodec = codec;
+
+ return self;
+}
+
+- (instancetype)initWithData:(nullable NSData *)data {
+ self = [super init];
+ if (!self) return nil;
+
+ _hashId = SDLControlFrameInt32NotFound;
+ _mtu = SDLControlFrameInt64NotFound;
+ _height = SDLControlFrameInt32NotFound;
+ _width = SDLControlFrameInt32NotFound;
+
+ if (data != nil) {
+ [self sdl_parse:data];
+ }
+
+ return self;
+}
+
+- (nullable NSData *)data {
+ if (self.hashId == SDLControlFrameInt32NotFound
+ && self.mtu == SDLControlFrameInt64NotFound
+ && self.height == SDLControlFrameInt32NotFound
+ && self.width == SDLControlFrameInt32NotFound
+ && self.videoProtocol == nil
+ && self.videoCodec == nil) {
+ return nil;
+ }
+
+ BsonObject payloadObject;
+ bson_object_initialize_default(&payloadObject);
+
+ if (self.hashId != SDLControlFrameInt32NotFound) {
+ bson_object_put_int32(&payloadObject, SDLControlFrameHashIdKey, self.hashId);
+ }
+
+ if (self.mtu != SDLControlFrameInt64NotFound) {
+ bson_object_put_int64(&payloadObject, SDLControlFrameMTUKey, self.mtu);
+ }
+
+ if (self.height != SDLControlFrameInt32NotFound) {
+ bson_object_put_int32(&payloadObject, SDLControlFrameHeightKey, self.height);
+ }
+
+ if (self.width != SDLControlFrameInt32NotFound) {
+ bson_object_put_int32(&payloadObject, SDLControlFrameWidthKey, self.width);
+ }
+
+ if (self.videoProtocol != nil) {
+ bson_object_put_string(&payloadObject, SDLControlFrameVideoProtocolKey, (char *)self.videoProtocol.UTF8String);
+ }
+
+ if (self.videoCodec != nil) {
+ bson_object_put_string(&payloadObject, SDLControlFrameVideoCodecKey, (char *)self.videoCodec.UTF8String);
+ }
+
+ BytePtr bsonData = bson_object_to_bytes(&payloadObject);
+ NSUInteger length = bson_object_size(&payloadObject);
+
+ bson_object_deinitialize(&payloadObject);
+
+ return [[NSData alloc] initWithBytes:bsonData length:length];
+}
+
+- (void)sdl_parse:(NSData *)data {
+ BsonObject payloadObject = bson_object_from_bytes((BytePtr)data.bytes);
+
+ self.hashId = bson_object_get_int32(&payloadObject, SDLControlFrameHashIdKey);
+ self.mtu = bson_object_get_int64(&payloadObject, SDLControlFrameMTUKey);
+ self.height = bson_object_get_int32(&payloadObject, SDLControlFrameHeightKey);
+ self.width = bson_object_get_int32(&payloadObject, SDLControlFrameWidthKey);
+
+ char *utf8String = bson_object_get_string(&payloadObject, SDLControlFrameVideoProtocolKey);
+ if (utf8String != NULL) {
+ self.videoProtocol = [NSString stringWithUTF8String:utf8String];
+ }
+
+ utf8String = bson_object_get_string(&payloadObject, SDLControlFrameVideoCodecKey);
+ if (utf8String != NULL) {
+ self.videoCodec = [NSString stringWithUTF8String:utf8String];
+ }
+
+ bson_object_deinitialize(&payloadObject);
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@>: Hash Id: %d, MTU: %lld, Width: %d, Height: %d, Protocol: %@, Codec: %@", NSStringFromClass(self.class), self.hashId, self.mtu, self.width, self.height, self.videoProtocol, self.videoCodec];
+}
+
+@end