Class: Couchbase::RawStringTranscoder

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

Instance Method Summary collapse

Instance Method Details

#decode(blob, flags) ⇒ String

Returns decoded document.

Parameters:

  • blob (String)

    string of bytes, containing encoded representation of the document

  • flags (Integer)

    bit field, describing how the data encoded

Returns:

  • (String)

    decoded document

Raises:



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

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

  blob
end

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

Returns pair of encoded document and flags.

Parameters:

  • document (String)

Returns:

  • (Array<String, Integer>)

    pair of encoded document and flags



22
23
24
25
26
27
28
# File 'lib/couchbase/raw_string_transcoder.rb', line 22

def encode(document)
  unless document.is_a?(String) && document.valid_encoding?
    raise Error::EncodingFailure, "Only String data supported by RawStringTranscoder"
  end

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