[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MirageOS-devel] Binary Irmin slices



On 15 May 2015 at 15:49, Thomas Leonard <talex5@xxxxxxxxx> wrote:
> I'm trying to sync an Irmin repository from some js_of_ocaml to a
> native Mirage server. It was working with JSON briefly, except that my
> repository grew enough that to_json now results in a StackOverflow, so
> I'm trying the binary protocol instead. However, reading the data back
> seems to fail. I'm guessing a bit how the Tc API works, but this is
> what I tried:
>
> open Lwt
>
> module Store = Irmin.Basic(Irmin_mem.Make)(Irmin.Contents.String)
>
> let config = Irmin_mem.config ()
> let task s = Irmin.Task.create ~date:0L ~owner:"User" s
>
> let main =
>   Store.create config task >>= fun t ->
>   let t = t "test" in
>   Store.update t ["key"] "value" >>= fun () ->
>   Store.head t >>= function
>   | None -> assert false
>   | Some head ->
>   Store.export t ~min:[] ~max:[head] >>= fun slice ->
>   let buf = Cstruct.create (Store.Private.Slice.size_of slice) in
>   let rest = Store.Private.Slice.write slice buf in
>   assert (Cstruct.len rest = 0);
>   let _slice2 = Store.Private.Slice.read (Mstruct.of_cstruct buf) in
>   return ()
>
> let () =
>   Lwt_main.run main
>
>
> I was expecting _slice2 to be the same as slice, but instead I get an
> error during the read (even in native code):
>
> Fatal error: exception Ir_hash.Invalid("lueB+ïï1d|EïïïOïï<ïïkey")
>
> Should this work, or have I misunderstood the API?

It seems that Irmin.Contents.String overrides the default Tc.String
serialisation with one that doesn't include the length:

https://github.com/mirage/irmin/blob/ae42dab34d8451395910eb4cd534ee887a6871a5/lib/ir_contents.ml#L143

Why does it do this?


-- 
Dr Thomas Leonard        http://roscidus.com/blog/
GPG: DA98 25AE CAD0 8975 7CDA  BD8E 0713 3F96 CA74 D8BA

_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.