Class MapReplaceCasCodec
java.lang.Object
com.loomcache.common.protocol.MapReplaceCasCodec
Wire-format codec for the
MessageType.MAP_REPLACE_CAS value field.
Prior implementations encoded "oldValue|newValue" as a pipe-delimited
UTF-8 string and split on "|" on the server, which made any value
containing a '|' character unrepresentable or ambiguous. This codec
replaces that with a length-prefixed binary format that is safe for arbitrary
UTF-8 payloads.
Wire format (both lengths are 4-byte signed big-endian integers):
[4 bytes oldValueLen][oldValueLen bytes — UTF-8 oldValue] [4 bytes newValueLen][newValueLen bytes — UTF-8 newValue]
The codec is deliberately self-contained so both the server handler and server-side test fixtures can share a single canonical format. Adding a client API for CAS in the future will reuse this codec as the wire contract.
- Since:
- 1.4
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordDecoded CAS payload: the expectedoldValueand the replacementnewValue. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFixed header overhead:4 (oldLen) + 4 (newLen) = 8 bytes. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable MapReplaceCasCodec.CasPayloaddecode(byte[] data) Decode a previously-encoded payload back intoMapReplaceCasCodec.CasPayload.static byte[]Encode(oldValue, newValue)into the binary wire format.
-
Field Details
-
HEADER_BYTES
public static final int HEADER_BYTESFixed header overhead:4 (oldLen) + 4 (newLen) = 8 bytes.- See Also:
-
-
Method Details
-
encode
Encode(oldValue, newValue)into the binary wire format.- Parameters:
oldValue- the expected current value (non-null; use""for empty)newValue- the replacement value (non-null; use""for empty)- Returns:
- the encoded byte array
- Throws:
NullPointerException- if either argument is null
-
decode
Decode a previously-encoded payload back intoMapReplaceCasCodec.CasPayload.- Parameters:
data- the encoded bytes (non-null)- Returns:
- the decoded payload, or
nullifdatais malformed
-