// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file is autogenerated by:
//     mojo/public/tools/bindings/mojom_bindings_generator.py
// For:
//     extensions/common/mojo/stash.mojom
//

package org.chromium.mojom.extensions;

public final class StashedObject extends org.chromium.mojo.bindings.Struct {

    private static final int STRUCT_SIZE = 40;
    private static final org.chromium.mojo.bindings.DataHeader[] VERSION_ARRAY = new org.chromium.mojo.bindings.DataHeader[] {new org.chromium.mojo.bindings.DataHeader(40, 0)};
    private static final org.chromium.mojo.bindings.DataHeader DEFAULT_STRUCT_INFO = VERSION_ARRAY[0];

    public String id;
    public byte[] data;
    public org.chromium.mojo.system.UntypedHandle[] stashedHandles;
    public boolean monitorHandles;

    private StashedObject(int version) {
        super(STRUCT_SIZE, version);
        monitorHandles = (boolean) false;
    }

    public StashedObject() {
        this(0);
    }

    public static StashedObject deserialize(org.chromium.mojo.bindings.Message message) {
        return decode(new org.chromium.mojo.bindings.Decoder(message));
    }

    @SuppressWarnings("unchecked")
    public static StashedObject decode(org.chromium.mojo.bindings.Decoder decoder0) {
        if (decoder0 == null) {
            return null;
        }
        org.chromium.mojo.bindings.DataHeader mainDataHeader = decoder0.readAndValidateDataHeader(VERSION_ARRAY);
        StashedObject result = new StashedObject(mainDataHeader.elementsOrVersion);
        if (mainDataHeader.elementsOrVersion >= 0) {
            result.id = decoder0.readString(8, false);
        }
        if (mainDataHeader.elementsOrVersion >= 0) {
            result.data = decoder0.readBytes(16, org.chromium.mojo.bindings.BindingsHelper.NOTHING_NULLABLE, org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH);
        }
        if (mainDataHeader.elementsOrVersion >= 0) {
            result.stashedHandles = decoder0.readUntypedHandles(24, org.chromium.mojo.bindings.BindingsHelper.NOTHING_NULLABLE, org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH);
        }
        if (mainDataHeader.elementsOrVersion >= 0) {
            result.monitorHandles = decoder0.readBoolean(32, 0);
        }
        return result;
    }

    @SuppressWarnings("unchecked")
    @Override
    protected final void encode(org.chromium.mojo.bindings.Encoder encoder) {
        org.chromium.mojo.bindings.Encoder encoder0 = encoder.getEncoderAtDataOffset(DEFAULT_STRUCT_INFO);
        encoder0.encode(id, 8, false);
        encoder0.encode(data, 16, org.chromium.mojo.bindings.BindingsHelper.NOTHING_NULLABLE, org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH);
        encoder0.encode(stashedHandles, 24, org.chromium.mojo.bindings.BindingsHelper.NOTHING_NULLABLE, org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH);
        encoder0.encode(monitorHandles, 32, 0);
    }

    /**
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(Object object) {
        if (object == this)
            return true;
        if (object == null)
            return false;
        if (getClass() != object.getClass())
            return false;
        StashedObject other = (StashedObject) object;
        if (!org.chromium.mojo.bindings.BindingsHelper.equals(this.id, other.id))
            return false;
        if (!java.util.Arrays.equals(this.data, other.data))
            return false;
        if (!java.util.Arrays.deepEquals(this.stashedHandles, other.stashedHandles))
            return false;
        if (this.monitorHandles != other.monitorHandles)
            return false;
        return true;
    }

    /**
     * @see Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = prime + getClass().hashCode();
        result = prime * result + org.chromium.mojo.bindings.BindingsHelper.hashCode(id);
        result = prime * result + java.util.Arrays.hashCode(data);
        result = prime * result + java.util.Arrays.deepHashCode(stashedHandles);
        result = prime * result + org.chromium.mojo.bindings.BindingsHelper.hashCode(monitorHandles);
        return result;
    }
}

