package gnet

import (
	"context"
)

// DataAccess 定义通用数据访问接口
type DataAccess 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 emptyDataAccess struct{}

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

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

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

var PLCDataAccessDiscard DataAccess = &emptyDataAccess{}
