1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
module CBOR
#
# CBOR::Packer is an interface to serialize objects into an internal buffer,
# which is a CBOR::Buffer.
#
class Packer
#
# Creates a CBOR::Packer instance.
# See Buffer#initialize for supported options.
#
# @overload initialize(options={})
# @param options [Hash]
#
# @overload initialize(io, options={})
# @param io [IO]
# @param options [Hash]
# This packer writes serialzied objects into the IO when the internal buffer is filled.
# _io_ must respond to write(string) or append(string) method.
#
def initialize(*args)
end
#
# Internal buffer
#
# @return CBOR::Buffer
#
attr_reader :buffer
#
# Serializes an object into internal buffer.
#
# If it could not serialize the object, it raises
# NoMethodError: undefined method `to_cbor' for #<the_object>.
#
# @param obj [Object] object to serialize
# @return [Packer] self
#
def write(obj)
end
alias pack write
#
# Serializes a nil object. Same as write(nil).
#
def write_nil
end
#
# Write a header of an array whose size is _n_.
# For example, write_array_header(1).write(true) is same as write([ true ]).
#
# @return [Packer] self
#
def write_array_header(n)
end
#
# Write a header of an map whose size is _n_.
# For example, write_map_header(1).write('key').write(true) is same as write('key'=>true).
#
# @return [Packer] self
#
def write_map_header(n)
end
#
# Flushes data in the internal buffer to the internal IO. Same as _buffer.flush.
# If internal IO is not set, it does nothing.
#
# @return [Packer] self
#
def flush
end
#
# Makes the internal buffer empty. Same as _buffer.clear_.
#
# @return nil
#
def clear
end
#
# Returns size of the internal buffer. Same as buffer.size.
#
# @return [Integer]
#
def size
end
#
# Returns _true_ if the internal buffer is empty. Same as buffer.empty?.
# This method is slightly faster than _size_.
#
# @return [Boolean]
#
def empty?
end
#
# Returns all data in the buffer as a string. Same as buffer.to_str.
#
# @return [String]
#
def to_str
end
alias to_s to_str
#
# Returns content of the internal buffer as an array of strings. Same as buffer.to_a.
# This method is faster than _to_str_.
#
# @return [Array] array of strings
#
def to_a
end
#
# Writes all of data in the internal buffer into the given IO. Same as buffer.write_to(io).
# This method consumes and removes data from the internal buffer.
# _io_ must respond to write(data) method.
#
# @param io [IO]
# @return [Integer] byte size of written data
#
def write_to(io)
end
end
end
|