blob: eb7ec6ea450f067a7c64b0c9af1c315c0c812882 [file] [log] [blame]
//
// 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
//
// http://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 (
"github.com/apache/plc4x/plc4go/internal/plc4go/spi/utils"
"github.com/pkg/errors"
)
// Code generated by build-utils. DO NOT EDIT.
// The data-structure of this message
type ModbusPDUDiagnosticRequest struct {
SubFunction uint16
Data uint16
Parent *ModbusPDU
}
// The corresponding interface
type IModbusPDUDiagnosticRequest interface {
LengthInBytes() uint16
LengthInBits() uint16
Serialize(writeBuffer utils.WriteBuffer) error
}
///////////////////////////////////////////////////////////
// Accessors for discriminator values.
///////////////////////////////////////////////////////////
func (m *ModbusPDUDiagnosticRequest) ErrorFlag() bool {
return false
}
func (m *ModbusPDUDiagnosticRequest) FunctionFlag() uint8 {
return 0x08
}
func (m *ModbusPDUDiagnosticRequest) Response() bool {
return false
}
func (m *ModbusPDUDiagnosticRequest) InitializeParent(parent *ModbusPDU) {
}
func NewModbusPDUDiagnosticRequest(subFunction uint16, data uint16) *ModbusPDU {
child := &ModbusPDUDiagnosticRequest{
SubFunction: subFunction,
Data: data,
Parent: NewModbusPDU(),
}
child.Parent.Child = child
return child.Parent
}
func CastModbusPDUDiagnosticRequest(structType interface{}) *ModbusPDUDiagnosticRequest {
castFunc := func(typ interface{}) *ModbusPDUDiagnosticRequest {
if casted, ok := typ.(ModbusPDUDiagnosticRequest); ok {
return &casted
}
if casted, ok := typ.(*ModbusPDUDiagnosticRequest); ok {
return casted
}
if casted, ok := typ.(ModbusPDU); ok {
return CastModbusPDUDiagnosticRequest(casted.Child)
}
if casted, ok := typ.(*ModbusPDU); ok {
return CastModbusPDUDiagnosticRequest(casted.Child)
}
return nil
}
return castFunc(structType)
}
func (m *ModbusPDUDiagnosticRequest) GetTypeName() string {
return "ModbusPDUDiagnosticRequest"
}
func (m *ModbusPDUDiagnosticRequest) LengthInBits() uint16 {
return m.LengthInBitsConditional(false)
}
func (m *ModbusPDUDiagnosticRequest) LengthInBitsConditional(lastItem bool) uint16 {
lengthInBits := uint16(m.Parent.ParentLengthInBits())
// Simple field (subFunction)
lengthInBits += 16
// Simple field (data)
lengthInBits += 16
return lengthInBits
}
func (m *ModbusPDUDiagnosticRequest) LengthInBytes() uint16 {
return m.LengthInBits() / 8
}
func ModbusPDUDiagnosticRequestParse(readBuffer utils.ReadBuffer) (*ModbusPDU, error) {
if pullErr := readBuffer.PullContext("ModbusPDUDiagnosticRequest"); pullErr != nil {
return nil, pullErr
}
// Simple Field (subFunction)
subFunction, _subFunctionErr := readBuffer.ReadUint16("subFunction", 16)
if _subFunctionErr != nil {
return nil, errors.Wrap(_subFunctionErr, "Error parsing 'subFunction' field")
}
// Simple Field (data)
data, _dataErr := readBuffer.ReadUint16("data", 16)
if _dataErr != nil {
return nil, errors.Wrap(_dataErr, "Error parsing 'data' field")
}
if closeErr := readBuffer.CloseContext("ModbusPDUDiagnosticRequest"); closeErr != nil {
return nil, closeErr
}
// Create a partially initialized instance
_child := &ModbusPDUDiagnosticRequest{
SubFunction: subFunction,
Data: data,
Parent: &ModbusPDU{},
}
_child.Parent.Child = _child
return _child.Parent, nil
}
func (m *ModbusPDUDiagnosticRequest) Serialize(writeBuffer utils.WriteBuffer) error {
ser := func() error {
if pushErr := writeBuffer.PushContext("ModbusPDUDiagnosticRequest"); pushErr != nil {
return pushErr
}
// Simple Field (subFunction)
subFunction := uint16(m.SubFunction)
_subFunctionErr := writeBuffer.WriteUint16("subFunction", 16, (subFunction))
if _subFunctionErr != nil {
return errors.Wrap(_subFunctionErr, "Error serializing 'subFunction' field")
}
// Simple Field (data)
data := uint16(m.Data)
_dataErr := writeBuffer.WriteUint16("data", 16, (data))
if _dataErr != nil {
return errors.Wrap(_dataErr, "Error serializing 'data' field")
}
if popErr := writeBuffer.PopContext("ModbusPDUDiagnosticRequest"); popErr != nil {
return popErr
}
return nil
}
return m.Parent.SerializeParent(writeBuffer, m, ser)
}
func (m *ModbusPDUDiagnosticRequest) String() string {
if m == nil {
return "<nil>"
}
buffer := utils.NewBoxedWriteBufferWithOptions(true, true)
m.Serialize(buffer)
return buffer.GetBox().String()
}