anchor.diff:      MetaBin = <<KeyLen:32/integer, KeyBin/binary, ValueLen:32/integer, ValueBin/binary>>,
       {Elems, <<RestBin/binary, MetaBin/binary>>}.
   
  +%% @doc Encode the contents of a riak object, either using
  +%% term_to_binary (if Enc == erlang), or msgpack encoding (if Enc ==
  +%% msgpack)
  +encode(Bin, Enc) when Enc == erlang ->
  +    encode_maybe_binary(Bin);
  +encode(Bin, Enc) when Enc == msgpack ->
  +    encode_msgpack(Bin).
  +
  +encode_msgpack(Bin) ->
  +    msgpack:pack(Bin, [{format, jsx}]).
  +
   encode_maybe_binary(Bin) when is_binary(Bin) ->
       <<1, Bin/binary>>;
   encode_maybe_binary(Bin) ->
       <<0, (term_to_binary(Bin))/binary>>.
  +
  +%% @doc Decode the contents of a riak object, either using
  +%% binary_to_term (if Enc == erlang), or msgpack decoding (if Enc ==
  +%% msgpack)
  +decode(ValBin, Enc) when Enc == erlang ->
  +    decode_maybe_binary(ValBin);
  +decode(ValBin, Enc) when Enc == msgpack ->
  +    decode_msgpack(ValBin).
  +
  +decode_msgpack(ValBin) ->
  +    {ok, Unpacked} = msgpack:unpack(ValBin, [{format, jsx}]),
  +    Unpacked.
   
   decode_maybe_binary(<<1, Bin/binary>>) ->
       Bin;
  
positive.code: %% @doc Convert binary object to riak object
  -spec from_binary(bucket(),key(),binary()) ->
      riak_object() | {error, 'bad_object_format'}.
  from_binary(_B,_K,<<131, _Rest/binary>>=ObjTerm) ->
      binary_to_term(ObjTerm);
  from_binary(B,K,<<?MAGIC:8/integer, 1:8/integer, Rest/binary>>=_ObjBin) ->
      %% Version 1 of binary riak object
      case Rest of
          <<VclockLen:32/integer, VclockBin:VclockLen/binary, SibCount:32/integer, SibsBin/binary>> ->
              Vclock = binary_to_term(VclockBin),
              Contents = sibs_of_binary(SibCount, SibsBin),
              #r_object{bucket=B,key=K,contents=Contents,vclock=Vclock};
          _Other ->
              {error, bad_object_format}
      end;
  from_binary(_B, _K, Obj = #r_object{}) ->
      Obj.
  
  sibs_of_binary(Count,SibsBin) ->
      sibs_of_binary(Count, SibsBin, []).
  
  sibs_of_binary(0, <<>>, Result) -> lists:reverse(Result);
  sibs_of_binary(0, _NotEmpty, _Result) ->
      {error, corrupt_contents};
  sibs_of_binary(Count, SibsBin, Result) ->
      {Sib, SibsRest} = sib_of_binary(SibsBin),
      sibs_of_binary(Count-1, SibsRest, [Sib | Result]).
  
  sib_of_binary(<<ValLen:32/integer, ValBin:ValLen/binary, MetaLen:32/integer, MetaBin:MetaLen/binary, Rest/binary>>) ->
      <<LMMega:32/integer, LMSecs:32/integer, LMMicro:32/integer, VTagLen:8/integer, VTag:VTagLen/binary, Deleted:1/binary-unit:8, MetaRestBin/binary>> = MetaBin,
  
      MDList0 = deleted_meta(Deleted, []),
  
negative.code: %% -type binobj_value()      :: <<ValueLen:32, ValueBin/binary, MetaLen:32,
  %%                                [binobj_meta()]>>.
  %% -type binobj()            :: <<binobj_header(), [binobj_value()]>>.
  new_v1(Vclock, Siblings, Enc) ->
      VclockBin = term_to_binary(Vclock),
      VclockLen = byte_size(VclockBin),
      SibCount = length(Siblings),
      SibsBin = bin_contents(Siblings, Enc),
      <<?MAGIC:8/integer, ?V1_VERS:8/integer, VclockLen:32/integer, VclockBin/binary, SibCount:32/integer, SibsBin/binary>>.
  
  bin_content(#r_content{metadata=Meta, value=Val}, Enc) ->
      ValBin = encode(Val, Enc),
      ValLen = byte_size(ValBin),
      MetaBin = meta_bin(Meta),
      MetaLen = byte_size(MetaBin),
      <<ValLen:32/integer, ValBin:ValLen/binary, MetaLen:32/integer, MetaBin:MetaLen/binary>>.
  
  bin_contents(Contents, Enc) ->
      F = fun(Content, Acc) ->
                  <<Acc/binary, (bin_content(Content, Enc))/binary>>
          end,
      lists:foldl(F, <<>>, Contents).
  
  