//------------------------------------------------------------------------------
// 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 EnumTyped field model
type FieldModelEnumTyped struct {
    // Field model buffer
    buffer *fbe.Buffer
    // Field model buffer offset
    offset int
}

// Create a new EnumTyped field model
func NewFieldModelEnumTyped(buffer *fbe.Buffer, offset int) *FieldModelEnumTyped {
    return &FieldModelEnumTyped{buffer: buffer, offset: offset}
}

// Get the field size
func (fm *FieldModelEnumTyped) FBESize() int { return 1 }
// Get the field extra size
func (fm *FieldModelEnumTyped) FBEExtra() int { return 0 }

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

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

// Check if the value is valid
func (fm *FieldModelEnumTyped) Verify() bool { return true }

// Get the value
func (fm *FieldModelEnumTyped) Get() (*EnumTyped, error) {
    var value EnumTyped
    return &value, fm.GetValueDefault(&value, EnumTyped(0))
}

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

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

// Get the value by the given pointer with provided default value
func (fm *FieldModelEnumTyped) GetValueDefault(value *EnumTyped, defaults EnumTyped) error {
    if (fm.buffer.Offset() + fm.FBEOffset() + fm.FBESize()) > fm.buffer.Size() {
        *value = defaults
        return nil
    }

    *value = EnumTyped(fbe.ReadUInt8(fm.buffer.Data(), fm.buffer.Offset() + fm.FBEOffset()))
    return nil
}

// Set the value by the given pointer
func (fm *FieldModelEnumTyped) Set(value *EnumTyped) error {
    return fm.SetValue(*value)
}

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

    fbe.WriteUInt8(fm.buffer.Data(), fm.buffer.Offset() + fm.FBEOffset(), uint8(value))
    return nil
}
