Module: Riak::Client::BeefcakeProtobuffsBackend::ObjectMethods

Included in:
Riak::Client::BeefcakeProtobuffsBackend
Defined in:
lib/riak/client/beefcake/object_methods.rb

Constant Summary collapse

ENCODING =
"Riak".respond_to?(:encoding)

Instance Method Summary collapse

Instance Method Details

#dump_object(robject, options = {}) ⇒ Object

Returns RpbPutReq



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/riak/client/beefcake/object_methods.rb', line 12

def dump_object(robject, options={})
  pbuf = RpbPutReq.new(options.merge(:bucket => maybe_encode(robject.bucket.name)))
  pbuf.key = maybe_encode(robject.key) if robject.key # Put w/o key supported!
  pbuf.vclock = maybe_encode(Base64.decode64(robject.vclock)) if robject.vclock
  pbuf.content = RpbContent.new(:value => maybe_encode(robject.raw_data),
                                :content_type => maybe_encode(robject.content_type),
                                :links => robject.links.map {|l| encode_link(l) }.compact,
                                :indexes => robject.indexes.map {|k,s| encode_index(k,s) }.flatten)

  pbuf.content.usermeta = robject.meta.map {|k,v| encode_meta(k,v)} if robject.meta.any?
  pbuf.content.vtag = maybe_encode(robject.etag) if robject.etag.present?
  if ENCODING # 1.9 support
    pbuf.content.charset = maybe_encode(robject.raw_data.encoding.name)
  end
  pbuf
end

#load_object(pbuf, robject) ⇒ Object

Returns RObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/riak/client/beefcake/object_methods.rb', line 30

def load_object(pbuf, robject)
  return robject if pbuf.respond_to?(:unchanged) && pbuf.unchanged # Reloading
  robject.vclock = Base64.encode64(pbuf.vclock).chomp if pbuf.vclock
  robject.key = maybe_unescape(pbuf.key) if pbuf.respond_to?(:key) && pbuf.key # Put w/o key
  if pbuf.content.size > 1
    robject.conflict = true
    robject.siblings = pbuf.content.map do |c|
      sibling = RObject.new(robject.bucket, robject.key)
      sibling.vclock = robject.vclock
      load_content(c, sibling)
    end

    return robject.attempt_conflict_resolution
  else
    load_content(pbuf.content.first, robject)
  end
  robject
end