Module: Couchbase::Transcoder::Document

Defined in:
lib/couchbase/transcoder.rb

Class Method Summary collapse

Class Method Details

.dump(obj, flags, options = {}) ⇒ Object



53
54
55
56
57
58
# File 'lib/couchbase/transcoder.rb', line 53

def self.dump(obj, flags, options = {})
  [
    MultiJson.dump(obj),
    (flags & ~Bucket::FMT_MASK) | Bucket::FMT_DOCUMENT
  ]
end

.load(blob, flags, options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/couchbase/transcoder.rb', line 60

def self.load(blob, flags, options = {})
  if (flags & Bucket::FMT_MASK) == Bucket::FMT_DOCUMENT || options[:forced]
    MultiJson.load(blob)
  else
    if Compat.enabled?
      return Compat.guess_and_load(blob, flags, options)
    else
      raise ArgumentError,
        "unexpected flags (0x%02x instead of 0x%02x)" % [flags, Bucket::FMT_DOCUMENT]
    end
  end
end