fulmine.rpc
Class RpcCodec

java.lang.Object
  extended by fulmine.rpc.RpcCodec
All Implemented Interfaces:
IRpcCodec

public class RpcCodec
extends Object
implements IRpcCodec

Standard implementation of an IRpcCodec. The encoding format in ABNF is as follows:

 ENCODED      = MARKER "|" KEY ARGS
 MARKER       = 1*DIGIT ; the RPC marker ID
 KEY          = "RpcKey" (1*DIGIT) ; this is the RPC key
 ARGS         = 0*("|" ARG)
 ARG          = 1*(ALPHA / DIGIT) ; argument values sent as their string value
 
The character '|' is special, so the arguments are further encoded/decoded to capture any '|' characters and replace them with '&|' (i.e. & + the HTML escape sequence for '|')

Author:
Ramon Servadei

Constructor Summary
RpcCodec(IRpcRegistry registry)
          Construct the codec with the registry.
 
Method Summary
 QuadValue<IRpcMarker,String,String,IField[]> decode(byte[] rpcData)
          Decode the byte[] into the RPC marker, key, identity of the remote context invoking this RPC and arguments.
 byte[] encode(IRpcMarker rpcMarker, String rpcKey, String contextIdentity, IField[] args)
          Encode the RPC marker, key and arguments into a byte[]
 String[] getArgs()
          Get the RPC arguments from the RPC data.
 String getRpcKey()
          Get the RPC key from the RPC data.
 void setData(byte[] rpcData)
          Set the RPC data to use for the getRpcKey() and getArgs()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RpcCodec

public RpcCodec(IRpcRegistry registry)
Construct the codec with the registry.

Parameters:
registry - the RPC definition registry
Method Detail

decode

public QuadValue<IRpcMarker,String,String,IField[]> decode(byte[] rpcData)
Description copied from interface: IRpcCodec
Decode the byte[] into the RPC marker, key, identity of the remote context invoking this RPC and arguments. The name of the remote context is important for updating the correct RPC result record.

Specified by:
decode in interface IRpcCodec
Parameters:
rpcData - the byte[] to decode
Returns:
a QuasValue holding the RPC marker, key, identity of the remote context invoking this RPC and the arguments for the invocation, null if it cannot be decoded.

encode

public byte[] encode(IRpcMarker rpcMarker,
                     String rpcKey,
                     String contextIdentity,
                     IField[] args)
Description copied from interface: IRpcCodec
Encode the RPC marker, key and arguments into a byte[]

Specified by:
encode in interface IRpcCodec
Parameters:
rpcMarker - the RPC marker to encode
rpcKey - the RPC key to encode
contextIdentity - the identity of the context invoking the RPC
args - the arguments to encode
Returns:
a byte[] with the encoded RPC marker, key and arguments.

getRpcKey

public String getRpcKey()
Get the RPC key from the RPC data. The RPC data is set using setData(byte[])

Returns:
the RPC key

getArgs

public String[] getArgs()
Get the RPC arguments from the RPC data. The RPC data is set using setData(byte[])

Returns:
the RPC arguments

setData

public void setData(byte[] rpcData)
Set the RPC data to use for the getRpcKey() and getArgs()

Parameters:
rpcData - the RPC data in its byte form


Copyright © 2007-2009. All Rights Reserved.