package org.craft.atom.protocol.rpc.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * Represents a RPC header field.
 * <p>
 * A body that can be sent or received with a Rpc message, 
 * but not all messages contain a body, it is optional.
 * The body contains a block of arbitrary data and can be serialized by specific serializer.
 * 
 * @author mindwind
 * @version 1.0, Jul 18, 2014
 */
@ToString
@EqualsAndHashCode(of = { "clazz", "method", "argTypes", "args", "attachments" })
public class RpcBody implements Serializable {

	
	private static final long serialVersionUID = 5138100956693144357L;
	
	
	@Getter @Setter private Class<?>            clazz      ;
	@Getter @Setter private String              method     ;
	@Getter         private Class<?>[]          argTypes   ;
	@Getter         private Object[]            args       ;
	@Getter @Setter private Map<String, Object> attachments;
	
	
	public void addAttachment(String key, String value) {
		if (attachments == null) {
			attachments = new HashMap<String, Object>();
		}
		attachments.put(key, value);
	}
	
	
	public void setArgTypes(Class<?>... argTypes) {
		this.argTypes = argTypes;
	}

	public void setArgs(Object... args) {
		this.args = args;
	}

}

@@ -245,14 +245,12 @@
 RPC 
-header
+body
  fie
@@ -306,17 +306,17 @@
  with a 
-R
+r
 pc messa
@@ -601,16 +601,48 @@
  %22args%22,
+ %22returnObject%22, %22thrownObject%22,
  %22attach
@@ -825,24 +825,25 @@
  clazz      
+ 
 ;%0A%09@Getter @
@@ -884,24 +884,25 @@
  method     
+ 
 ;%0A%09@Getter  
@@ -947,16 +947,17 @@
 Types   
+ 
 ;%0A%09@Gett
@@ -1002,24 +1002,143 @@
  args       
+ ;%0A%09@Getter @Setter private Object              returnObject;%0A%09@Getter @Setter private Throwable           thrownObject
 ;%0A%09@Getter @
@@ -1183,16 +1183,36 @@
 achments
+ ;%0A%09private int test
 ;%0A%09%0A%09%0A%09p

improve - add fields