| 49 | } |
| 50 | |
| 51 | bool SnappyDecompress(const butil::IOBuf& data, google::protobuf::Message* msg) { |
| 52 | butil::IOBuf binary_pb; |
| 53 | if (!SnappyDecompress(data, &binary_pb)) { |
| 54 | LOG(WARNING) << "Fail to snappy::Uncompress, size=" << data.size(); |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | bool ok; |
| 59 | butil::IOBufAsZeroCopyInputStream stream(binary_pb); |
| 60 | if (msg->GetDescriptor() == Deserializer::descriptor()) { |
| 61 | ok = ((Deserializer*)msg)->DeserializeFrom(&stream); |
| 62 | } else { |
| 63 | ok = msg->ParseFromZeroCopyStream(&stream); |
| 64 | } |
| 65 | if (!ok) { |
| 66 | LOG(WARNING) << "Fail to eserialize input message=" |
| 67 | << msg->GetDescriptor()->full_name(); |
| 68 | } |
| 69 | return ok; |
| 70 | } |
| 71 | |
| 72 | bool SnappyCompress(const butil::IOBuf& in, butil::IOBuf* out) { |
| 73 | butil::IOBufAsSnappySource source(in); |