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

Method decodeFromJSON

valdi_protobuf/src/valdi_protobuf/Message.cpp:224–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222}
223
224bool Message::decodeFromJSON(std::string_view json, ExceptionTracker& exceptionTracker) {
225 if (_descriptor == nullptr) {
226 exceptionTracker.onError("Cannot parse from JSON without a descriptor");
227 return false;
228 }
229
230 JSONHelper jsonHelper(_descriptor, reinterpret_cast<const Byte*>(json.data()), json.size());
231
232 auto result = google::protobuf::util::JsonToBinaryStream(jsonHelper.typeResolver,
233 jsonHelper.typeUrl,
234 &jsonHelper.inputStream,
235 &jsonHelper.outputStream,
236 google::protobuf::util::JsonParseOptions());
237 if (!result.ok()) {
238 exceptionTracker.onError(result.message());
239 return false;
240 }
241
242 auto buffer = makeShared<ByteBuffer>();
243 buffer->set(reinterpret_cast<const Byte*>(jsonHelper.output.data()),
244 reinterpret_cast<const Byte*>(jsonHelper.output.data() + jsonHelper.output.size()));
245 _dataSource = buffer;
246
247 return decode(buffer->data(), buffer->size(), exceptionTracker);
248}
249
250Ref<Message> Message::clone() const {
251 auto out = makeShared<Message>(_descriptor, _dataSource);

Callers 2

decodeMessageFromJSONMethod · 0.80
parseFromJSONMethod · 0.80

Calls 6

decodeFunction · 0.85
messageMethod · 0.80
onErrorMethod · 0.65
setMethod · 0.65
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected