/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */
// Generated by http://code.google.com/p/protostuff/ ... DO NOT EDIT!
// Generated from protobuf

package org.apache.drill.exec.proto.beans;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.List;

import com.dyuproject.protostuff.GraphIOUtil;
import com.dyuproject.protostuff.Input;
import com.dyuproject.protostuff.Message;
import com.dyuproject.protostuff.Output;
import com.dyuproject.protostuff.Schema;

public final class RecordBatchDef implements Externalizable, Message<RecordBatchDef>, Schema<RecordBatchDef>
{

    public static Schema<RecordBatchDef> getSchema()
    {
        return DEFAULT_INSTANCE;
    }

    public static RecordBatchDef getDefaultInstance()
    {
        return DEFAULT_INSTANCE;
    }

    static final RecordBatchDef DEFAULT_INSTANCE = new RecordBatchDef();

    
    private int recordCount;
    private List<SerializedField> field;
    private Boolean carriesTwoByteSelectionVector;
    private int affectedRowsCount;

    public RecordBatchDef()
    {
        
    }

    // getters and setters

    // recordCount

    public int getRecordCount()
    {
        return recordCount;
    }

    public RecordBatchDef setRecordCount(int recordCount)
    {
        this.recordCount = recordCount;
        return this;
    }

    // field

    public List<SerializedField> getFieldList()
    {
        return field;
    }

    public RecordBatchDef setFieldList(List<SerializedField> field)
    {
        this.field = field;
        return this;
    }

    // carriesTwoByteSelectionVector

    public Boolean getCarriesTwoByteSelectionVector()
    {
        return carriesTwoByteSelectionVector;
    }

    public RecordBatchDef setCarriesTwoByteSelectionVector(Boolean carriesTwoByteSelectionVector)
    {
        this.carriesTwoByteSelectionVector = carriesTwoByteSelectionVector;
        return this;
    }

    // affectedRowsCount

    public int getAffectedRowsCount()
    {
        return affectedRowsCount;
    }

    public RecordBatchDef setAffectedRowsCount(int affectedRowsCount)
    {
        this.affectedRowsCount = affectedRowsCount;
        return this;
    }

    // java serialization

    public void readExternal(ObjectInput in) throws IOException
    {
        GraphIOUtil.mergeDelimitedFrom(in, this, this);
    }

    public void writeExternal(ObjectOutput out) throws IOException
    {
        GraphIOUtil.writeDelimitedTo(out, this, this);
    }

    // message method

    public Schema<RecordBatchDef> cachedSchema()
    {
        return DEFAULT_INSTANCE;
    }

    // schema methods

    public RecordBatchDef newMessage()
    {
        return new RecordBatchDef();
    }

    public Class<RecordBatchDef> typeClass()
    {
        return RecordBatchDef.class;
    }

    public String messageName()
    {
        return RecordBatchDef.class.getSimpleName();
    }

    public String messageFullName()
    {
        return RecordBatchDef.class.getName();
    }

    public boolean isInitialized(RecordBatchDef message)
    {
        return true;
    }

    public void mergeFrom(Input input, RecordBatchDef message) throws IOException
    {
        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
        {
            switch(number)
            {
                case 0:
                    return;
                case 1:
                    message.recordCount = input.readInt32();
                    break;
                case 2:
                    if(message.field == null)
                        message.field = new ArrayList<SerializedField>();
                    message.field.add(input.mergeObject(null, SerializedField.getSchema()));
                    break;

                case 3:
                    message.carriesTwoByteSelectionVector = input.readBool();
                    break;
                case 4:
                    message.affectedRowsCount = input.readInt32();
                    break;
                default:
                    input.handleUnknownField(number, this);
            }   
        }
    }


    public void writeTo(Output output, RecordBatchDef message) throws IOException
    {
        if(message.recordCount != 0)
            output.writeInt32(1, message.recordCount, false);

        if(message.field != null)
        {
            for(SerializedField field : message.field)
            {
                if(field != null)
                    output.writeObject(2, field, SerializedField.getSchema(), true);
            }
        }


        if(message.carriesTwoByteSelectionVector != null)
            output.writeBool(3, message.carriesTwoByteSelectionVector, false);

        if(message.affectedRowsCount != 0)
            output.writeInt32(4, message.affectedRowsCount, false);
    }

    public String getFieldName(int number)
    {
        switch(number)
        {
            case 1: return "recordCount";
            case 2: return "field";
            case 3: return "carriesTwoByteSelectionVector";
            case 4: return "affectedRowsCount";
            default: return null;
        }
    }

    public int getFieldNumber(String name)
    {
        final Integer number = __fieldMap.get(name);
        return number == null ? 0 : number.intValue();
    }

    private static final java.util.HashMap<String,Integer> __fieldMap = new java.util.HashMap<String,Integer>();
    static
    {
        __fieldMap.put("recordCount", 1);
        __fieldMap.put("field", 2);
        __fieldMap.put("carriesTwoByteSelectionVector", 3);
        __fieldMap.put("affectedRowsCount", 4);
    }
    
}
