| 197 | } |
| 198 | |
| 199 | size_t ProtobufArena::copyMessage(const ProtobufArena& fromArena, |
| 200 | size_t messageIndex, |
| 201 | ExceptionTracker& exceptionTracker) { |
| 202 | auto* message = fromArena.getMessage(messageIndex, exceptionTracker); |
| 203 | if (message == nullptr) { |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | // We just encode/decode to simplify the implementation |
| 208 | // In practice there should be almost never any cases where messages are transferred between arenas. |
| 209 | |
| 210 | VALDI_TRACE_META("Protobuf.copyMessage", message->getDescriptor()->name()); |
| 211 | |
| 212 | // The descriptors driving the encode/decode below belong to the source arena's |
| 213 | // factories' pool; serialize access to it against concurrent pool mutation. |
| 214 | auto factoryLocks = fromArena.lockRetainedMessageFactories(); |
| 215 | |
| 216 | auto encoded = message->encode(_includeAllFieldsDuringEncoding); |
| 217 | |
| 218 | // Also retain the message factories |
| 219 | for (const auto& messageFactory : fromArena._retainedMessageFactories) { |
| 220 | retainMessageFactory(messageFactory); |
| 221 | } |
| 222 | |
| 223 | auto outputMessage = createMessageForDescriptor(message->getDescriptor(), encoded.getSource()); |
| 224 | |
| 225 | if (!outputMessage->decode(encoded.data(), encoded.size(), exceptionTracker)) { |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | return outputMessage->getMessageIndex(); |
| 230 | } |
| 231 | |
| 232 | std::string ProtobufArena::messageToJSON(size_t messageIndex, |
| 233 | const Protobuf::JSONPrintOptions& printOptions, |
nothing calls this directly
no test coverage detected