Files
gobngsdk/reader_socket.go
esilva 312d979be1 added some new API calls
mainly around getting the file size and data read for convenience for
other tools
2026-09-16 23:47:35 +01:00

54 lines
980 B
Go

package bngsdk
import (
"errors"
)
type OgUDPReader struct {
udpConnection *UDPTransport
}
var ErrInvalidOutgaugeData = errors.New("data is of different size than outgauge")
func NewOgUDPReader(ip string, port int) (*OgUDPReader, error) {
conn, err := NewUDPReader(ip, port)
if err != nil {
return nil, err
}
return &OgUDPReader{
udpConnection: conn,
}, nil
}
func (ogr *OgUDPReader) Close() error {
if ogr.udpConnection != nil {
return ogr.udpConnection.Close()
}
return nil
}
func (ogr *OgUDPReader) Reset() error {
// NOTE: what to implement here?
return nil
}
func (ogr *OgUDPReader) Next(buffer []byte) (int, error) {
nBytes, err := ogr.udpConnection.Read(buffer)
if err != nil {
return 0, err
}
// Check if enough data was received to fill our struct
if int64(nBytes) != OutgaugeSize {
return 0, ErrInvalidOutgaugeData
}
return nBytes, nil
}
func (ogr *OgUDPReader) GetTotalRead() int64 {
return ogr.udpConnection.GetTotalBytes()
}