Class: Aws::Cbor::Encoder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-core/cbor/encoder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Pure ruby implementation of CBOR encoder.

Instance Method Summary collapse

Constructor Details

#initializeEncoder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Encoder.



9
10
11
# File 'lib/aws-sdk-core/cbor/encoder.rb', line 9

def initialize
  @buffer = String.new
end

Instance Method Details

#add(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

generic method for adding generic Ruby data based on its type



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/aws-sdk-core/cbor/encoder.rb', line 19

def add(value)
  case value
  when BigDecimal then add_big_decimal(value)
  when Integer then add_auto_integer(value)
  when Numeric then add_auto_float(value)
  when Symbol then add_string(value.to_s)
  when true, false then add_boolean(value)
  when nil then add_nil
  when Tagged
    add_tag(value.tag)
    add(value.value)
  when String
    if value.encoding == Encoding::BINARY
      add_byte_string(value)
    else
      add_string(value)
    end
  when Array
    start_array(value.size)
    value.each { |di| add(di) }
  when Hash
    start_map(value.size)
    value.each do |k, v|
      add(k)
      add(v)
    end
  when Time
    add_time(value)
  else
    raise UnknownTypeError, value
  end
  self
end

#bytesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the encoded bytes in CBOR format for all added data.

Returns:

  • the encoded bytes in CBOR format for all added data



14
15
16
# File 'lib/aws-sdk-core/cbor/encoder.rb', line 14

def bytes
  @buffer
end