Class: Couchbase::JsonTranscoder

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/json_transcoder.rb

Instance Method Summary collapse

Instance Method Details

#decode(blob, flags) ⇒ Object

Returns Object decoded document.

Parameters:

  • blob (String, nil)

    string of bytes, containing encoded representation of the document

  • flags (Integer, :json)

    bit field, describing how the data encoded

Returns:

  • Object decoded document

[View source]

28
29
30
# File 'lib/couchbase/json_transcoder.rb', line 28

def decode(blob, flags)
  JSON.parse(blob) unless blob.nil?
end

#encode(document) ⇒ Array<String, Integer>

Returns pair of encoded document and flags.

Parameters:

  • document (Object)

Returns:

  • (Array<String, Integer>)

    pair of encoded document and flags

[View source]

21
22
23
# File 'lib/couchbase/json_transcoder.rb', line 21

def encode(document)
  [JSON.generate(document), (0x02 << 24) | 0x06]
end