-
Notifications
You must be signed in to change notification settings - Fork 466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a merge method, update unknown tests to use valid binary input. #307
Conversation
/// When `partial` is `true`, then partial messages are allowed, and | ||
/// `Message.isInitialized` is not checked. | ||
/// - Throws: An instance of `BinaryDecodingError` on failure. | ||
mutating func merge(serializedData data: Data, extensions: ExtensionSet? = nil, partial: Bool = false) throws { | ||
if !data.isEmpty { | ||
try data.withUnsafeBytes { (pointer: UnsafePointer<UInt8>) in | ||
try decodeBinary(from: pointer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should decodeBinary
be renamed merge
as well? It does the same thing (only accepting a pointer/count instead of a Data object).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, also prefixed the new name with \_
since it isn't really a public symbol.
@allevato I'm assuming you'll give me a better name for the method. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_mergeSerializedBytes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
msg1.unknownFields.append(protobufData: Data(bytes: [1, 2])) | ||
assertUnknownFields(msg1, [1, 2]) | ||
try msg1.merge(serializedData: Data(bytes: [24, 1])) // Field 3, varint | ||
assertUnknownFields(msg1, [24, 1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Since you're removing the only use of unknownFields.append outside of the library, would you mind marking the append
method internal
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/// Updates the message by decoding the Protocol Buffer binary serialization | ||
/// format data into this message. | ||
/// | ||
/// - Note: If the api does throw, the message may still have been mutated by the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"If this method throws"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and new set of diffs posted merging this into the original.
c2120ff
to
bf83f29
Compare
Rename decodeBinary(from:count:extensions:) to _mergeSerializedBytes(from:count:extensions:) since it merges into the existing message and to tag it as an internal detail.
bf83f29
to
0f28e51
Compare
No description provided.