2222
2323#include " absl/status/status.h"
2424#include " absl/strings/cord.h"
25- #include " absl/strings/escaping.h"
2625#include < nlohmann/json.hpp>
2726#include " re2/re2.h"
27+ #include " tensorstore/internal/ascii_set.h"
2828#include " tensorstore/internal/json/value_as.h"
2929#include " tensorstore/internal/json_binding/bindable.h"
3030#include " tensorstore/internal/json_binding/json_binding.h"
3131#include " tensorstore/internal/json_binding/std_array.h"
3232#include " tensorstore/internal/json_binding/std_variant.h"
33- #include " tensorstore/internal/path.h"
3433#include " tensorstore/internal/uri_utils.h"
3534#include " tensorstore/json_serialization_options_base.h"
3635#include " tensorstore/kvstore/ocdbt/config.h"
3736#include " tensorstore/kvstore/ocdbt/format/btree.h"
37+ #include " tensorstore/kvstore/ocdbt/format/config.h"
3838#include " tensorstore/kvstore/ocdbt/format/indirect_data_reference.h"
3939#include " tensorstore/kvstore/ocdbt/format/manifest.h"
4040#include " tensorstore/kvstore/ocdbt/format/version_tree.h"
@@ -72,7 +72,7 @@ namespace jb = tensorstore::internal_json_binding;
7272constexpr auto ConfigBinder = jb::Compose<ConfigConstraints>(
7373 [](auto is_loading, const auto & options, auto * obj, auto * constraints) {
7474 if constexpr (is_loading) {
75- CreateConfig (constraints, *obj);
75+ TENSORSTORE_RETURN_IF_ERROR ( CreateConfig (* constraints, {}, *obj) );
7676 if (ConfigConstraints (*obj) != *constraints) {
7777 return absl::InvalidArgumentError (" Config is not fully specified" );
7878 }
@@ -92,11 +92,16 @@ static inline constexpr internal::AsciiSet
9292constexpr auto LabeledIndirectDataReferenceBinder =
9393 [](auto is_loading, const auto & options, auto * obj, auto * j) {
9494 if constexpr (is_loading) {
95- if (auto * s = j->template get_ptr < const std::string*> ()) {
96- TENSORSTORE_ASSIGN_OR_RETURN ( *obj,
97- LabeledIndirectDataReference::Parse (*s)) ;
95+ if (j->is_discarded ()) {
96+ *obj = LabeledIndirectDataReference{IndirectDataKind:: kBtreeNode ,
97+ IndirectDataReference::Missing ()} ;
9898 } else {
99- return internal_json::ExpectedError (*j, " string" );
99+ if (auto * s = j->template get_ptr <const std::string*>()) {
100+ TENSORSTORE_ASSIGN_OR_RETURN (
101+ *obj, LabeledIndirectDataReference::Parse (*s));
102+ } else {
103+ return internal_json::ExpectedError (*j, " string" );
104+ }
100105 }
101106 } else {
102107 if (obj->location .IsMissing ()) {
@@ -121,6 +126,11 @@ constexpr auto IndirectDataReferenceBinder(IndirectDataKind kind) {
121126 return jb::Compose<LabeledIndirectDataReference>(
122127 [kind](auto is_loading, const auto & options, auto * obj, auto * j) {
123128 if constexpr (is_loading) {
129+ if (j->kind != kind) {
130+ return absl::InvalidArgumentError (tensorstore::StrCat (
131+ " Indirect data reference kind mismatch: expected " , kind,
132+ " , got " , j->kind ));
133+ }
124134 *obj = j->location ;
125135 } else {
126136 j->location = *obj;
@@ -273,5 +283,21 @@ ::nlohmann::json Dump(const VersionTreeNode& node) {
273283 return jb::ToJson (node, VersionTreeNodeBinder).value ();
274284}
275285
286+ Result<absl::Cord> UndumpManifest (::nlohmann::json dumped_manifest) {
287+ TENSORSTORE_ASSIGN_OR_RETURN (
288+ auto manifest, jb::FromJson<Manifest>(dumped_manifest, ManifestBinder));
289+ return EncodeManifest (manifest, /* encode_as_single=*/ false );
290+ }
291+
292+ Result<absl::Cord> UndumpVersionTreeNode (::nlohmann::json dumped_config,
293+ ::nlohmann::json dumped_node) {
294+ TENSORSTORE_ASSIGN_OR_RETURN (
295+ auto config, jb::FromJson<Config>(dumped_config, ConfigBinder));
296+ TENSORSTORE_ASSIGN_OR_RETURN (
297+ auto node,
298+ jb::FromJson<VersionTreeNode>(dumped_node, VersionTreeNodeBinder));
299+ return EncodeVersionTreeNode (config, node);
300+ }
301+
276302} // namespace internal_ocdbt
277303} // namespace tensorstore
0 commit comments