This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 0bdf79e plc4go: readBuffer moved methods related to byte base
operation into own interface
0bdf79e is described below
commit 0bdf79eccc6221d57097c8324ed26254154e4cf9
Author: Sebastian Rühl <[email protected]>
AuthorDate: Mon Apr 19 17:50:08 2021 +0200
plc4go: readBuffer moved methods related to byte base operation into own
interface
---
plc4go/internal/plc4go/spi/utils/ReadBuffer.go | 6 +-----
plc4go/internal/plc4go/spi/utils/ReadBufferByteBased.go | 12 ++++++++++--
plc4go/internal/plc4go/spi/utils/ReadBufferXmlBased.go | 16 ----------------
plc4go/internal/plc4go/spi/values/RawPlcValue.go | 10 +++++-----
4 files changed, 16 insertions(+), 28 deletions(-)
diff --git a/plc4go/internal/plc4go/spi/utils/ReadBuffer.go
b/plc4go/internal/plc4go/spi/utils/ReadBuffer.go
index 2979dd6..0ebb3a3 100644
--- a/plc4go/internal/plc4go/spi/utils/ReadBuffer.go
+++ b/plc4go/internal/plc4go/spi/utils/ReadBuffer.go
@@ -24,12 +24,8 @@ import (
)
type ReadBuffer interface {
- Reset()
GetPos() uint16
- GetBytes() []uint8
- GetTotalBytes() uint64
HasMore(bitLength uint8) bool
- PeekByte(offset uint8) uint8
PullContext(logicalName string, readerArgs ...WithReaderArgs) error
ReadBit(logicalName string, readerArgs ...WithReaderArgs) (bool, error)
ReadUint8(logicalName string, bitLength uint8, readerArgs
...WithReaderArgs) (uint8, error)
@@ -42,7 +38,7 @@ type ReadBuffer interface {
ReadInt64(logicalName string, bitLength uint8, readerArgs
...WithReaderArgs) (int64, error)
ReadBigInt(logicalName string, bitLength uint64, readerArgs
...WithReaderArgs) (*big.Int, error)
ReadFloat32(logicalName string, signed bool, exponentBitLength uint8,
mantissaBitLength uint8, readerArgs ...WithReaderArgs) (float32, error)
- ReadFloat64(logicalName string, _ bool, exponentBitLength uint8,
mantissaBitLength uint8, readerArgs ...WithReaderArgs) (float64, error)
+ ReadFloat64(logicalName string, singed bool, exponentBitLength uint8,
mantissaBitLength uint8, readerArgs ...WithReaderArgs) (float64, error)
ReadBigFloat(logicalName string, signed bool, exponentBitLength uint8,
mantissaBitLength uint8, readerArgs ...WithReaderArgs) (*big.Float, error)
ReadString(logicalName string, bitLength uint32, readerArgs
...WithReaderArgs) (string, error)
CloseContext(logicalName string, readerArgs ...WithReaderArgs) error
diff --git a/plc4go/internal/plc4go/spi/utils/ReadBufferByteBased.go
b/plc4go/internal/plc4go/spi/utils/ReadBufferByteBased.go
index 6995536..79f52fd 100644
--- a/plc4go/internal/plc4go/spi/utils/ReadBufferByteBased.go
+++ b/plc4go/internal/plc4go/spi/utils/ReadBufferByteBased.go
@@ -28,7 +28,15 @@ import (
"math/big"
)
-func NewReadBuffer(data []uint8) ReadBuffer {
+type ReadBufferByteBased interface {
+ ReadBuffer
+ Reset()
+ GetBytes() []uint8
+ GetTotalBytes() uint64
+ PeekByte(offset uint8) uint8
+}
+
+func NewReadBuffer(data []uint8) ReadBufferByteBased {
buffer := bytes.NewBuffer(data)
reader := bitio.NewReader(buffer)
return &byteReadBuffer{
@@ -39,7 +47,7 @@ func NewReadBuffer(data []uint8) ReadBuffer {
}
}
-func NewLittleEndianReadBuffer(data []uint8) ReadBuffer {
+func NewLittleEndianReadBuffer(data []uint8) ReadBufferByteBased {
buffer := bytes.NewBuffer(data)
reader := bitio.NewReader(buffer)
return &byteReadBuffer{
diff --git a/plc4go/internal/plc4go/spi/utils/ReadBufferXmlBased.go
b/plc4go/internal/plc4go/spi/utils/ReadBufferXmlBased.go
index d439b11..2757976 100644
--- a/plc4go/internal/plc4go/spi/utils/ReadBufferXmlBased.go
+++ b/plc4go/internal/plc4go/spi/utils/ReadBufferXmlBased.go
@@ -51,30 +51,14 @@ type xmlReadBuffer struct {
///////////////////////////////////////
///////////////////////////////////////
-func (x *xmlReadBuffer) Reset() {
- panic("implement me")
-}
-
func (x *xmlReadBuffer) GetPos() uint16 {
return uint16(x.pos / 8)
}
-func (x *xmlReadBuffer) GetBytes() []uint8 {
- panic("implement me")
-}
-
-func (x *xmlReadBuffer) GetTotalBytes() uint64 {
- panic("implement me")
-}
-
func (x *xmlReadBuffer) HasMore(bitLength uint8) bool {
return true
}
-func (x *xmlReadBuffer) PeekByte(offset uint8) uint8 {
- panic("implement me")
-}
-
func (x *xmlReadBuffer) PullContext(logicalName string, readerArgs
...WithReaderArgs) error {
startElement, err := x.travelToNextStartElement()
if err != nil {
diff --git a/plc4go/internal/plc4go/spi/values/RawPlcValue.go
b/plc4go/internal/plc4go/spi/values/RawPlcValue.go
index fa7d71e..87a4313 100644
--- a/plc4go/internal/plc4go/spi/values/RawPlcValue.go
+++ b/plc4go/internal/plc4go/spi/values/RawPlcValue.go
@@ -43,7 +43,7 @@ func NewRawPlcValue(readBuffer utils.ReadBuffer, decoder
PlcValueDecoder) RawPlc
}
func (m RawPlcValue) GetRaw() []byte {
- return m.readBuffer.GetBytes()
+ return m.readBuffer.(utils.ReadBufferByteBased).GetBytes()
}
func (m RawPlcValue) IsList() bool {
@@ -51,16 +51,16 @@ func (m RawPlcValue) IsList() bool {
}
func (m RawPlcValue) GetLength() uint32 {
- return uint32(m.readBuffer.GetTotalBytes())
+ return uint32(m.readBuffer.(utils.ReadBufferByteBased).GetTotalBytes())
}
func (m RawPlcValue) GetIndex(i uint32) api.PlcValue {
- return NewPlcUSINT(m.readBuffer.GetBytes()[i])
+ return
NewPlcUSINT(m.readBuffer.(utils.ReadBufferByteBased).GetBytes()[i])
}
func (m RawPlcValue) GetList() []api.PlcValue {
var plcValues []api.PlcValue
- for _, value := range m.readBuffer.GetBytes() {
+ for _, value := range
m.readBuffer.(utils.ReadBufferByteBased).GetBytes() {
plcValues = append(plcValues, NewPlcUSINT(value))
}
return plcValues
@@ -75,7 +75,7 @@ func (m RawPlcValue) RawHasMore() bool {
}
func (m RawPlcValue) RawReset() {
- m.readBuffer.Reset()
+ m.readBuffer.(utils.ReadBufferByteBased).Reset()
}
func (m RawPlcValue) MarshalXML(e *xml.Encoder, start xml.StartElement) error {