Class: CBOR::Streaming::Encoder
- Inherits:
-
Object
- Object
- CBOR::Streaming::Encoder
- Defined in:
- lib/libcbor/streaming/encoder.rb
Overview
Provides streaming encoding facilities. Initialize it with an output object and either feed it encodable objects, or invoke the methods directly
Instance Method Summary collapse
-
#<<(object) ⇒ void
Serializes and writes an object to the stream.
-
#break ⇒ void
Encodes indefinite item break code.
-
#initialize(stream) ⇒ Encoder
constructor
A new instance of Encoder.
-
#start_array ⇒ void
Encodes a ‘start array’ mark.
-
#start_chunked_byte_string ⇒ void
Encodes a ‘start indefinite byte string’ mark.
-
#start_chunked_string ⇒ void
Encodes a ‘start indefinite string’ mark.
-
#start_map ⇒ void
Encodes a ‘start map’ mark.
-
#tag(value) ⇒ void
Encodes a tag with the give
value
.
Constructor Details
#initialize(stream) ⇒ Encoder
Returns a new instance of Encoder.
9 10 11 |
# File 'lib/libcbor/streaming/encoder.rb', line 9 def initialize(stream) @stream = stream end |
Instance Method Details
#<<(object) ⇒ void
This method returns an undefined value.
Serializes and writes an object to the stream
17 18 19 |
# File 'lib/libcbor/streaming/encoder.rb', line 17 def <<(object) stream.write(object.public_send(CBOR.method_name)) end |
#break ⇒ void
This method returns an undefined value.
Encodes indefinite item break code.
70 71 72 |
# File 'lib/libcbor/streaming/encoder.rb', line 70 def break stream.write("\xff") end |
#start_array ⇒ void
This method returns an undefined value.
Encodes a ‘start array’ mark. You are responsible for correctly #breaking it
25 26 27 |
# File 'lib/libcbor/streaming/encoder.rb', line 25 def start_array stream.write("\x9f") end |
#start_chunked_byte_string ⇒ void
This method returns an undefined value.
Encodes a ‘start indefinite byte string’ mark. You are responsible for correctly #breaking it
49 50 51 |
# File 'lib/libcbor/streaming/encoder.rb', line 49 def start_chunked_byte_string stream.write("\x5f") end |
#start_chunked_string ⇒ void
This method returns an undefined value.
Encodes a ‘start indefinite string’ mark. You are responsible for correctly #breaking it
41 42 43 |
# File 'lib/libcbor/streaming/encoder.rb', line 41 def start_chunked_string stream.write("\x7f") end |
#start_map ⇒ void
This method returns an undefined value.
Encodes a ‘start map’ mark. You are responsible for correctly #breaking it
33 34 35 |
# File 'lib/libcbor/streaming/encoder.rb', line 33 def start_map stream.write("\xbf") end |
#tag(value) ⇒ void
This method returns an undefined value.
Encodes a tag with the give value
.
You are responsible for correctly supplying the item that follows (i.e. the one the tag will apply to)
60 61 62 63 64 65 |
# File 'lib/libcbor/streaming/encoder.rb', line 60 def tag(value) @@bfr ||= FFI::Buffer.new(:uchar, 9) stream.write( @@bfr.get_bytes(0, LibCBOR.cbor_encode_tag(value, @@bfr, 9)) ) end |