Class: Takagi::Serialization::Base Abstract
- Inherits:
-
Object
- Object
- Takagi::Serialization::Base
- Defined in:
- lib/takagi/serialization/base.rb
Overview
This class is abstract.
Subclass and implement all methods
Base interface for all content-format serializers
Serializers implement encoding/decoding logic for specific content-formats. Each serializer handles one CoAP content-format (MIME type).
Direct Known Subclasses
CborSerializer, JsonSerializer, OctetStreamSerializer, TextSerializer
Instance Method Summary collapse
-
#binary? ⇒ Boolean
Check if this serializer can handle binary data.
-
#content_format_code ⇒ Integer
CoAP content-format code.
-
#content_type ⇒ String
MIME type this serializer handles.
-
#decode(bytes) ⇒ Object
Decode bytes to Ruby object.
-
#encode(data) ⇒ String
Encode Ruby object to bytes.
-
#name ⇒ String
Human-readable name for this serializer.
Instance Method Details
#binary? ⇒ Boolean
Check if this serializer can handle binary data
78 79 80 |
# File 'lib/takagi/serialization/base.rb', line 78 def binary? false end |
#content_format_code ⇒ Integer
CoAP content-format code
71 72 73 |
# File 'lib/takagi/serialization/base.rb', line 71 def content_format_code raise NotImplementedError, "#{self.class}#content_format_code must be implemented" end |
#content_type ⇒ String
MIME type this serializer handles
61 62 63 |
# File 'lib/takagi/serialization/base.rb', line 61 def content_type raise NotImplementedError, "#{self.class}#content_type must be implemented" end |
#decode(bytes) ⇒ Object
Decode bytes to Ruby object
51 52 53 |
# File 'lib/takagi/serialization/base.rb', line 51 def decode(bytes) raise NotImplementedError, "#{self.class}#decode must be implemented" end |
#encode(data) ⇒ String
Encode Ruby object to bytes
39 40 41 |
# File 'lib/takagi/serialization/base.rb', line 39 def encode(data) raise NotImplementedError, "#{self.class}#encode must be implemented" end |
#name ⇒ String
Human-readable name for this serializer
85 86 87 |
# File 'lib/takagi/serialization/base.rb', line 85 def name self.class.name.split('::').last.sub(/Serializer$/, '') end |