Class: Couchbase::RawJsonTranscoder

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

Instance Method Summary collapse

Instance Method Details

#decode(blob, flags) ⇒ String

Returns decoded document.

Raises:

Parameters:

  • string of bytes, containing encoded representation of the document

  • bit field, describing how the data encoded

Returns:

  • decoded document



33
34
35
36
37
38
# File 'lib/couchbase/raw_json_transcoder.rb', line 33

def decode(blob, flags)
  format = TranscoderFlags.decode(flags).format
  raise Error::DecodingFailure, "Unable to decode #{format} with the RawJsonTranscoder" unless format == :json || format.nil?

  blob
end

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

Returns pair of encoded document and flags.

Raises:

Parameters:

Returns:

  • pair of encoded document and flags



24
25
26
27
28
# File 'lib/couchbase/raw_json_transcoder.rb', line 24

def encode(document)
  raise Error::EncodingFailure, "Only String and binary data supported by RawJsonTranscoder" unless document.is_a?(String)

  [document, TranscoderFlags.new(format: :json).encode]
end