| 39 | } |
| 40 | |
| 41 | Status DecodeString(const TensorProto& proto, Tensor* tensor) { |
| 42 | auto pstr = tensor->Raw<std::string*>(); |
| 43 | auto start = proto.tensor_content().c_str(); |
| 44 | auto end = start + proto.tensor_content().size(); |
| 45 | for (int i = 0; i < tensor->NumElements(); ++i) { |
| 46 | if (start + sizeof(uint32_t) > end) { |
| 47 | return Status::Internal("Invalid tensor proto"); |
| 48 | } |
| 49 | uint32_t len = *reinterpret_cast<const uint32_t*>(start); |
| 50 | start += sizeof(uint32_t); |
| 51 | (*pstr)->resize(len); |
| 52 | if (start + len > end) { |
| 53 | return Status::Internal("Invalid tensor proto"); |
| 54 | } |
| 55 | (*pstr)->assign(start, len); |
| 56 | pstr++; |
| 57 | start += len; |
| 58 | } |
| 59 | return Status::OK(); |
| 60 | } |
| 61 | |
| 62 | } // namespace |
| 63 |
no test coverage detected