| 184 | } |
| 185 | |
| 186 | bool Message::Equals(const Message& other) const { |
| 187 | int64_t metadata_bytes = std::min(metadata()->size(), other.metadata()->size()); |
| 188 | |
| 189 | if (!metadata()->Equals(*other.metadata(), metadata_bytes)) { |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | // Compare bodies, if they have them |
| 194 | auto this_body = body(); |
| 195 | auto other_body = other.body(); |
| 196 | |
| 197 | const bool this_has_body = (this_body != nullptr) && (this_body->size() > 0); |
| 198 | const bool other_has_body = (other_body != nullptr) && (other_body->size() > 0); |
| 199 | |
| 200 | if (this_has_body && other_has_body) { |
| 201 | return this_body->Equals(*other_body); |
| 202 | } else if (this_has_body ^ other_has_body) { |
| 203 | // One has a body but not the other |
| 204 | return false; |
| 205 | } else { |
| 206 | // Neither has a body |
| 207 | return true; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | Result<std::unique_ptr<Message>> Message::ReadFrom(std::shared_ptr<Buffer> metadata, |
| 212 | io::InputStream* stream) { |