Allow CGFloat values to be serialised. #1309
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description & motivation
As the title says, it is handy to be able to map a CGFloat value to a Double for the purposes of encoding it in the
Serializer
types.This came about when the
VideoSize
type went away. It was replaced by aCGSize
which returnsCGFloat
types for thewidth
andheight
properties. In themakeMetaData
function on anRTMPStream
, these properties are assigned as values to keys in the dictionary:The only problem is that they fail to serialise when going through the
func serialize(_ value: Any?) -> Self
function inAMF0Serializer
, as it doesn't handleCGFloat
data types.Please let me know if you foresee any issues with the proposed solution. It should be additive only. In the interest of consistency, I've made the change in both
AMF0Serializer
andAMF3Serializer
. If there's a reason it should be in one and not the other, I'm happy to update.Alternatives considered
I also considered fixing the problem at the point we add the properties to the dictionary, e.g:
But ultimately decided making the serialiser code more robust could help prevent against similar issues in the future, instead of fixing just the specific situation with video resolution here.
If you'd prefer the change above where the values are cast to
Double
, I'm happy to make that change instead. I understand if there's a reluctance to use aCGFloat
type in this library as it's not in the Swift language itself. However, I noteCGFloat
is used in other places, and that the file I've edited doesimport Foundation
so I figure it should be okay.Type of change
Please delete options that are not relevant.