blob: 3ec1fc1ed26a069d5bce379b79a1444df6879aba [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.
// AdsMethodInfos is the corresponding interface of AdsMethodInfos
type AdsMethodInfos interface {
fmt.Stringer
utils.LengthAware
utils.Serializable
utils.Copyable
// GetMethodInfos returns MethodInfos (property field)
GetMethodInfos() []AdsMethodInfo
// IsAdsMethodInfos is a marker method to prevent unintentional type checks (interfaces of same signature)
IsAdsMethodInfos()
// CreateBuilder creates a AdsMethodInfosBuilder
CreateAdsMethodInfosBuilder() AdsMethodInfosBuilder
}
// _AdsMethodInfos is the data-structure of this message
type _AdsMethodInfos struct {
MethodInfos []AdsMethodInfo
}
var _ AdsMethodInfos = (*_AdsMethodInfos)(nil)
// NewAdsMethodInfos factory function for _AdsMethodInfos
func NewAdsMethodInfos(methodInfos []AdsMethodInfo) *_AdsMethodInfos {
return &_AdsMethodInfos{MethodInfos: methodInfos}
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
/////////////////////// Builder
///////////////////////
// AdsMethodInfosBuilder is a builder for AdsMethodInfos
type AdsMethodInfosBuilder interface {
utils.Copyable
// WithMandatoryFields adds all mandatory fields (convenience for using multiple builder calls)
WithMandatoryFields(methodInfos []AdsMethodInfo) AdsMethodInfosBuilder
// WithMethodInfos adds MethodInfos (property field)
WithMethodInfos(...AdsMethodInfo) AdsMethodInfosBuilder
// Build builds the AdsMethodInfos or returns an error if something is wrong
Build() (AdsMethodInfos, error)
// MustBuild does the same as Build but panics on error
MustBuild() AdsMethodInfos
}
// NewAdsMethodInfosBuilder() creates a AdsMethodInfosBuilder
func NewAdsMethodInfosBuilder() AdsMethodInfosBuilder {
return &_AdsMethodInfosBuilder{_AdsMethodInfos: new(_AdsMethodInfos)}
}
type _AdsMethodInfosBuilder struct {
*_AdsMethodInfos
collectedErr []error
}
var _ (AdsMethodInfosBuilder) = (*_AdsMethodInfosBuilder)(nil)
func (b *_AdsMethodInfosBuilder) WithMandatoryFields(methodInfos []AdsMethodInfo) AdsMethodInfosBuilder {
return b.WithMethodInfos(methodInfos...)
}
func (b *_AdsMethodInfosBuilder) WithMethodInfos(methodInfos ...AdsMethodInfo) AdsMethodInfosBuilder {
b.MethodInfos = methodInfos
return b
}
func (b *_AdsMethodInfosBuilder) Build() (AdsMethodInfos, error) {
if err := stdErrors.Join(b.collectedErr...); err != nil {
return nil, errors.Wrap(err, "error occurred during build")
}
return b._AdsMethodInfos.deepCopy(), nil
}
func (b *_AdsMethodInfosBuilder) MustBuild() AdsMethodInfos {
build, err := b.Build()
if err != nil {
panic(err)
}
return build
}
func (b *_AdsMethodInfosBuilder) DeepCopy() any {
_copy := b.CreateAdsMethodInfosBuilder().(*_AdsMethodInfosBuilder)
if b.collectedErr != nil {
copy(_copy.collectedErr, b.collectedErr)
}
return _copy
}
// CreateAdsMethodInfosBuilder creates a AdsMethodInfosBuilder
func (b *_AdsMethodInfos) CreateAdsMethodInfosBuilder() AdsMethodInfosBuilder {
if b == nil {
return NewAdsMethodInfosBuilder()
}
return &_AdsMethodInfosBuilder{_AdsMethodInfos: b.deepCopy()}
}
///////////////////////
///////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
/////////////////////// Accessors for property fields.
///////////////////////
func (m *_AdsMethodInfos) GetMethodInfos() []AdsMethodInfo {
return m.MethodInfos
}
///////////////////////
///////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Deprecated: use the interface for direct cast
func CastAdsMethodInfos(structType any) AdsMethodInfos {
if casted, ok := structType.(AdsMethodInfos); ok {
return casted
}
if casted, ok := structType.(*AdsMethodInfos); ok {
return *casted
}
return nil
}
func (m *_AdsMethodInfos) GetPlx4xTypeName() string {
return "AdsMethodInfos"
}
func (m *_AdsMethodInfos) GetLengthInBits(ctx context.Context) uint16 {
lengthInBits := uint16(0)
// Implicit Field (numMethodInfos)
lengthInBits += 16
// Array field
if len(m.MethodInfos) > 0 {
for _curItem, element := range m.MethodInfos {
arrayCtx := utils.CreateArrayContext(ctx, len(m.MethodInfos), _curItem)
lengthInBits += element.GetLengthInBits(arrayCtx)
}
}
return lengthInBits
}
func (m *_AdsMethodInfos) GetLengthInBytes(ctx context.Context) uint16 {
return m.GetLengthInBits(ctx) / 8
}
func AdsMethodInfosParse(ctx context.Context, theBytes []byte) (AdsMethodInfos, error) {
return AdsMethodInfosParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes))
}
func AdsMethodInfosParseWithBufferProducer() func(ctx context.Context, readBuffer utils.ReadBuffer) (AdsMethodInfos, error) {
return func(ctx context.Context, readBuffer utils.ReadBuffer) (AdsMethodInfos, error) {
return AdsMethodInfosParseWithBuffer(ctx, readBuffer)
}
}
func AdsMethodInfosParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (AdsMethodInfos, error) {
v, err := (new(_AdsMethodInfos)).parse(ctx, readBuffer)
if err != nil {
return nil, err
}
return v, nil
}
func (m *_AdsMethodInfos) parse(ctx context.Context, readBuffer utils.ReadBuffer) (__adsMethodInfos AdsMethodInfos, err error) {
positionAware := readBuffer
_ = positionAware
if pullErr := readBuffer.PullContext("AdsMethodInfos"); pullErr != nil {
return nil, errors.Wrap(pullErr, "Error pulling for AdsMethodInfos")
}
currentPos := positionAware.GetPos()
_ = currentPos
numMethodInfos, err := ReadImplicitField[uint16](ctx, "numMethodInfos", ReadUnsignedShort(readBuffer, uint8(16)))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'numMethodInfos' field"))
}
_ = numMethodInfos
methodInfos, err := ReadCountArrayField[AdsMethodInfo](ctx, "methodInfos", ReadComplex[AdsMethodInfo](AdsMethodInfoParseWithBuffer, readBuffer), uint64(numMethodInfos))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'methodInfos' field"))
}
m.MethodInfos = methodInfos
if closeErr := readBuffer.CloseContext("AdsMethodInfos"); closeErr != nil {
return nil, errors.Wrap(closeErr, "Error closing for AdsMethodInfos")
}
return m, nil
}
func (m *_AdsMethodInfos) 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 *_AdsMethodInfos) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error {
positionAware := writeBuffer
_ = positionAware
log := zerolog.Ctx(ctx)
_ = log
if pushErr := writeBuffer.PushContext("AdsMethodInfos"); pushErr != nil {
return errors.Wrap(pushErr, "Error pushing for AdsMethodInfos")
}
numMethodInfos := uint16(uint16(len(m.GetMethodInfos())))
if err := WriteImplicitField(ctx, "numMethodInfos", numMethodInfos, WriteUnsignedShort(writeBuffer, 16)); err != nil {
return errors.Wrap(err, "Error serializing 'numMethodInfos' field")
}
if err := WriteComplexTypeArrayField(ctx, "methodInfos", m.GetMethodInfos(), writeBuffer); err != nil {
return errors.Wrap(err, "Error serializing 'methodInfos' field")
}
if popErr := writeBuffer.PopContext("AdsMethodInfos"); popErr != nil {
return errors.Wrap(popErr, "Error popping for AdsMethodInfos")
}
return nil
}
func (m *_AdsMethodInfos) IsAdsMethodInfos() {}
func (m *_AdsMethodInfos) DeepCopy() any {
return m.deepCopy()
}
func (m *_AdsMethodInfos) deepCopy() *_AdsMethodInfos {
if m == nil {
return nil
}
_AdsMethodInfosCopy := &_AdsMethodInfos{
utils.DeepCopySlice[AdsMethodInfo, AdsMethodInfo](m.MethodInfos),
}
return _AdsMethodInfosCopy
}
func (m *_AdsMethodInfos) 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()
}