From 3af104259308b507de6ee0a05be3024c617a7b61 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 18 Jun 2017 00:50:49 +0200 Subject: [PATCH] Fix fs_to_write() to serialize headers correctly --- .../src/file_abstraction/stdio/mapper/json.rs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libimagstore/src/file_abstraction/stdio/mapper/json.rs b/libimagstore/src/file_abstraction/stdio/mapper/json.rs index 5411d002..761e290b 100644 --- a/libimagstore/src/file_abstraction/stdio/mapper/json.rs +++ b/libimagstore/src/file_abstraction/stdio/mapper/json.rs @@ -103,10 +103,18 @@ impl Mapper for JsonMapper { } fn fs_to_write(&self, hm: &mut HashMap>>, out: &mut W) -> Result<()> { + use util::entry_buffer_to_header_content; + + #[derive(Serialize, Deserialize)] + struct Entry { + header: ::toml::Value, + content: String, + } + #[derive(Serialize)] struct OutDocument { version: String, - store: HashMap, + store: HashMap, } let mut doc = OutDocument { @@ -117,8 +125,14 @@ impl Mapper for JsonMapper { for (key, value) in hm.drain() { let res = String::from_utf8(value.into_inner()) .map_err_into(SEK::IoError) - .map(|entrystr| { - doc.store.insert(key, entrystr); + .and_then(|buf| entry_buffer_to_header_content(&buf)) + .map(|(header, content)| { + let entry = Entry { + header: header, + content: content + }; + + doc.store.insert(key, entry); }) .map(|_| ());