| /* |
| * 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/errors" |
| "github.com/apache/plc4x/plc4go/spi/utils" |
| ) |
| |
| // Code generated by code-generation. DO NOT EDIT. |
| |
| // CipConnectionManagerResponse is the corresponding interface of CipConnectionManagerResponse |
| // CIP Vol 1, Section 3-5.5.2: Forward_Open. A rejected Forward_Open does not |
| // simply carry a status in the successful layout -- it replies in a shorter |
| // "unsuccessful" format, so the body has to be discriminated on the general |
| // status from the shared response header. |
| type CipConnectionManagerResponse interface { |
| CipConnectionManagerResponseContract |
| CipConnectionManagerResponseRequirements |
| fmt.Stringer |
| utils.LengthAware |
| utils.Serializable |
| utils.Copyable |
| // IsCipConnectionManagerResponse is a marker method to prevent unintentional type checks (interfaces of same signature) |
| IsCipConnectionManagerResponse() |
| // CreateBuilder creates a CipConnectionManagerResponseBuilder |
| CreateCipConnectionManagerResponseBuilder() CipConnectionManagerResponseBuilder |
| } |
| |
| // CipConnectionManagerResponseContract provides a set of functions which can be overwritten by a sub struct |
| type CipConnectionManagerResponseContract interface { |
| CipServiceResponseContract |
| // GetService returns Service (discriminator field) |
| GetService() uint8 |
| // IsCipConnectionManagerResponse is a marker method to prevent unintentional type checks (interfaces of same signature) |
| IsCipConnectionManagerResponse() |
| // CreateBuilder creates a CipConnectionManagerResponseBuilder |
| CreateCipConnectionManagerResponseBuilder() CipConnectionManagerResponseBuilder |
| } |
| |
| // CipConnectionManagerResponseRequirements provides a set of functions which need to be implemented by a sub struct |
| type CipConnectionManagerResponseRequirements interface { |
| CipServiceResponseRequirements |
| GetLengthInBits(ctx context.Context) uint64 |
| GetLengthInBytes(ctx context.Context) uint64 |
| } |
| |
| // _CipConnectionManagerResponse is the data-structure of this message |
| type _CipConnectionManagerResponse struct { |
| CipServiceResponseContract |
| _SubType interface { |
| CipConnectionManagerResponseContract |
| CipConnectionManagerResponseRequirements |
| } |
| } |
| |
| var _ CipConnectionManagerResponseContract = (*_CipConnectionManagerResponse)(nil) |
| |
| // NewCipConnectionManagerResponse factory function for _CipConnectionManagerResponse |
| func NewCipConnectionManagerResponse(status uint8, extStatus []uint16) *_CipConnectionManagerResponse { |
| _result := &_CipConnectionManagerResponse{ |
| CipServiceResponseContract: NewCipServiceResponse(status, extStatus), |
| } |
| _result.CipServiceResponseContract.(*_CipServiceResponse)._SubType = _result._SubType |
| return _result |
| } |
| |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////// Builder |
| /////////////////////// |
| |
| // CipConnectionManagerResponseBuilder is a builder for CipConnectionManagerResponse |
| type CipConnectionManagerResponseBuilder interface { |
| utils.Copyable |
| // WithMandatoryFields adds all mandatory fields (convenience for using multiple builder calls) |
| WithMandatoryFields() CipConnectionManagerResponseBuilder |
| // AsCipConnectionManagerResponseSuccess converts this build to a subType of CipConnectionManagerResponse. It is always possible to return to current builder using Done() |
| AsCipConnectionManagerResponseSuccess() CipConnectionManagerResponseSuccessBuilder |
| // AsCipConnectionManagerResponseFailure converts this build to a subType of CipConnectionManagerResponse. It is always possible to return to current builder using Done() |
| AsCipConnectionManagerResponseFailure() CipConnectionManagerResponseFailureBuilder |
| // Build builds the CipConnectionManagerResponse or returns an error if something is wrong |
| PartialBuild() (CipConnectionManagerResponseContract, error) |
| // MustBuild does the same as Build but panics on error |
| PartialMustBuild() CipConnectionManagerResponseContract |
| // 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 CipConnectionManagerResponse or returns an error if something is wrong |
| Build() (CipConnectionManagerResponse, error) |
| // MustBuild does the same as Build but panics on error |
| MustBuild() CipConnectionManagerResponse |
| } |
| |
| // NewCipConnectionManagerResponseBuilder() creates a CipConnectionManagerResponseBuilder |
| func NewCipConnectionManagerResponseBuilder() CipConnectionManagerResponseBuilder { |
| return &_CipConnectionManagerResponseBuilder{_CipConnectionManagerResponse: new(_CipConnectionManagerResponse)} |
| } |
| |
| type _CipConnectionManagerResponseChildBuilder interface { |
| utils.Copyable |
| setParent(CipConnectionManagerResponseContract) |
| buildForCipConnectionManagerResponse() (CipConnectionManagerResponse, error) |
| } |
| |
| type _CipConnectionManagerResponseBuilder struct { |
| *_CipConnectionManagerResponse |
| |
| parentBuilder *_CipServiceResponseBuilder |
| |
| childBuilder _CipConnectionManagerResponseChildBuilder |
| |
| collectedErr []error |
| } |
| |
| var _ (CipConnectionManagerResponseBuilder) = (*_CipConnectionManagerResponseBuilder)(nil) |
| |
| func (b *_CipConnectionManagerResponseBuilder) setParent(contract CipServiceResponseContract) { |
| b.CipServiceResponseContract = contract |
| contract.(*_CipServiceResponse)._SubType = b._CipConnectionManagerResponse |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) WithMandatoryFields() CipConnectionManagerResponseBuilder { |
| return b |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) PartialBuild() (CipConnectionManagerResponseContract, error) { |
| if err := stdErrors.Join(b.collectedErr...); err != nil { |
| return nil, errors.Wrap(err, "error occurred during build") |
| } |
| return b._CipConnectionManagerResponse.deepCopy(), nil |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) PartialMustBuild() CipConnectionManagerResponseContract { |
| build, err := b.PartialBuild() |
| if err != nil { |
| panic(err) |
| } |
| return build |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) AsCipConnectionManagerResponseSuccess() CipConnectionManagerResponseSuccessBuilder { |
| if cb, ok := b.childBuilder.(CipConnectionManagerResponseSuccessBuilder); ok { |
| return cb |
| } |
| cb := NewCipConnectionManagerResponseSuccessBuilder().(*_CipConnectionManagerResponseSuccessBuilder) |
| cb.parentBuilder = b |
| b.childBuilder = cb |
| return cb |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) AsCipConnectionManagerResponseFailure() CipConnectionManagerResponseFailureBuilder { |
| if cb, ok := b.childBuilder.(CipConnectionManagerResponseFailureBuilder); ok { |
| return cb |
| } |
| cb := NewCipConnectionManagerResponseFailureBuilder().(*_CipConnectionManagerResponseFailureBuilder) |
| cb.parentBuilder = b |
| b.childBuilder = cb |
| return cb |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) Done() CipServiceResponseBuilder { |
| if b.parentBuilder == nil { |
| b.parentBuilder = NewCipServiceResponseBuilder().(*_CipServiceResponseBuilder) |
| } |
| return b.parentBuilder |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) buildForCipServiceResponse() (CipServiceResponse, error) { |
| return b.Build() |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) Build() (CipConnectionManagerResponse, error) { |
| v, err := b.PartialBuild() |
| if err != nil { |
| return nil, errors.Wrap(err, "error occurred during partial build") |
| } |
| if b.childBuilder == nil { |
| return nil, errors.New("no child builder present") |
| } |
| b.childBuilder.setParent(v) |
| return b.childBuilder.buildForCipConnectionManagerResponse() |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) MustBuild() CipConnectionManagerResponse { |
| build, err := b.Build() |
| if err != nil { |
| panic(err) |
| } |
| return build |
| } |
| |
| func (b *_CipConnectionManagerResponseBuilder) DeepCopy() any { |
| _copy := b.CreateCipConnectionManagerResponseBuilder().(*_CipConnectionManagerResponseBuilder) |
| _copy.childBuilder = b.childBuilder.DeepCopy().(_CipConnectionManagerResponseChildBuilder) |
| _copy.childBuilder.setParent(_copy) |
| if b.collectedErr != nil { |
| copy(_copy.collectedErr, b.collectedErr) |
| } |
| return _copy |
| } |
| |
| // CreateCipConnectionManagerResponseBuilder creates a CipConnectionManagerResponseBuilder |
| func (b *_CipConnectionManagerResponse) CreateCipConnectionManagerResponseBuilder() CipConnectionManagerResponseBuilder { |
| if b == nil { |
| return NewCipConnectionManagerResponseBuilder() |
| } |
| return &_CipConnectionManagerResponseBuilder{_CipConnectionManagerResponse: b.deepCopy()} |
| } |
| |
| /////////////////////// |
| /////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////// Accessors for discriminator values. |
| /////////////////////// |
| |
| func (m *_CipConnectionManagerResponse) GetService() uint8 { |
| return 0x5B |
| } |
| |
| /////////////////////// |
| /////////////////////// |
| /////////////////////////////////////////////////////////// |
| /////////////////////////////////////////////////////////// |
| |
| // Deprecated: use the interface for direct cast |
| func CastCipConnectionManagerResponse(structType any) CipConnectionManagerResponse { |
| if casted, ok := structType.(CipConnectionManagerResponse); ok { |
| return casted |
| } |
| if casted, ok := structType.(*CipConnectionManagerResponse); ok { |
| return *casted |
| } |
| return nil |
| } |
| |
| func (m *_CipConnectionManagerResponse) GetPlx4xTypeName() string { |
| return "CipConnectionManagerResponse" |
| } |
| |
| func (m *_CipConnectionManagerResponse) getLengthInBits(ctx context.Context) uint64 { |
| lengthInBits := uint64(m.CipServiceResponseContract.(*_CipServiceResponse).getLengthInBits(ctx)) |
| |
| return lengthInBits |
| } |
| |
| func (m *_CipConnectionManagerResponse) GetLengthInBits(ctx context.Context) uint64 { |
| return m._SubType.GetLengthInBits(ctx) |
| } |
| |
| func (m *_CipConnectionManagerResponse) GetLengthInBytes(ctx context.Context) uint64 { |
| return m._SubType.GetLengthInBits(ctx) / 8 |
| } |
| |
| func (m *_CipConnectionManagerResponse) parse(ctx context.Context, readBuffer utils.ReadBuffer, parent *_CipServiceResponse, status uint8, connected bool, serviceLen uint16) (__cipConnectionManagerResponse CipConnectionManagerResponse, err error) { |
| m.CipServiceResponseContract = parent |
| positionAware := readBuffer |
| _ = positionAware |
| if pullErr := readBuffer.PullContext("CipConnectionManagerResponse"); pullErr != nil { |
| return nil, errors.Wrap(pullErr, "Error pulling for CipConnectionManagerResponse") |
| } |
| currentPos := positionAware.GetPos() |
| _ = currentPos |
| |
| // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) |
| var _child CipConnectionManagerResponse |
| switch { |
| case status == 0x00: // CipConnectionManagerResponseSuccess |
| if _child, err = new(_CipConnectionManagerResponseSuccess).parse(ctx, readBuffer, m, uint8(status), connected, uint16(serviceLen)); err != nil { |
| return nil, errors.Wrap(err, "Error parsing sub-type CipConnectionManagerResponseSuccess for type-switch of CipConnectionManagerResponse") |
| } |
| case true: // CipConnectionManagerResponseFailure |
| if _child, err = new(_CipConnectionManagerResponseFailure).parse(ctx, readBuffer, m, uint8(status), connected, uint16(serviceLen)); err != nil { |
| return nil, errors.Wrap(err, "Error parsing sub-type CipConnectionManagerResponseFailure for type-switch of CipConnectionManagerResponse") |
| } |
| default: |
| return nil, errors.Errorf("Unmapped type for parameters [status=%v]", status) |
| } |
| |
| if closeErr := readBuffer.CloseContext("CipConnectionManagerResponse"); closeErr != nil { |
| return nil, errors.Wrap(closeErr, "Error closing for CipConnectionManagerResponse") |
| } |
| |
| parent._SubType = _child |
| return _child, nil |
| } |
| |
| func (pm *_CipConnectionManagerResponse) serializeParent(ctx context.Context, writeBuffer utils.WriteBuffer, child CipConnectionManagerResponse, serializeChildFunction func() error) error { |
| // We redirect all calls through client as some methods are only implemented there |
| m := child |
| _ = m |
| positionAware := writeBuffer |
| _ = positionAware |
| log := zerolog.Ctx(ctx) |
| _ = log |
| ser := func() error { |
| if pushErr := writeBuffer.PushContext("CipConnectionManagerResponse"); pushErr != nil { |
| return errors.Wrap(pushErr, "Error pushing for CipConnectionManagerResponse") |
| } |
| |
| // Switch field (Depending on the discriminator values, passes the serialization to a sub-type) |
| if _typeSwitchErr := serializeChildFunction(); _typeSwitchErr != nil { |
| return errors.Wrap(_typeSwitchErr, "Error serializing sub-type field") |
| } |
| |
| if popErr := writeBuffer.PopContext("CipConnectionManagerResponse"); popErr != nil { |
| return errors.Wrap(popErr, "Error popping for CipConnectionManagerResponse") |
| } |
| return nil |
| } |
| return pm.CipServiceResponseContract.(*_CipServiceResponse).serializeParent(ctx, writeBuffer, m, ser) |
| } |
| |
| func (m *_CipConnectionManagerResponse) IsCipConnectionManagerResponse() {} |
| |
| func (m *_CipConnectionManagerResponse) DeepCopy() any { |
| return m.deepCopy() |
| } |
| |
| func (m *_CipConnectionManagerResponse) deepCopy() *_CipConnectionManagerResponse { |
| if m == nil { |
| return nil |
| } |
| _CipConnectionManagerResponseCopy := &_CipConnectionManagerResponse{ |
| m.CipServiceResponseContract.(*_CipServiceResponse).deepCopy(), |
| nil, // will be set by child |
| } |
| _CipConnectionManagerResponseCopy.CipServiceResponseContract.(*_CipServiceResponse)._SubType = m |
| return _CipConnectionManagerResponseCopy |
| } |