Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/serialize.cc
- This file was added.
| #include "BLI_serialize.hh" | |||||
| #include "json.hpp" | |||||
| namespace blender::io::serialize { | |||||
| static void convert_to_json(nlohmann::json &j, const Value &value) | |||||
| { | |||||
| switch (value.type()) { | |||||
| case ValueType::String: { | |||||
| j = value.string_value(); | |||||
| break; | |||||
Severin: Didn't the documentation for this function say that there will be an assert for the type-match… | |||||
Done Inline ActionsWill adapt the documentation. seems like I had a different implementation in my head when writing the docs :-) jbakker: Will adapt the documentation. seems like I had a different implementation in my head when… | |||||
| } | |||||
Done Inline ActionsThis assumes that any Value with type_ == eValueType::String is a StringValue. This tight coupling is not documented at all! sybren: This assumes that any `Value` with `type_ == eValueType::String` is a `StringValue`. This tight… | |||||
| case ValueType::Int: { | |||||
| j = value.int_value(); | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| void JsonFormatter::serialize(std::ostream &os, Value &value) | |||||
| { | |||||
| nlohmann::json j; | |||||
| convert_to_json(j, value); | |||||
| os << j.dump(2); | |||||
| } | |||||
| } // namespace blender::io::serialize | |||||
Done Inline ActionsI would much prefer returning std::unique_ptrs here, rather than raw owning pointers. Especially since it's not documented that they are owning and need freeing :) Severin: I would much prefer returning `std::unique_ptr`s here, rather than raw owning pointers. | |||||
Done Inline ActionsThese should be extracted to their own functions. sybren: These should be extracted to their own functions. | |||||
Done Inline ActionsWhy is this necessary at all? sybren: Why is this necessary at all? | |||||
Done Inline ActionsWhat is this notation? sybren: What is this notation? | |||||
Done Inline ActionsSuch blocks should be their own function sybren: Such blocks should be their own function | |||||
Done Inline ActionsThen why are they (and this code) even here? sybren: Then why are they (and this code) even here? | |||||
Done Inline Actionswill → would sybren: will → would | |||||
Done Inline Actionswill → would sybren: will → would | |||||
Didn't the documentation for this function say that there will be an assert for the type-match as well?