Skip to content

Commit

Permalink
Remove reference to api that are "hookable".
Browse files Browse the repository at this point in the history
These fall down in the face of modules. What's worse, is they
don't fail to build, the fail to apply in some cases, and to
understand it, a developer has to really understand how protocols
work/are resolved/etc.

We also were documenting the wrong method as a hook point.

So, rather than try to document all the things that do/don't work,
just stop documenting it, and allow future changes to not be
required to support it.

Issue #773 is open to look at provide better apis in the future for
customizing comparisons.
  • Loading branch information
thomasvl committed Jul 24, 2018
1 parent 3dec79b commit a31212e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 42 deletions.
20 changes: 0 additions & 20 deletions Documentation/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,6 @@ then the word `Message` is appended to the name.
For example, a `message Int` in the proto file will cause the
generator to emit a `struct IntMessage` to the generated Swift file.

### Overridable Message methods

You can redefine the following in manually-constructed extensions if you
want to override the default generated behavior for any reason:

```swift
// By default, this just calls `serializedText()`
public var debugDescription: String

// By default, this computes a simple hash over all of the
// defined fields and submessages.
public var hashValue: Int

// The == operator is implemented in terms of this method
// so that you can easily override the implementation.
// You may override this method, but you should never call it directly.
// The default generated implementation compares every field for equality.
public func isEqualTo(message: Example) -> Bool
```

## Enum API

Proto enums are translated to Swift enums in a fairly straightforward manner.
Expand Down
8 changes: 3 additions & 5 deletions Documentation/INTERNALS.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ use an additional type object at this point.

Many other facilities - not just serialization - can be built on
top of this same machinery.
For example, the default `hashValue` implementation uses the same
traversal machinery to iterate over all of the set fields and values
in order to compute the hash.
For example, the `hashValue` implementation uses the same traversal
machinery to iterate over all of the set fields and values in order
to compute the hash.

You can look at the runtime library to see more details about the
`Visitor` protocol and the various implementations in each encoder.
Expand Down Expand Up @@ -448,8 +448,6 @@ collected unknown field data onto the resulting message object.

TODO: initializers

TODO: isEqualTo

TODO: _protobuf_generated methods

# Enums
Expand Down
20 changes: 3 additions & 17 deletions Sources/SwiftProtobuf/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
/// }
///
/// The actual functionality is implemented either in the generated code or in
/// default implementations of the below methods and properties. Some of them,
/// including `hashValue` and `debugDescription`, are designed to let you
/// override the functionality in custom extensions to the generated code.
/// default implementations of the below methods and properties.
public protocol Message: CustomDebugStringConvertible {
/// Creates a new message with all of its fields initialized to their default
/// values.
Expand Down Expand Up @@ -108,11 +106,6 @@ public protocol Message: CustomDebugStringConvertible {
/// with the `Hashable` protocol.
var hashValue: Int { get }

/// A textual representation of this message's contents suitable for
/// debugging, for conformance with the `CustomDebugStringConvertible`
/// protocol.
var debugDescription: String { get }

/// Helper to compare `Message`s when not having a specific type to use
/// normal `Equatable`. `Equatable` is provided with specific generated
/// types.
Expand All @@ -129,22 +122,15 @@ public extension Message {
return true
}

/// A hash based on the message's full contents. Can be overridden
/// to improve performance and/or remove some values from being used for the
/// hash.
///
/// If you override this, make sure you maintain the property that values
/// which are `==` to each other have identical `hashValues`, providing a
/// custom implementation of `==` if necessary.
/// A hash based on the message's full contents.
var hashValue: Int {
var visitor = HashVisitor()
try? traverse(visitor: &visitor)
return visitor.hashValue
}

/// A description generated by recursively visiting all fields in the message,
/// including messages. May be overridden to improve readability and/or
/// performance.
/// including messages.
var debugDescription: String {
// TODO Ideally there would be something like serializeText() that can
// take a prefix so we could do something like:
Expand Down

0 comments on commit a31212e

Please sign in to comment.