Class: Takagi::Serialization::OctetStreamSerializer
- Defined in:
- lib/takagi/serialization/octet_stream_serializer.rb
Overview
Octet-stream serializer (RFC 2046)
Handles application/octet-stream content-format (code 42). Pass-through for raw binary data with no transformation.
Instance Method Summary collapse
-
#binary? ⇒ Boolean
Octet-stream is binary.
-
#content_format_code ⇒ Integer
CoAP content-format code for octet-stream.
-
#content_type ⇒ String
MIME type for octet-stream.
-
#decode(bytes) ⇒ String
Decode binary bytes.
-
#encode(data) ⇒ String
Encode data to binary bytes.
Methods inherited from Base
Instance Method Details
#binary? ⇒ Boolean
Octet-stream is binary
77 78 79 |
# File 'lib/takagi/serialization/octet_stream_serializer.rb', line 77 def binary? true end |
#content_format_code ⇒ Integer
CoAP content-format code for octet-stream
70 71 72 |
# File 'lib/takagi/serialization/octet_stream_serializer.rb', line 70 def content_format_code CoAP::Registries::ContentFormat::OCTET_STREAM end |
#content_type ⇒ String
MIME type for octet-stream
63 64 65 |
# File 'lib/takagi/serialization/octet_stream_serializer.rb', line 63 def content_type 'application/octet-stream' end |
#decode(bytes) ⇒ String
Decode binary bytes
Pass-through decoder - bytes are returned as-is.
51 52 53 54 55 56 57 58 |
# File 'lib/takagi/serialization/octet_stream_serializer.rb', line 51 def decode(bytes) return nil if bytes.nil? || bytes.empty? # Return as binary string bytes.b rescue StandardError => e raise DecodeError, "Octet-stream decoding failed: #{e.}" end |
#encode(data) ⇒ String
Encode data to binary bytes
Pass-through serializer - data is returned as-is in binary form. Non-string objects are converted to string first.
31 32 33 34 35 36 37 38 39 |
# File 'lib/takagi/serialization/octet_stream_serializer.rb', line 31 def encode(data) return ''.b if data.nil? || data == '' # Convert to binary string result = data.is_a?(String) ? data : data.to_s result.b rescue StandardError => e raise EncodeError, "Octet-stream encoding failed: #{e.}" end |