| /* |
| * 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. |
| |
| // AdsExtendedInfoEntryInt64 is the corresponding interface of AdsExtendedInfoEntryInt64 |
| type AdsExtendedInfoEntryInt64 interface { |
| fmt.Stringer |
| utils.LengthAware |
| utils.Serializable |
| utils.Copyable |
| AdsExtendedInfoEntry |
| // GetValue returns Value (property field) |
| GetValue() int64 |
| // IsAdsExtendedInfoEntryInt64 is a marker method to prevent unintentional type checks (interfaces of same signature) |
| IsAdsExtendedInfoEntryInt64() |
| // CreateBuilder creates a AdsExtendedInfoEntryInt64Builder |
| CreateAdsExtendedInfoEntryInt64Builder() AdsExtendedInfoEntryInt64Builder |
| } |
| |
| // _AdsExtendedInfoEntryInt64 is the data-structure of this message |
| type _AdsExtendedInfoEntryInt64 struct { |
| AdsExtendedInfoEntryContract |
| Value int64 |
| } |
| |
| var _ AdsExtendedInfoEntryInt64 = (*_AdsExtendedInfoEntryInt64)(nil) |
| var _ AdsExtendedInfoEntryRequirements = (*_AdsExtendedInfoEntryInt64)(nil) |
| |
| // NewAdsExtendedInfoEntryInt64 factory function for _AdsExtendedInfoEntryInt64 |
| func NewAdsExtendedInfoEntryInt64(name string, value int64) *_AdsExtendedInfoEntryInt64 { |
| _result := &_AdsExtendedInfoEntryInt64{ |
| AdsExtendedInfoEntryContract: NewAdsExtendedInfoEntry(name), |
| Value: value, |
| } |
| _result.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry)._SubType = _result |
| return _result |
| } |
| |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////// Builder |
| /////////////////////// |
| |
| // AdsExtendedInfoEntryInt64Builder is a builder for AdsExtendedInfoEntryInt64 |
| type AdsExtendedInfoEntryInt64Builder interface { |
| utils.Copyable |
| // WithMandatoryFields adds all mandatory fields (convenience for using multiple builder calls) |
| WithMandatoryFields(value int64) AdsExtendedInfoEntryInt64Builder |
| // WithValue adds Value (property field) |
| WithValue(int64) AdsExtendedInfoEntryInt64Builder |
| // 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 AdsExtendedInfoEntryInt64 or returns an error if something is wrong |
| Build() (AdsExtendedInfoEntryInt64, error) |
| // MustBuild does the same as Build but panics on error |
| MustBuild() AdsExtendedInfoEntryInt64 |
| } |
| |
| // NewAdsExtendedInfoEntryInt64Builder() creates a AdsExtendedInfoEntryInt64Builder |
| func NewAdsExtendedInfoEntryInt64Builder() AdsExtendedInfoEntryInt64Builder { |
| return &_AdsExtendedInfoEntryInt64Builder{_AdsExtendedInfoEntryInt64: new(_AdsExtendedInfoEntryInt64)} |
| } |
| |
| type _AdsExtendedInfoEntryInt64Builder struct { |
| *_AdsExtendedInfoEntryInt64 |
| |
| parentBuilder *_AdsExtendedInfoEntryBuilder |
| |
| collectedErr []error |
| } |
| |
| var _ (AdsExtendedInfoEntryInt64Builder) = (*_AdsExtendedInfoEntryInt64Builder)(nil) |
| |
| func (b *_AdsExtendedInfoEntryInt64Builder) setParent(contract AdsExtendedInfoEntryContract) { |
| b.AdsExtendedInfoEntryContract = contract |
| contract.(*_AdsExtendedInfoEntry)._SubType = b._AdsExtendedInfoEntryInt64 |
| } |
| |
| func (b *_AdsExtendedInfoEntryInt64Builder) WithMandatoryFields(value int64) AdsExtendedInfoEntryInt64Builder { |
| return b.WithValue(value) |
| } |
| |
| func (b *_AdsExtendedInfoEntryInt64Builder) WithValue(value int64) AdsExtendedInfoEntryInt64Builder { |
| b.Value = value |
| return b |
| } |
| |
| func (b *_AdsExtendedInfoEntryInt64Builder) Build() (AdsExtendedInfoEntryInt64, error) { |
| if err := stdErrors.Join(b.collectedErr...); err != nil { |
| return nil, errors.Wrap(err, "error occurred during build") |
| } |
| return b._AdsExtendedInfoEntryInt64.deepCopy(), nil |
| } |
| |
| func (b *_AdsExtendedInfoEntryInt64Builder) MustBuild() AdsExtendedInfoEntryInt64 { |
| build, err := b.Build() |
| if err != nil { |
| panic(err) |
| } |
| return build |
| } |
| |
| func (b *_AdsExtendedInfoEntryInt64Builder) Done() AdsExtendedInfoEntryBuilder { |
| if b.parentBuilder == nil { |
| b.parentBuilder = NewAdsExtendedInfoEntryBuilder().(*_AdsExtendedInfoEntryBuilder) |
| } |
| return b.parentBuilder |
| } |
| |
| func (b *_AdsExtendedInfoEntryInt64Builder) buildForAdsExtendedInfoEntry() (AdsExtendedInfoEntry, error) { |
| return b.Build() |
| } |
| |
| func (b *_AdsExtendedInfoEntryInt64Builder) DeepCopy() any { |
| _copy := b.CreateAdsExtendedInfoEntryInt64Builder().(*_AdsExtendedInfoEntryInt64Builder) |
| if b.collectedErr != nil { |
| copy(_copy.collectedErr, b.collectedErr) |
| } |
| return _copy |
| } |
| |
| // CreateAdsExtendedInfoEntryInt64Builder creates a AdsExtendedInfoEntryInt64Builder |
| func (b *_AdsExtendedInfoEntryInt64) CreateAdsExtendedInfoEntryInt64Builder() AdsExtendedInfoEntryInt64Builder { |
| if b == nil { |
| return NewAdsExtendedInfoEntryInt64Builder() |
| } |
| return &_AdsExtendedInfoEntryInt64Builder{_AdsExtendedInfoEntryInt64: b.deepCopy()} |
| } |
| |
| /////////////////////// |
| /////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////// Accessors for discriminator values. |
| /////////////////////// |
| |
| func (m *_AdsExtendedInfoEntryInt64) GetDataType() AdsDatatypeId { |
| return AdsDatatypeId_ADST_INT64 |
| } |
| |
| /////////////////////// |
| /////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| |
| func (m *_AdsExtendedInfoEntryInt64) GetParent() AdsExtendedInfoEntryContract { |
| return m.AdsExtendedInfoEntryContract |
| } |
| |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////// Accessors for property fields. |
| /////////////////////// |
| |
| func (m *_AdsExtendedInfoEntryInt64) GetValue() int64 { |
| return m.Value |
| } |
| |
| /////////////////////// |
| /////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| |
| // Deprecated: use the interface for direct cast |
| func CastAdsExtendedInfoEntryInt64(structType any) AdsExtendedInfoEntryInt64 { |
| if casted, ok := structType.(AdsExtendedInfoEntryInt64); ok { |
| return casted |
| } |
| if casted, ok := structType.(*AdsExtendedInfoEntryInt64); ok { |
| return *casted |
| } |
| return nil |
| } |
| |
| func (m *_AdsExtendedInfoEntryInt64) GetPlx4xTypeName() string { |
| return "AdsExtendedInfoEntryInt64" |
| } |
| |
| func (m *_AdsExtendedInfoEntryInt64) GetLengthInBits(ctx context.Context) uint16 { |
| lengthInBits := uint16(m.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry).getLengthInBits(ctx)) |
| |
| // Simple field (value) |
| lengthInBits += 64 |
| |
| return lengthInBits |
| } |
| |
| func (m *_AdsExtendedInfoEntryInt64) GetLengthInBytes(ctx context.Context) uint16 { |
| return m.GetLengthInBits(ctx) / 8 |
| } |
| |
| func (m *_AdsExtendedInfoEntryInt64) parse(ctx context.Context, readBuffer utils.ReadBuffer, parent *_AdsExtendedInfoEntry, dataType AdsDatatypeId) (__adsExtendedInfoEntryInt64 AdsExtendedInfoEntryInt64, err error) { |
| m.AdsExtendedInfoEntryContract = parent |
| parent._SubType = m |
| positionAware := readBuffer |
| _ = positionAware |
| if pullErr := readBuffer.PullContext("AdsExtendedInfoEntryInt64"); pullErr != nil { |
| return nil, errors.Wrap(pullErr, "Error pulling for AdsExtendedInfoEntryInt64") |
| } |
| currentPos := positionAware.GetPos() |
| _ = currentPos |
| |
| value, err := ReadSimpleField(ctx, "value", ReadSignedLong(readBuffer, uint8(64))) |
| if err != nil { |
| return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'value' field")) |
| } |
| m.Value = value |
| |
| if closeErr := readBuffer.CloseContext("AdsExtendedInfoEntryInt64"); closeErr != nil { |
| return nil, errors.Wrap(closeErr, "Error closing for AdsExtendedInfoEntryInt64") |
| } |
| |
| return m, nil |
| } |
| |
| func (m *_AdsExtendedInfoEntryInt64) 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 *_AdsExtendedInfoEntryInt64) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { |
| positionAware := writeBuffer |
| _ = positionAware |
| log := zerolog.Ctx(ctx) |
| _ = log |
| ser := func() error { |
| if pushErr := writeBuffer.PushContext("AdsExtendedInfoEntryInt64"); pushErr != nil { |
| return errors.Wrap(pushErr, "Error pushing for AdsExtendedInfoEntryInt64") |
| } |
| |
| if err := WriteSimpleField[int64](ctx, "value", m.GetValue(), WriteSignedLong(writeBuffer, 64)); err != nil { |
| return errors.Wrap(err, "Error serializing 'value' field") |
| } |
| |
| if popErr := writeBuffer.PopContext("AdsExtendedInfoEntryInt64"); popErr != nil { |
| return errors.Wrap(popErr, "Error popping for AdsExtendedInfoEntryInt64") |
| } |
| return nil |
| } |
| return m.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry).serializeParent(ctx, writeBuffer, m, ser) |
| } |
| |
| func (m *_AdsExtendedInfoEntryInt64) IsAdsExtendedInfoEntryInt64() {} |
| |
| func (m *_AdsExtendedInfoEntryInt64) DeepCopy() any { |
| return m.deepCopy() |
| } |
| |
| func (m *_AdsExtendedInfoEntryInt64) deepCopy() *_AdsExtendedInfoEntryInt64 { |
| if m == nil { |
| return nil |
| } |
| _AdsExtendedInfoEntryInt64Copy := &_AdsExtendedInfoEntryInt64{ |
| m.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry).deepCopy(), |
| m.Value, |
| } |
| _AdsExtendedInfoEntryInt64Copy.AdsExtendedInfoEntryContract.(*_AdsExtendedInfoEntry)._SubType = m |
| return _AdsExtendedInfoEntryInt64Copy |
| } |
| |
| func (m *_AdsExtendedInfoEntryInt64) 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() |
| } |