Sha256: 16ba6df14f275d562b2554561d8bc13ca7de123ebc67e7cd47be36fc4ce14e1f

Contents?: true

Size: 1.12 KB

Versions: 14

Compression:

Stored size: 1.12 KB

Contents

#    Copyright 2020 Couchbase, Inc.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

require "json"

module Couchbase
  class JsonTranscoder
    # @param [Object] document
    # @return [Array<String, Integer>] pair of encoded document and flags
    def encode(document)
      [JSON.generate(document), (0x02 << 24) | 0x06]
    end

    # @param [String, nil] blob string of bytes, containing encoded representation of the document
    # @param [Integer, :json] flags bit field, describing how the data encoded
    # @return Object decoded document
    def decode(blob, flags)
      JSON.parse(blob) unless blob.nil?
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
couchbase-3.0.0.beta.1-universal-darwin-19 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.beta.1 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.5-x86_64-linux lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.5-universal-darwin-19 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.5-x86_64-darwin-19 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.5 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.4-x86_64-linux lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.4-x86_64-darwin-19 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.4-universal-darwin-19 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.4 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.3-x86_64-linux lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.3-x86_64-darwin-19 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.3-universal-darwin-19 lib/couchbase/json_transcoder.rb
couchbase-3.0.0.alpha.3 lib/couchbase/json_transcoder.rb