Skip to content
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

Merged
merged 4 commits into from
Feb 23, 2017

Conversation

thomasvl
Copy link
Collaborator

No description provided.

@thomasvl
Copy link
Collaborator Author

@tbkka - this should clear things for your unknowns work.
@allevato - merge() api look good?

Assuming this is good, I'll circle back and do followup PR to add explicit merge() tests (just cloning the required fields tests I did, but using merge instead).

/// 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,
Copy link
Collaborator

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).

Copy link
Collaborator Author

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. 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_mergeSerializedBytes?

Copy link
Collaborator Author

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])
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If this method throws"

Copy link
Collaborator Author

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.

@thomasvl thomasvl force-pushed the mergeSerializedData branch from c2120ff to bf83f29 Compare February 23, 2017 17:48
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.
@thomasvl thomasvl force-pushed the mergeSerializedData branch from bf83f29 to 0f28e51 Compare February 23, 2017 18:27
@thomasvl thomasvl merged commit b11100b into apple:master Feb 23, 2017
@thomasvl thomasvl deleted the mergeSerializedData branch February 23, 2017 18:28
ahmed-osama-saad pushed a commit to ahmed-osama-saad/swift-protobuf that referenced this pull request Oct 12, 2023
Queue up messages until event-sink has been created
Closes apple#307, apple#251, apple#137
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants