blob: 1b93bf7ecd4676119835cad041f07a2532f7e476 [file]
/*
* 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
*
* https://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.
*/
package model
import (
"context"
stdErrors "errors"
"fmt"
"github.com/rs/zerolog"
. "github.com/apache/plc4x/plc4go/spi/codegen/fields"
. "github.com/apache/plc4x/plc4go/spi/codegen/io"
"github.com/apache/plc4x/plc4go/spi/errors"
"github.com/apache/plc4x/plc4go/spi/utils"
)
// Code generated by code-generation. DO NOT EDIT.
// AdsExtendedInfoEntryInt32 is the corresponding interface of AdsExtendedInfoEntryInt32
type AdsExtendedInfoEntryInt32 interface {
fmt.Stringer
utils.LengthAware
utils.Serializable
utils.Copyable
AdsExtendedInfoEntry
// GetValue returns Value (property field)
GetValue() int32
// IsAdsExtendedInfoEntryInt32 is a marker method to prevent unintentional type checks (interfaces of same signature)
IsAdsExtendedInfoEntryInt32()
// CreateBuilder creates a AdsExtendedInfoEntryInt32Builder
CreateAdsExtendedInfoEntryInt32Builder() AdsExtendedInfoEntryInt32Builder
}
// _AdsExtendedInfoEntryInt32 is the data-structure of this message
type _AdsExtendedInfoEntryInt32 struct {
AdsExtendedInfoEntryContract
Value int32
}
var _ AdsExtendedInfoEntryInt32 = (*_AdsExtendedInfoEntryInt32)(nil)
var _ AdsExtendedInfoEntryRequirements = (*_AdsExtendedInfoEntryInt32)(nil)
// NewAdsExtendedInfoEntryInt32 factory function for _AdsExtendedInfoEntryInt32
func NewAdsExtendedInfoEntryInt32(name string, value int32) *_AdsExtendedInfoEntryInt32 {
_result := &_AdsExtendedInfoEntryInt32{
AdsExtendedInfoEntryContract: NewAdsExtendedInfoEntry(name),
Value: value,
}
_result.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry)._SubType = _result
return _result
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
/////////////////////// Builder
///////////////////////
// AdsExtendedInfoEntryInt32Builder is a builder for AdsExtendedInfoEntryInt32
type AdsExtendedInfoEntryInt32Builder interface {
utils.Copyable
// WithMandatoryFields adds all mandatory fields (convenience for using multiple builder calls)
WithMandatoryFields(value int32) AdsExtendedInfoEntryInt32Builder
// WithValue adds Value (property field)
WithValue(int32) AdsExtendedInfoEntryInt32Builder
// Done is used to finish work on this child and return (or create one if none) to the parent builder
Done() AdsExtendedInfoEntryBuilder
// Build builds the AdsExtendedInfoEntryInt32 or returns an error if something is wrong
Build() (AdsExtendedInfoEntryInt32, error)
// MustBuild does the same as Build but panics on error
MustBuild() AdsExtendedInfoEntryInt32
}
// NewAdsExtendedInfoEntryInt32Builder() creates a AdsExtendedInfoEntryInt32Builder
func NewAdsExtendedInfoEntryInt32Builder() AdsExtendedInfoEntryInt32Builder {
return &_AdsExtendedInfoEntryInt32Builder{_AdsExtendedInfoEntryInt32: new(_AdsExtendedInfoEntryInt32)}
}
type _AdsExtendedInfoEntryInt32Builder struct {
*_AdsExtendedInfoEntryInt32
parentBuilder *_AdsExtendedInfoEntryBuilder
collectedErr []error
}
var _ (AdsExtendedInfoEntryInt32Builder) = (*_AdsExtendedInfoEntryInt32Builder)(nil)
func (b *_AdsExtendedInfoEntryInt32Builder) setParent(contract AdsExtendedInfoEntryContract) {
b.AdsExtendedInfoEntryContract = contract
contract.(*_AdsExtendedInfoEntry)._SubType = b._AdsExtendedInfoEntryInt32
}
func (b *_AdsExtendedInfoEntryInt32Builder) WithMandatoryFields(value int32) AdsExtendedInfoEntryInt32Builder {
return b.WithValue(value)
}
func (b *_AdsExtendedInfoEntryInt32Builder) WithValue(value int32) AdsExtendedInfoEntryInt32Builder {
b.Value = value
return b
}
func (b *_AdsExtendedInfoEntryInt32Builder) Build() (AdsExtendedInfoEntryInt32, error) {
if err := stdErrors.Join(b.collectedErr...); err != nil {
return nil, errors.Wrap(err, "error occurred during build")
}
return b._AdsExtendedInfoEntryInt32.deepCopy(), nil
}
func (b *_AdsExtendedInfoEntryInt32Builder) MustBuild() AdsExtendedInfoEntryInt32 {
build, err := b.Build()
if err != nil {
panic(err)
}
return build
}
func (b *_AdsExtendedInfoEntryInt32Builder) Done() AdsExtendedInfoEntryBuilder {
if b.parentBuilder == nil {
b.parentBuilder = NewAdsExtendedInfoEntryBuilder().(*_AdsExtendedInfoEntryBuilder)
}
return b.parentBuilder
}
func (b *_AdsExtendedInfoEntryInt32Builder) buildForAdsExtendedInfoEntry() (AdsExtendedInfoEntry, error) {
return b.Build()
}
func (b *_AdsExtendedInfoEntryInt32Builder) DeepCopy() any {
_copy := b.CreateAdsExtendedInfoEntryInt32Builder().(*_AdsExtendedInfoEntryInt32Builder)
if b.collectedErr != nil {
copy(_copy.collectedErr, b.collectedErr)
}
return _copy
}
// CreateAdsExtendedInfoEntryInt32Builder creates a AdsExtendedInfoEntryInt32Builder
func (b *_AdsExtendedInfoEntryInt32) CreateAdsExtendedInfoEntryInt32Builder() AdsExtendedInfoEntryInt32Builder {
if b == nil {
return NewAdsExtendedInfoEntryInt32Builder()
}
return &_AdsExtendedInfoEntryInt32Builder{_AdsExtendedInfoEntryInt32: b.deepCopy()}
}
///////////////////////
///////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
/////////////////////// Accessors for discriminator values.
///////////////////////
func (m *_AdsExtendedInfoEntryInt32) GetDataType() AdsDatatypeId {
return AdsDatatypeId_ADST_INT32
}
///////////////////////
///////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
func (m *_AdsExtendedInfoEntryInt32) GetParent() AdsExtendedInfoEntryContract {
return m.AdsExtendedInfoEntryContract
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
/////////////////////// Accessors for property fields.
///////////////////////
func (m *_AdsExtendedInfoEntryInt32) GetValue() int32 {
return m.Value
}
///////////////////////
///////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Deprecated: use the interface for direct cast
func CastAdsExtendedInfoEntryInt32(structType any) AdsExtendedInfoEntryInt32 {
if casted, ok := structType.(AdsExtendedInfoEntryInt32); ok {
return casted
}
if casted, ok := structType.(*AdsExtendedInfoEntryInt32); ok {
return *casted
}
return nil
}
func (m *_AdsExtendedInfoEntryInt32) GetPlx4xTypeName() string {
return "AdsExtendedInfoEntryInt32"
}
func (m *_AdsExtendedInfoEntryInt32) GetLengthInBits(ctx context.Context) uint16 {
lengthInBits := uint16(m.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry).getLengthInBits(ctx))
// Simple field (value)
lengthInBits += 32
return lengthInBits
}
func (m *_AdsExtendedInfoEntryInt32) GetLengthInBytes(ctx context.Context) uint16 {
return m.GetLengthInBits(ctx) / 8
}
func (m *_AdsExtendedInfoEntryInt32) parse(ctx context.Context, readBuffer utils.ReadBuffer, parent *_AdsExtendedInfoEntry, dataType AdsDatatypeId) (__adsExtendedInfoEntryInt32 AdsExtendedInfoEntryInt32, err error) {
m.AdsExtendedInfoEntryContract = parent
parent._SubType = m
positionAware := readBuffer
_ = positionAware
if pullErr := readBuffer.PullContext("AdsExtendedInfoEntryInt32"); pullErr != nil {
return nil, errors.Wrap(pullErr, "Error pulling for AdsExtendedInfoEntryInt32")
}
currentPos := positionAware.GetPos()
_ = currentPos
value, err := ReadSimpleField(ctx, "value", ReadSignedInt(readBuffer, uint8(32)))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'value' field"))
}
m.Value = value
if closeErr := readBuffer.CloseContext("AdsExtendedInfoEntryInt32"); closeErr != nil {
return nil, errors.Wrap(closeErr, "Error closing for AdsExtendedInfoEntryInt32")
}
return m, nil
}
func (m *_AdsExtendedInfoEntryInt32) Serialize() ([]byte, error) {
wb := utils.NewWriteBufferByteBased(utils.WithInitialSizeForByteBasedBuffer(int(m.GetLengthInBytes(context.Background()))))
if err := m.SerializeWithWriteBuffer(context.Background(), wb); err != nil {
return nil, err
}
return wb.GetBytes(), nil
}
func (m *_AdsExtendedInfoEntryInt32) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error {
positionAware := writeBuffer
_ = positionAware
log := zerolog.Ctx(ctx)
_ = log
ser := func() error {
if pushErr := writeBuffer.PushContext("AdsExtendedInfoEntryInt32"); pushErr != nil {
return errors.Wrap(pushErr, "Error pushing for AdsExtendedInfoEntryInt32")
}
if err := WriteSimpleField[int32](ctx, "value", m.GetValue(), WriteSignedInt(writeBuffer, 32)); err != nil {
return errors.Wrap(err, "Error serializing 'value' field")
}
if popErr := writeBuffer.PopContext("AdsExtendedInfoEntryInt32"); popErr != nil {
return errors.Wrap(popErr, "Error popping for AdsExtendedInfoEntryInt32")
}
return nil
}
return m.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry).serializeParent(ctx, writeBuffer, m, ser)
}
func (m *_AdsExtendedInfoEntryInt32) IsAdsExtendedInfoEntryInt32() {}
func (m *_AdsExtendedInfoEntryInt32) DeepCopy() any {
return m.deepCopy()
}
func (m *_AdsExtendedInfoEntryInt32) deepCopy() *_AdsExtendedInfoEntryInt32 {
if m == nil {
return nil
}
_AdsExtendedInfoEntryInt32Copy := &_AdsExtendedInfoEntryInt32{
m.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry).deepCopy(),
m.Value,
}
_AdsExtendedInfoEntryInt32Copy.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry)._SubType = m
return _AdsExtendedInfoEntryInt32Copy
}
func (m *_AdsExtendedInfoEntryInt32) String() string {
if m == nil {
return "<nil>"
}
wb := utils.NewWriteBufferBoxBased(
utils.WithWriteBufferBoxBasedMergeSingleBoxes(),
utils.WithWriteBufferBoxBasedOmitEmptyBoxes(),
utils.WithWriteBufferBoxBasedPrintPosLengthFooter(),
)
if err := wb.WriteSerializable(context.Background(), m); err != nil {
return err.Error()
}
return wb.GetBox().String()
}