50 lines
881 B
Go
50 lines
881 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 nBytes != outgaugeSize {
|
|
return 0, ErrInvalidOutgaugeData
|
|
}
|
|
|
|
return nBytes, nil
|
|
}
|