Package com.btcvelocity.api.bridge
Class BridgeCodec
java.lang.Object
com.btcvelocity.api.bridge.BridgeCodec
Handles JSON serialization and deserialization of
BridgeMessage records.
Each message is encoded as a JSON object containing every record component plus a
"type" discriminator field. Decoding reads the "type" field and routes
the payload to the matching record class. Malformed or unrecognized payloads decode to
null rather than throwing, so a single bad message can never destabilize the
proxy.
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable BridgeMessagedecode(byte[] data) Decodes a JSON byte array into a bridge message.static byte[]encode(BridgeMessage message) Encodes a bridge message to a UTF-8 JSON byte array.
-
Method Details
-
encode
Encodes a bridge message to a UTF-8 JSON byte array.- Parameters:
message- the message to encode- Returns:
- the JSON payload as a byte array
-
decode
Decodes a JSON byte array into a bridge message.- Parameters:
data- the JSON payload as a byte array- Returns:
- the decoded message, or
nullif the payload is malformed, missing a"type"field, or refers to an unknown message type
-