forked from apple/swift-protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add isInitialized Message protocol - Provide default isInitialized so the generator can emit a custom one as needed. - Add isInitialized to ExtensionFields so Message can call to it. - Add Internal.swift as a place to hold public code (because the generated code has to be able to call it), but that is not intended to be part of the "developer public" api. - Helpers for checking a map and repeated field for being initialized. - Generate isInitialized - Walk the message fields to decided if directly/indirectly can have messages with required fields. Re apple#98
- Loading branch information
Showing
8 changed files
with
367 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Sources/SwiftProtobuf/Message.swift - Message support | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See LICENSE.txt for license information: | ||
// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt | ||
// | ||
// ----------------------------------------------------------------------------- | ||
/// | ||
/// Internal helpers on Messages for the library. These are public | ||
/// just so the generated code can call them, but shouldn't be called | ||
/// by developers directly. | ||
/// | ||
// ----------------------------------------------------------------------------- | ||
|
||
|
||
import Foundation | ||
import Swift | ||
|
||
public struct Internal { | ||
private init() {} | ||
|
||
public static func areAllInitialized<M: Message>(_ listOfMessages: [M]) -> Bool { | ||
for msg in listOfMessages { | ||
if !msg.isInitialized { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
public static func areAllInitialized<K: Hashable, M: Message>(_ mapToMessages: [K: M]) -> Bool { | ||
for (_, msg) in mapToMessages { | ||
if !msg.isInitialized { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.