package gnet

import (
	"context"
)

// PLCDataAccess 定义通用数据访问接口
type PLCDataAccess interface {
	// ReadData 读取数据
	ReadData(ctx context.Context, blockID, address, count int) ([]byte, error)
	// WriteData 写入数据
	WriteData(ctx context.Context, blockId, address, count int, buf []byte) error
	// GetProtocolName 返回协议名称
	GetProtocolName() string
}

type emptyPLCDataAccess struct{}

func (e emptyPLCDataAccess) ReadData(_ context.Context, _, _, _ int) ([]byte, error) {
	return nil, ErrUnconnected
}

func (e emptyPLCDataAccess) WriteData(_ context.Context, _, _, _ int, _ []byte) error {
	return ErrUnconnected
}

func (e emptyPLCDataAccess) GetProtocolName() string { return "unknown" }

var PLCDataAccessDiscard PLCDataAccess = &emptyPLCDataAccess{}
