| /* |
| * 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. |
| |
| // GetAttributeAllResponse is the corresponding interface of GetAttributeAllResponse |
| type GetAttributeAllResponse interface { |
| fmt.Stringer |
| utils.LengthAware |
| utils.Serializable |
| utils.Copyable |
| CipServiceResponse |
| // GetAttributes returns Attributes (property field) |
| GetAttributes() CIPAttributes |
| // IsGetAttributeAllResponse is a marker method to prevent unintentional type checks (interfaces of same signature) |
| IsGetAttributeAllResponse() |
| // CreateBuilder creates a GetAttributeAllResponseBuilder |
| CreateGetAttributeAllResponseBuilder() GetAttributeAllResponseBuilder |
| } |
| |
| // _GetAttributeAllResponse is the data-structure of this message |
| type _GetAttributeAllResponse struct { |
| CipServiceResponseContract |
| Attributes CIPAttributes |
| } |
| |
| var _ GetAttributeAllResponse = (*_GetAttributeAllResponse)(nil) |
| var _ CipServiceResponseRequirements = (*_GetAttributeAllResponse)(nil) |
| |
| // NewGetAttributeAllResponse factory function for _GetAttributeAllResponse |
| func NewGetAttributeAllResponse(status uint8, extStatus []uint16, attributes CIPAttributes) *_GetAttributeAllResponse { |
| _result := &_GetAttributeAllResponse{ |
| CipServiceResponseContract: NewCipServiceResponse(status, extStatus), |
| Attributes: attributes, |
| } |
| _result.CipServiceResponseContract.(*_CipServiceResponse)._SubType = _result |
| return _result |
| } |
| |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////// Builder |
| /////////////////////// |
| |
| // GetAttributeAllResponseBuilder is a builder for GetAttributeAllResponse |
| type GetAttributeAllResponseBuilder interface { |
| utils.Copyable |
| // WithMandatoryFields adds all mandatory fields (convenience for using multiple builder calls) |
| WithMandatoryFields() GetAttributeAllResponseBuilder |
| // WithAttributes adds Attributes (property field) |
| WithOptionalAttributes(CIPAttributes) GetAttributeAllResponseBuilder |
| // WithOptionalAttributesBuilder adds Attributes (property field) which is build by the builder |
| WithOptionalAttributesBuilder(func(CIPAttributesBuilder) CIPAttributesBuilder) GetAttributeAllResponseBuilder |
| // Done is used to finish work on this child and return (or create one if none) to the parent builder |
| Done() CipServiceResponseBuilder |
| // Build builds the GetAttributeAllResponse or returns an error if something is wrong |
| Build() (GetAttributeAllResponse, error) |
| // MustBuild does the same as Build but panics on error |
| MustBuild() GetAttributeAllResponse |
| } |
| |
| // NewGetAttributeAllResponseBuilder() creates a GetAttributeAllResponseBuilder |
| func NewGetAttributeAllResponseBuilder() GetAttributeAllResponseBuilder { |
| return &_GetAttributeAllResponseBuilder{_GetAttributeAllResponse: new(_GetAttributeAllResponse)} |
| } |
| |
| type _GetAttributeAllResponseBuilder struct { |
| *_GetAttributeAllResponse |
| |
| parentBuilder *_CipServiceResponseBuilder |
| |
| collectedErr []error |
| } |
| |
| var _ (GetAttributeAllResponseBuilder) = (*_GetAttributeAllResponseBuilder)(nil) |
| |
| func (b *_GetAttributeAllResponseBuilder) setParent(contract CipServiceResponseContract) { |
| b.CipServiceResponseContract = contract |
| contract.(*_CipServiceResponse)._SubType = b._GetAttributeAllResponse |
| } |
| |
| func (b *_GetAttributeAllResponseBuilder) WithMandatoryFields() GetAttributeAllResponseBuilder { |
| return b |
| } |
| |
| func (b *_GetAttributeAllResponseBuilder) WithOptionalAttributes(attributes CIPAttributes) GetAttributeAllResponseBuilder { |
| b.Attributes = attributes |
| return b |
| } |
| |
| func (b *_GetAttributeAllResponseBuilder) WithOptionalAttributesBuilder(builderSupplier func(CIPAttributesBuilder) CIPAttributesBuilder) GetAttributeAllResponseBuilder { |
| builder := builderSupplier(b.Attributes.CreateCIPAttributesBuilder()) |
| var err error |
| b.Attributes, err = builder.Build() |
| if err != nil { |
| b.collectedErr = append(b.collectedErr, errors.Wrap(err, "CIPAttributesBuilder failed")) |
| } |
| return b |
| } |
| |
| func (b *_GetAttributeAllResponseBuilder) Build() (GetAttributeAllResponse, error) { |
| if err := stdErrors.Join(b.collectedErr...); err != nil { |
| return nil, errors.Wrap(err, "error occurred during build") |
| } |
| return b._GetAttributeAllResponse.deepCopy(), nil |
| } |
| |
| func (b *_GetAttributeAllResponseBuilder) MustBuild() GetAttributeAllResponse { |
| build, err := b.Build() |
| if err != nil { |
| panic(err) |
| } |
| return build |
| } |
| |
| func (b *_GetAttributeAllResponseBuilder) Done() CipServiceResponseBuilder { |
| if b.parentBuilder == nil { |
| b.parentBuilder = NewCipServiceResponseBuilder().(*_CipServiceResponseBuilder) |
| } |
| return b.parentBuilder |
| } |
| |
| func (b *_GetAttributeAllResponseBuilder) buildForCipServiceResponse() (CipServiceResponse, error) { |
| return b.Build() |
| } |
| |
| func (b *_GetAttributeAllResponseBuilder) DeepCopy() any { |
| _copy := b.CreateGetAttributeAllResponseBuilder().(*_GetAttributeAllResponseBuilder) |
| if b.collectedErr != nil { |
| copy(_copy.collectedErr, b.collectedErr) |
| } |
| return _copy |
| } |
| |
| // CreateGetAttributeAllResponseBuilder creates a GetAttributeAllResponseBuilder |
| func (b *_GetAttributeAllResponse) CreateGetAttributeAllResponseBuilder() GetAttributeAllResponseBuilder { |
| if b == nil { |
| return NewGetAttributeAllResponseBuilder() |
| } |
| return &_GetAttributeAllResponseBuilder{_GetAttributeAllResponse: b.deepCopy()} |
| } |
| |
| /////////////////////// |
| /////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////// Accessors for discriminator values. |
| /////////////////////// |
| |
| func (m *_GetAttributeAllResponse) GetService() uint8 { |
| return 0x01 |
| } |
| |
| /////////////////////// |
| /////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| |
| func (m *_GetAttributeAllResponse) GetParent() CipServiceResponseContract { |
| return m.CipServiceResponseContract |
| } |
| |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////// Accessors for property fields. |
| /////////////////////// |
| |
| func (m *_GetAttributeAllResponse) GetAttributes() CIPAttributes { |
| return m.Attributes |
| } |
| |
| /////////////////////// |
| /////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| |
| // Deprecated: use the interface for direct cast |
| func CastGetAttributeAllResponse(structType any) GetAttributeAllResponse { |
| if casted, ok := structType.(GetAttributeAllResponse); ok { |
| return casted |
| } |
| if casted, ok := structType.(*GetAttributeAllResponse); ok { |
| return *casted |
| } |
| return nil |
| } |
| |
| func (m *_GetAttributeAllResponse) GetPlx4xTypeName() string { |
| return "GetAttributeAllResponse" |
| } |
| |
| func (m *_GetAttributeAllResponse) GetLengthInBits(ctx context.Context) uint64 { |
| lengthInBits := uint64(m.CipServiceResponseContract.(*_CipServiceResponse).getLengthInBits(ctx)) |
| |
| // Optional Field (attributes) |
| if m.Attributes != nil { |
| lengthInBits += m.Attributes.GetLengthInBits(ctx) |
| } |
| |
| return lengthInBits |
| } |
| |
| func (m *_GetAttributeAllResponse) GetLengthInBytes(ctx context.Context) uint64 { |
| return m.GetLengthInBits(ctx) / 8 |
| } |
| |
| func (m *_GetAttributeAllResponse) parse(ctx context.Context, readBuffer utils.ReadBuffer, parent *_CipServiceResponse, extStatusSize uint16, connected bool, serviceLen uint16) (__getAttributeAllResponse GetAttributeAllResponse, err error) { |
| m.CipServiceResponseContract = parent |
| parent._SubType = m |
| positionAware := readBuffer |
| _ = positionAware |
| if pullErr := readBuffer.PullContext("GetAttributeAllResponse"); pullErr != nil { |
| return nil, errors.Wrap(pullErr, "Error pulling for GetAttributeAllResponse") |
| } |
| currentPos := positionAware.GetPos() |
| _ = currentPos |
| |
| var attributes CIPAttributes |
| _attributes, err := ReadOptionalField[CIPAttributes](ctx, "attributes", ReadComplex[CIPAttributes](CIPAttributesParseWithBufferProducer((uint16)(uint16(uint16(serviceLen)-uint16(uint16(4)))-uint16((uint16(uint16(2))*uint16(extStatusSize))))), readBuffer), bool((((serviceLen)-(4))-((2)*(extStatusSize))) > (0))) |
| if err != nil { |
| return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'attributes' field")) |
| } |
| if _attributes != nil { |
| attributes = *_attributes |
| m.Attributes = attributes |
| } |
| |
| if closeErr := readBuffer.CloseContext("GetAttributeAllResponse"); closeErr != nil { |
| return nil, errors.Wrap(closeErr, "Error closing for GetAttributeAllResponse") |
| } |
| |
| return m, nil |
| } |
| |
| func (m *_GetAttributeAllResponse) 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 *_GetAttributeAllResponse) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error { |
| positionAware := writeBuffer |
| _ = positionAware |
| log := zerolog.Ctx(ctx) |
| _ = log |
| ser := func() error { |
| if pushErr := writeBuffer.PushContext("GetAttributeAllResponse"); pushErr != nil { |
| return errors.Wrap(pushErr, "Error pushing for GetAttributeAllResponse") |
| } |
| |
| if err := WriteOptionalField[CIPAttributes](ctx, "attributes", new(m.GetAttributes()), WriteComplex[CIPAttributes](writeBuffer), true); err != nil { |
| return errors.Wrap(err, "Error serializing 'attributes' field") |
| } |
| |
| if popErr := writeBuffer.PopContext("GetAttributeAllResponse"); popErr != nil { |
| return errors.Wrap(popErr, "Error popping for GetAttributeAllResponse") |
| } |
| return nil |
| } |
| return m.CipServiceResponseContract.(*_CipServiceResponse).serializeParent(ctx, writeBuffer, m, ser) |
| } |
| |
| func (m *_GetAttributeAllResponse) IsGetAttributeAllResponse() {} |
| |
| func (m *_GetAttributeAllResponse) DeepCopy() any { |
| return m.deepCopy() |
| } |
| |
| func (m *_GetAttributeAllResponse) deepCopy() *_GetAttributeAllResponse { |
| if m == nil { |
| return nil |
| } |
| _GetAttributeAllResponseCopy := &_GetAttributeAllResponse{ |
| m.CipServiceResponseContract.(*_CipServiceResponse).deepCopy(), |
| utils.DeepCopy[CIPAttributes](m.Attributes), |
| } |
| _GetAttributeAllResponseCopy.CipServiceResponseContract.(*_CipServiceResponse)._SubType = m |
| return _GetAttributeAllResponseCopy |
| } |
| |
| func (m *_GetAttributeAllResponse) 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() |
| } |