| 215 | |
| 216 | |
| 217 | Status MessageToBuffer(const tensorflow::protobuf::MessageLite& in, |
| 218 | TF_Buffer* out) { |
| 219 | if (out->data != nullptr) { |
| 220 | return InvalidArgument("Passing non-empty TF_Buffer is invalid."); |
| 221 | } |
| 222 | const size_t proto_size = in.ByteSizeLong(); |
| 223 | void* buf = port::Malloc(proto_size); |
| 224 | if (buf == nullptr) { |
| 225 | return tensorflow::errors::ResourceExhausted( |
| 226 | "Failed to allocate memory to serialize message of type '", |
| 227 | in.GetTypeName(), "' and size ", proto_size); |
| 228 | } |
| 229 | if (!in.SerializeWithCachedSizesToArray(static_cast<uint8*>(buf))) { |
| 230 | port::Free(buf); |
| 231 | return InvalidArgument("Unable to serialize ", in.GetTypeName(), |
| 232 | " protocol buffer, perhaps the serialized size (", |
| 233 | proto_size, " bytes) is too large?"); |
| 234 | } |
| 235 | out->data = buf; |
| 236 | out->length = proto_size; |
| 237 | out->data_deallocator = [](void* data, size_t length) { port::Free(data); }; |
| 238 | return Status::OK(); |
| 239 | } |
| 240 | |
| 241 | void RecordMutation(TF_Graph* graph, const TF_Operation& op, |
| 242 | const char* mutation_type) { |
no test coverage detected