//------------------------------------------------------------------------------
// Automatically generated by the Fast Binary Encoding compiler, do not modify!
// https://github.com/chronoxor/FastBinaryEncoding
// Source: test.fbe
// FBE version: 1.15.0.0
//------------------------------------------------------------------------------

package test

import "errors"
import "../fbe"

// Fast Binary Encoding EnumSimple final model
type FinalModelEnumSimple struct {
    // Final model buffer
    buffer *fbe.Buffer
    // Final model buffer offset
    offset int
}

// Create a new EnumSimple final model
func NewFinalModelEnumSimple(buffer *fbe.Buffer, offset int) *FinalModelEnumSimple {
    return &FinalModelEnumSimple{buffer: buffer, offset: offset}
}

// Get the allocation size
func (fm *FinalModelEnumSimple) FBEAllocationSize(value *EnumSimple) int { return fm.FBESize() }

// Get the final size
func (fm *FinalModelEnumSimple) FBESize() int { return 4 }

// Get the final offset
func (fm *FinalModelEnumSimple) FBEOffset() int { return fm.offset }
// Set the final offset
func (fm *FinalModelEnumSimple) SetFBEOffset(value int) { fm.offset = value }

// Shift the current final offset
func (fm *FinalModelEnumSimple) FBEShift(size int) { fm.offset += size }
// Unshift the current final offset
func (fm *FinalModelEnumSimple) FBEUnshift(size int) { fm.offset -= size }

// Check if the value is valid
func (fm *FinalModelEnumSimple) Verify() int {
    if (fm.buffer.Offset() + fm.FBEOffset() + fm.FBESize()) > fm.buffer.Size() {
        return fbe.MaxInt
    }

    return fm.FBESize()
}

// Get the value
func (fm *FinalModelEnumSimple) Get() (*EnumSimple, int, error) {
    var value EnumSimple
    size, err := fm.GetValueDefault(&value, EnumSimple(0))
    return &value, size, err
}

// Get the value with provided default value
func (fm *FinalModelEnumSimple) GetDefault(defaults EnumSimple) (*EnumSimple, int, error) {
    var value EnumSimple
    size, err := fm.GetValueDefault(&value, defaults)
    return &value, size, err
}

// Get the value by the given pointer
func (fm *FinalModelEnumSimple) GetValue(value *EnumSimple) (int, error) {
    return fm.GetValueDefault(value, EnumSimple(0))
}

// Get the value by the given pointer with provided default value
func (fm *FinalModelEnumSimple) GetValueDefault(value *EnumSimple, defaults EnumSimple) (int, error) {
    if (fm.buffer.Offset() + fm.FBEOffset() + fm.FBESize()) > fm.buffer.Size() {
        *value = defaults
        return 0, errors.New("model is broken")
    }

    *value = EnumSimple(fbe.ReadInt32(fm.buffer.Data(), fm.buffer.Offset() + fm.FBEOffset()))
    return fm.FBESize(), nil
}

// Set the value by the given pointer
func (fm *FinalModelEnumSimple) Set(value *EnumSimple) (int, error) {
    return fm.SetValue(*value)
}

// Set the value
func (fm *FinalModelEnumSimple) SetValue(value EnumSimple) (int, error) {
    if (fm.buffer.Offset() + fm.FBEOffset() + fm.FBESize()) > fm.buffer.Size() {
        return 0, errors.New("model is broken")
    }

    fbe.WriteInt32(fm.buffer.Data(), fm.buffer.Offset() + fm.FBEOffset(), int32(value))
    return fm.FBESize(), nil
}
