abstract class
Amber::WebSockets::Decoders::Decoder
- Amber::WebSockets::Decoders::Decoder
- Reference
- Object
Overview
Abstract base class for WebSocket message decoders.
Decoders handle the serialization and deserialization of messages sent over WebSocket connections. The framework ships with JSON, text, and binary decoders, but custom decoders can be created by inheriting from this class.
Example:
class CustomDecoder < Amber::WebSockets::Decoders::Decoder
def decode(raw : String) : JSON::Any
# custom decoding logic
end
def encode(payload) : String
# custom encoding logic
end
def content_type : String
"application/x-custom"
end
end
Direct Known Subclasses
- Amber::WebSockets::Decoders::BinaryDecoder
- Amber::WebSockets::Decoders::JsonDecoder
- Amber::WebSockets::Decoders::TextDecoder
Defined in:
amber/websockets/decoders/decoder.crInstance Method Summary
-
#content_type : String
Returns the MIME content type associated with this decoder.
-
#decode(raw : String) : JSON::Any
Decodes a raw message string into a structured JSON::Any value.
-
#encode(payload : Hash) : String
Encodes a Hash payload into a string suitable for sending over the socket.
-
#encode(payload : JSON::Any) : String
Encodes a JSON::Any payload into a string suitable for sending over the socket.
Instance Method Detail
Returns the MIME content type associated with this decoder.
Decodes a raw message string into a structured JSON::Any value.
Returns a JSON::Any representing the decoded message. Implementations
should raise DecoderError if the message cannot be decoded.
Encodes a Hash payload into a string suitable for sending over the socket.
Encodes a JSON::Any payload into a string suitable for sending over the socket.