MCPcopy Create free account
hub / github.com/Snapchat/Valdi / copyMessage

Method copyMessage

valdi/src/valdi/runtime/JavaScript/Modules/ProtobufArena.cpp:199–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199size_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
232std::string ProtobufArena::messageToJSON(size_t messageIndex,
233 const Protobuf::JSONPrintOptions& printOptions,

Callers

nothing calls this directly

Calls 9

getDescriptorMethod · 0.80
getMessageIndexMethod · 0.80
getMessageMethod · 0.65
nameMethod · 0.65
encodeMethod · 0.65
decodeMethod · 0.65
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected