// Path: src/main/java/io/s4/collector/Event.java
// public static final String EVENT_NAME_KEY = "S4__eventName";
// 
// Path: src/main/java/io/s4/schema/AvroSchemaManager.java
// public class AvroSchemaManager extends SchemaManager {
//     Map<String, Schema> schemaMap = new ConcurrentHashMap<String, Schema>();
// 
//     public void init() {
//         super.init();
//         for (String schemaName : schemaStringMap.keySet()) {
//             String schemaString = schemaStringMap.get(schemaName);
//             schemaMap.put(schemaName, Schema.parse(schemaString));
//             if (Logger.getLogger("s4").isDebugEnabled()) {
//                 Logger.getLogger("s4").debug("Putting schema " + schemaName
//                         + ": " + schemaMap.get(schemaName));
//             }
//         }
// 
//     }
// 
//     public void addSchemaFromFile(String schemaName, String schemaFilename) {
//         super.addSchemaFromFile(schemaName, schemaFilename);
//         String schemaString = schemaStringMap.get(schemaName);
//         schemaMap.put(schemaName, Schema.parse(schemaString));
//     }
// 
//     public void addSchema(String schemaName, String schemaString) {
//         super.addSchema(schemaName, schemaString);
//         schemaMap.put(schemaName, Schema.parse(schemaString));
//     }
// 
//     public Schema getCompiledSchema(String schemaName) {
//         return schemaMap.get(schemaName);
//     }
// }
// 
// Path: src/main/java/io/s4/util/MiscConstants.java
// public class MiscConstants {
//     public final static String EVENT_WRAPPER_SCHEMA_NAME = "EventWrapper";
// }


import static io.s4.collector.Event.EVENT_NAME_KEY;
import io.s4.schema.AvroSchemaManager;
import io.s4.util.MiscConstants;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
import org.apache.avro.generic.GenericArray;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.util.Utf8;
            if (schemaNameUtf8 == null) {
                throw new RuntimeException("Wrapper message does not contain eventType field");
            }

            String schemaName = schemaNameUtf8.toString();
            Schema eventSchema = avroSchemaManager.getCompiledSchema(schemaName);

            ByteBuffer byteBuffer = (ByteBuffer) wrapper.get("rawdata");
            if (byteBuffer == null) {
                throw new RuntimeException("Wrapper message does not contain rawdata field");
            }

            byte[] byteData = byteBuffer.array();
            GenericRecord avroEvent = deserialize(eventSchema, byteData);

            // convert the avro version of the event into a Map
            event = new HashMap<String, Object>();
            copyRecord(avroEvent, event);
            if (event.get(EVENT_NAME_KEY) == null) {
                event.put(EVENT_NAME_KEY, schemaName);
            }
            return event;
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }

    public byte[] serialize(Object message) {
        Map<String, Object> event = (Map<String, Object>) message;

// Path: src/main/java/io/s4/collector/Event.java
// public static final String EVENT_NAME_KEY = "S4__eventName";
// 
// Path: src/main/java/io/s4/schema/AvroSchemaManager.java
// public class AvroSchemaManager extends SchemaManager {
//     Map<String, Schema> schemaMap = new ConcurrentHashMap<String, Schema>();
// 
//     public void init() {
//         super.init();
//         for (String schemaName : schemaStringMap.keySet()) {
//             String schemaString = schemaStringMap.get(schemaName);
//             schemaMap.put(schemaName, Schema.parse(schemaString));
//             if (Logger.getLogger("s4").isDebugEnabled()) {
//                 Logger.getLogger("s4").debug("Putting schema " + schemaName
//                         + ": " + schemaMap.get(schemaName));
//             }
//         }
// 
//     }
// 
//     public void addSchemaFromFile(String schemaName, String schemaFilename) {
//         super.addSchemaFromFile(schemaName, schemaFilename);
//         String schemaString = schemaStringMap.get(schemaName);
//         schemaMap.put(schemaName, Schema.parse(schemaString));
//     }
// 
//     public void addSchema(String schemaName, String schemaString) {
//         super.addSchema(schemaName, schemaString);
//         schemaMap.put(schemaName, Schema.parse(schemaString));
//     }
// 
//     public Schema getCompiledSchema(String schemaName) {
//         return schemaMap.get(schemaName);
//     }
// }
// 
// Path: src/main/java/io/s4/util/MiscConstants.java
// public class MiscConstants {
//     public final static String EVENT_WRAPPER_SCHEMA_NAME = "EventWrapper";
// }


// Path: src/main/java/io/s4/serialize/AvroSerDeser.java
import static io.s4.collector.Event.EVENT_NAME_KEY;
import io.s4.schema.AvroSchemaManager;
import io.s4.util.MiscConstants;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
import org.apache.avro.generic.GenericArray;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.util.Utf8;

            if (schemaNameUtf8 == null) {
                throw new RuntimeException("Wrapper message does not contain eventType field");
            }

            String schemaName = schemaNameUtf8.toString();
            Schema eventSchema = avroSchemaManager.getCompiledSchema(schemaName);

            ByteBuffer byteBuffer = (ByteBuffer) wrapper.get("rawdata");
            if (byteBuffer == null) {
                throw new RuntimeException("Wrapper message does not contain rawdata field");
            }

            byte[] byteData = byteBuffer.array();
            GenericRecord avroEvent = deserialize(eventSchema, byteData);

            // convert the avro version of the event into a Map
            event = new HashMap<String, Object>();
            copyRecord(avroEvent, event);
            if (event.get(EVENT_NAME_KEY) == null) {
                event.put(EVENT_NAME_KEY, schemaName);
            }
            return event;
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }

    public byte[] serialize(Object message) {
        Map<String, Object> event = (Map<String, Object>) message;

        Schema wrapperSchema = avroSchemaManager.getCompiledSchema(MiscConstants.EVENT_WRAPPER_SCHEMA_NAME);