// Path: ddp-client/src/main/java/io/advantageous/ddp/rpc/MethodMessage.java
// public class MethodMessage {
// 
//     private String method;
// 
//     private String id;
// 
//     private Object[] params;
// 
//     public String getMethod() {
//         return method;
//     }
// 
//     public void setMethod(String method) {
//         this.method = method;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public Object[] getParams() {
//         return params;
//     }
// 
//     public void setParams(Object[] params) {
//         this.params = params;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/rpc/ResultMessage.java
// public class ResultMessage {
// 
//     private String id;
// 
//     private DDPError error;
// 
//     private Object result;
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public DDPError getError() {
//         return error;
//     }
// 
//     public void setError(DDPError error) {
//         this.error = error;
//     }
// 
//     public Object getResult() {
//         return result;
//     }
// 
//     public void setResult(Object result) {
//         this.result = result;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/rpc/UpdatedMessage.java
// public class UpdatedMessage {
// 
//     private String[] methods;
// 
//     public String[] getMethods() {
//         return methods;
//     }
// }


import io.advantageous.ddp.rpc.MethodMessage;
import io.advantageous.ddp.rpc.ResultMessage;
import io.advantageous.ddp.rpc.UpdatedMessage;
import io.advantageous.ddp.subscription.message.*;
import java.util.HashMap;
import java.util.Map;
/*
 * Copyright (C) 2014. Geoffrey Chandler.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.advantageous.ddp;



/**
 * Interface for converting DDP messages to and from raw string types.
 *
 * @author geoffc@gmail.com
 * @since 1/17/14 at 7:08 PM.
 */
public interface MessageConverter {

    public Object fromDDP(String message) throws UnsupportedMessageException;

    public String toDDP(Object object);

    static class MessageRegistry {

        static final Map<String, Class> STRING_CLASS_HASH_MAP = new HashMap<>();

        static final Map<Class, String> CLASS_STRING_HASH_MAP = new HashMap<>();

        static void register(String name, Class clazz) {
            STRING_CLASS_HASH_MAP.put(name, clazz);
            CLASS_STRING_HASH_MAP.put(clazz, name);
        }

        static String get(Class clazz) {
            return CLASS_STRING_HASH_MAP.get(clazz);
        }

        static Class get(String key) {
            return STRING_CLASS_HASH_MAP.get(key);
        }

        static {
            register("method", MethodMessage.class);
            register("result", ResultMessage.class);
// Path: ddp-client/src/main/java/io/advantageous/ddp/rpc/MethodMessage.java
// public class MethodMessage {
// 
//     private String method;
// 
//     private String id;
// 
//     private Object[] params;
// 
//     public String getMethod() {
//         return method;
//     }
// 
//     public void setMethod(String method) {
//         this.method = method;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public Object[] getParams() {
//         return params;
//     }
// 
//     public void setParams(Object[] params) {
//         this.params = params;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/rpc/ResultMessage.java
// public class ResultMessage {
// 
//     private String id;
// 
//     private DDPError error;
// 
//     private Object result;
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public DDPError getError() {
//         return error;
//     }
// 
//     public void setError(DDPError error) {
//         this.error = error;
//     }
// 
//     public Object getResult() {
//         return result;
//     }
// 
//     public void setResult(Object result) {
//         this.result = result;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/rpc/UpdatedMessage.java
// public class UpdatedMessage {
// 
//     private String[] methods;
// 
//     public String[] getMethods() {
//         return methods;
//     }
// }


// Path: ddp-client/src/main/java/io/advantageous/ddp/MessageConverter.java
import io.advantageous.ddp.rpc.MethodMessage;
import io.advantageous.ddp.rpc.ResultMessage;
import io.advantageous.ddp.rpc.UpdatedMessage;
import io.advantageous.ddp.subscription.message.*;
import java.util.HashMap;
import java.util.Map;

/*
 * Copyright (C) 2014. Geoffrey Chandler.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.advantageous.ddp;



/**
 * Interface for converting DDP messages to and from raw string types.
 *
 * @author geoffc@gmail.com
 * @since 1/17/14 at 7:08 PM.
 */
public interface MessageConverter {

    public Object fromDDP(String message) throws UnsupportedMessageException;

    public String toDDP(Object object);

    static class MessageRegistry {

        static final Map<String, Class> STRING_CLASS_HASH_MAP = new HashMap<>();

        static final Map<Class, String> CLASS_STRING_HASH_MAP = new HashMap<>();

        static void register(String name, Class clazz) {
            STRING_CLASS_HASH_MAP.put(name, clazz);
            CLASS_STRING_HASH_MAP.put(clazz, name);
        }

        static String get(Class clazz) {
            return CLASS_STRING_HASH_MAP.get(clazz);
        }

        static Class get(String key) {
            return STRING_CLASS_HASH_MAP.get(key);
        }

        static {
            register("method", MethodMessage.class);
            register("result", ResultMessage.class);
            register("updated", UpdatedMessage.class);