 
 extension AnyMessageStorage {
   var hashValue: Int {
-    var hash: Int = 0
-    hash = (hash &* 16777619) ^ _typeURL.hashValue
-    if let v = _valueData {
-      hash = (hash &* 16777619) ^ v.hashValue
-    }
-    if let m = _message {
-      hash = (hash &* 16777619) ^ m.hashValue
-    }
+    var hash: Int = i_2166136261
+    if !_typeURL.isEmpty {
+      hash = (hash &* i_16777619) ^ _typeURL.hashValue
+    }
+    // Can't use _valueData for a few reasons:
+    // 1. Since decode is done on demand, two objects could be equal
+    //    but created differently (one from JSON, one for Message, etc.),
+    //    and the hashes have to be equal even if we don't have data yet.
+    // 2. map<> serialization order is undefined. At the time of writing
+    //    the Swift, Objective-C, and Go runtimes all tend to have random
+    //    orders, so the messages could be identical, but in binary form
+    //    they could differ.
     return hash
   }
 

// -----------------------------------------------------------------------------

import Foundation

fileprivate func serializeAnyJSON(for message: Message, typeURL: String) throws -> String {
  var visitor = try JSONEncodingVisitor(message: message)

      return false
    }

    // Since the library does lazy Any decode, equality is a very hard problem.
    // It things exactly match, that's pretty easy, otherwise, one ends up having
    // to error on saying they aren't equal.
    //
    // The best option would be to have Message forms and compare those, as that
    // removes issues like map<> serialization order, some other protocol buffer
    // implementation details/bugs around serialized form order, etc.; but that
    // would also greatly slow down equality tests.
    //
    // Despite the problems with binary serialization, that may be the best bet
    // as looking at most other language implementations around Any they don't
    // do lazy decode and instead keep all the `value` fields in binary form and
    // end up just comparing those binary fields when comparing Anys.

    // If both have messages, check if they are the same.
//    if let myMsg = _message, let otherMsg = other._message, type(of: myMsg) == type(of: otherMsg) {
//      // There doesn't seem to be a way to use `==` or `_protobuf_generated_isEqualTo`
//      // since _MessageImplementationBase has a constraint one can't do
//      // `as? _MessageImplementationBase`.
//      if let myMsg = myMsg as? _MessageImplementationBase, let otherMsg = otherMsg as? _MessageImplementationBase {
//        if (myMsg._protobuf_generated_isEqualTo(other: otherMsg)) {
//          return true
//        }
//      }
//    }

    // If both have serialized data, and they exactly match; the messages are equal.
    // Because there could be map in the message, the fact that the data isn't the
    // same doesn't always mean the messages aren't equal.
    if let myValue = _valueData, let otherValue = other._valueData, myValue == otherValue {
      return true
    }
