blob: 2c6eed85fbb4414eb6222ac45cb386e23894d515 [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/errors"
"github.com/apache/plc4x/plc4go/spi/utils"
)
// Code generated by code-generation. DO NOT EDIT.
// AdsString is the corresponding interface of AdsString
type AdsString interface {
fmt.Stringer
utils.LengthAware
utils.Serializable
utils.Copyable
// GetStringValue returns StringValue (property field)
GetStringValue() string
// IsAdsString is a marker method to prevent unintentional type checks (interfaces of same signature)
IsAdsString()
// CreateBuilder creates a AdsStringBuilder
CreateAdsStringBuilder() AdsStringBuilder
}
// _AdsString is the data-structure of this message
type _AdsString struct {
StringValue string
}
var _ AdsString = (*_AdsString)(nil)
// NewAdsString factory function for _AdsString
func NewAdsString(stringValue string) *_AdsString {
return &_AdsString{StringValue: stringValue}
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
/////////////////////// Builder
///////////////////////
// AdsStringBuilder is a builder for AdsString
type AdsStringBuilder interface {
utils.Copyable
// WithMandatoryFields adds all mandatory fields (convenience for using multiple builder calls)
WithMandatoryFields(stringValue string) AdsStringBuilder
// WithStringValue adds StringValue (property field)
WithStringValue(string) AdsStringBuilder
// Build builds the AdsString or returns an error if something is wrong
Build() (AdsString, error)
// MustBuild does the same as Build but panics on error
MustBuild() AdsString
}
// NewAdsStringBuilder() creates a AdsStringBuilder
func NewAdsStringBuilder() AdsStringBuilder {
return &_AdsStringBuilder{_AdsString: new(_AdsString)}
}
type _AdsStringBuilder struct {
*_AdsString
collectedErr []error
}
var _ (AdsStringBuilder) = (*_AdsStringBuilder)(nil)
func (b *_AdsStringBuilder) WithMandatoryFields(stringValue string) AdsStringBuilder {
return b.WithStringValue(stringValue)
}
func (b *_AdsStringBuilder) WithStringValue(stringValue string) AdsStringBuilder {
b.StringValue = stringValue
return b
}
func (b *_AdsStringBuilder) Build() (AdsString, error) {
if err := stdErrors.Join(b.collectedErr...); err != nil {
return nil, errors.Wrap(err, "error occurred during build")
}
return b._AdsString.deepCopy(), nil
}
func (b *_AdsStringBuilder) MustBuild() AdsString {
build, err := b.Build()
if err != nil {
panic(err)
}
return build
}
func (b *_AdsStringBuilder) DeepCopy() any {
_copy := b.CreateAdsStringBuilder().(*_AdsStringBuilder)
if b.collectedErr != nil {
copy(_copy.collectedErr, b.collectedErr)
}
return _copy
}
// CreateAdsStringBuilder creates a AdsStringBuilder
func (b *_AdsString) CreateAdsStringBuilder() AdsStringBuilder {
if b == nil {
return NewAdsStringBuilder()
}
return &_AdsStringBuilder{_AdsString: b.deepCopy()}
}
///////////////////////
///////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
/////////////////////// Accessors for property fields.
///////////////////////
func (m *_AdsString) GetStringValue() string {
return m.StringValue
}
///////////////////////
///////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Deprecated: use the interface for direct cast
func CastAdsString(structType any) AdsString {
if casted, ok := structType.(AdsString); ok {
return casted
}
if casted, ok := structType.(*AdsString); ok {
return *casted
}
return nil
}
func (m *_AdsString) GetPlx4xTypeName() string {
return "AdsString"
}
func (m *_AdsString) GetLengthInBits(ctx context.Context) uint16 {
lengthInBits := uint16(0)
// Manual Field (stringValue)
lengthInBits += uint16(LengthZeroTerminatedString(ctx, m.GetStringValue()))
return lengthInBits
}
func (m *_AdsString) GetLengthInBytes(ctx context.Context) uint16 {
return m.GetLengthInBits(ctx) / 8
}
func AdsStringParse(ctx context.Context, theBytes []byte, stringLength uint16) (AdsString, error) {
return AdsStringParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), stringLength)
}
func AdsStringParseWithBufferProducer(stringLength uint16) func(ctx context.Context, readBuffer utils.ReadBuffer) (AdsString, error) {
return func(ctx context.Context, readBuffer utils.ReadBuffer) (AdsString, error) {
return AdsStringParseWithBuffer(ctx, readBuffer, stringLength)
}
}
func AdsStringParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, stringLength uint16) (AdsString, error) {
v, err := (new(_AdsString)).parse(ctx, readBuffer, stringLength)
if err != nil {
return nil, err
}
return v, nil
}
func (m *_AdsString) parse(ctx context.Context, readBuffer utils.ReadBuffer, stringLength uint16) (__adsString AdsString, err error) {
positionAware := readBuffer
_ = positionAware
if pullErr := readBuffer.PullContext("AdsString"); pullErr != nil {
return nil, errors.Wrap(pullErr, "Error pulling for AdsString")
}
currentPos := positionAware.GetPos()
_ = currentPos
stringValue, err := ReadManualField[string](ctx, "stringValue", readBuffer, EnsureType[string](ParseZeroTerminatedString(ctx, readBuffer, stringLength)))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'stringValue' field"))
}
m.StringValue = stringValue
if closeErr := readBuffer.CloseContext("AdsString"); closeErr != nil {
return nil, errors.Wrap(closeErr, "Error closing for AdsString")
}
return m, nil
}
func (m *_AdsString) 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 *_AdsString) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error {
positionAware := writeBuffer
_ = positionAware
log := zerolog.Ctx(ctx)
_ = log
if pushErr := writeBuffer.PushContext("AdsString"); pushErr != nil {
return errors.Wrap(pushErr, "Error pushing for AdsString")
}
if err := WriteManualField[string](ctx, "stringValue", func(ctx context.Context) error {
return SerializeZeroTerminatedString(ctx, writeBuffer, m.GetStringValue())
}, writeBuffer); err != nil {
return errors.Wrap(err, "Error serializing 'stringValue' field")
}
if popErr := writeBuffer.PopContext("AdsString"); popErr != nil {
return errors.Wrap(popErr, "Error popping for AdsString")
}
return nil
}
func (m *_AdsString) IsAdsString() {}
func (m *_AdsString) DeepCopy() any {
return m.deepCopy()
}
func (m *_AdsString) deepCopy() *_AdsString {
if m == nil {
return nil
}
_AdsStringCopy := &_AdsString{
m.StringValue,
}
return _AdsStringCopy
}
func (m *_AdsString) 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()
}