/*
 * 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 SerializedField implements Externalizable, Message<SerializedField>, Schema<SerializedField>
{

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

    public static SerializedField getDefaultInstance()
    {
        return DEFAULT_INSTANCE;
    }

    static final SerializedField DEFAULT_INSTANCE = new SerializedField();

    
    private org.apache.drill.common.types.MajorType majorType;
    private NamePart namePart;
    private List<SerializedField> child;
    private int valueCount;
    private int varByteLength;
    private int bufferLength;

    public SerializedField()
    {
        
    }

    // getters and setters

    // majorType

    public org.apache.drill.common.types.MajorType getMajorType()
    {
        return majorType;
    }

    public SerializedField setMajorType(org.apache.drill.common.types.MajorType majorType)
    {
        this.majorType = majorType;
        return this;
    }

    // namePart

    public NamePart getNamePart()
    {
        return namePart;
    }

    public SerializedField setNamePart(NamePart namePart)
    {
        this.namePart = namePart;
        return this;
    }

    // child

    public List<SerializedField> getChildList()
    {
        return child;
    }

    public SerializedField setChildList(List<SerializedField> child)
    {
        this.child = child;
        return this;
    }

    // valueCount

    public int getValueCount()
    {
        return valueCount;
    }

    public SerializedField setValueCount(int valueCount)
    {
        this.valueCount = valueCount;
        return this;
    }

    // varByteLength

    public int getVarByteLength()
    {
        return varByteLength;
    }

    public SerializedField setVarByteLength(int varByteLength)
    {
        this.varByteLength = varByteLength;
        return this;
    }

    // bufferLength

    public int getBufferLength()
    {
        return bufferLength;
    }

    public SerializedField setBufferLength(int bufferLength)
    {
        this.bufferLength = bufferLength;
        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<SerializedField> cachedSchema()
    {
        return DEFAULT_INSTANCE;
    }

    // schema methods

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

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

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

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

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

    public void mergeFrom(Input input, SerializedField message) throws IOException
    {
        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
        {
            switch(number)
            {
                case 0:
                    return;
                case 1:
                    message.majorType = input.mergeObject(message.majorType, org.apache.drill.common.types.MajorType.getSchema());
                    break;

                case 2:
                    message.namePart = input.mergeObject(message.namePart, NamePart.getSchema());
                    break;

                case 3:
                    if(message.child == null)
                        message.child = new ArrayList<SerializedField>();
                    message.child.add(input.mergeObject(null, SerializedField.getSchema()));
                    break;

                case 4:
                    message.valueCount = input.readInt32();
                    break;
                case 5:
                    message.varByteLength = input.readInt32();
                    break;
                case 7:
                    message.bufferLength = input.readInt32();
                    break;
                default:
                    input.handleUnknownField(number, this);
            }   
        }
    }


    public void writeTo(Output output, SerializedField message) throws IOException
    {
        if(message.majorType != null)
             output.writeObject(1, message.majorType, org.apache.drill.common.types.MajorType.getSchema(), false);


        if(message.namePart != null)
             output.writeObject(2, message.namePart, NamePart.getSchema(), false);


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


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

        if(message.varByteLength != 0)
            output.writeInt32(5, message.varByteLength, false);

        if(message.bufferLength != 0)
            output.writeInt32(7, message.bufferLength, false);
    }

    public String getFieldName(int number)
    {
        switch(number)
        {
            case 1: return "majorType";
            case 2: return "namePart";
            case 3: return "child";
            case 4: return "valueCount";
            case 5: return "varByteLength";
            case 7: return "bufferLength";
            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("majorType", 1);
        __fieldMap.put("namePart", 2);
        __fieldMap.put("child", 3);
        __fieldMap.put("valueCount", 4);
        __fieldMap.put("varByteLength", 5);
        __fieldMap.put("bufferLength", 7);
    }
    
}
