Class: Couchbase::JsonTranscoder
- Inherits:
-
Object
- Object
- Couchbase::JsonTranscoder
- Defined in:
- lib/couchbase/json_transcoder.rb,
/code/couchbase-ruby-client/lib/couchbase/json_transcoder.rb
Instance Method Summary collapse
-
#decode(blob, flags) ⇒ Object
Decoded document.
-
#encode(document) ⇒ Array<String, Integer>
Pair of encoded document and flags.
Instance Method Details
#decode(blob, flags) ⇒ Object
Returns decoded document.
34 35 36 37 38 39 |
# File 'lib/couchbase/json_transcoder.rb', line 34 def decode(blob, flags) format = TranscoderFlags.decode(flags).format raise Error::DecodingFailure, "Unable to decode #{format} with the JsonTranscoder" unless format == :json || format.nil? JSON.parse(blob) unless blob&.empty? end |
#encode(document) ⇒ Array<String, Integer>
Returns pair of encoded document and flags.
25 26 27 28 29 |
# File 'lib/couchbase/json_transcoder.rb', line 25 def encode(document) raise Error::EncodingFailure, "The JsonTranscoder does not support binary data" if document.is_a?(String) && !document.valid_encoding? [JSON.generate(document), TranscoderFlags.new(format: :json, lower_bits: 6).encode] end |