From f03f66853c7948f5eb396c46b450db609f0c3a85 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Thu, 31 Aug 2023 00:47:27 -0400 Subject: [PATCH] Added DataHolder list methods to streams --- stream_in.go | 21 +++++++++++++++++++++ stream_out.go | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/stream_in.go b/stream_in.go index 122b2c3b..046bdafe 100644 --- a/stream_in.go +++ b/stream_in.go @@ -924,6 +924,27 @@ func (stream *StreamIn) ReadListStructure(structure StructureInterface) (interfa return structureSlice.Interface(), nil } +// ReadListDataHolder reads a list of NEX DataHolder types +func (stream *StreamIn) ReadListDataHolder() ([]*DataHolder, error) { + length, err := stream.ReadUInt32LE() + if err != nil { + return nil, fmt.Errorf("Failed to read List length. %s", err.Error()) + } + + list := make([]*DataHolder, 0, length) + + for i := 0; i < int(length); i++ { + value, err := stream.ReadDataHolder() + if err != nil { + return nil, fmt.Errorf("Failed to read List value at index %d. %s", i, err.Error()) + } + + list = append(list, value) + } + + return list, nil +} + // NewStreamIn returns a new NEX input stream func NewStreamIn(data []byte, server *Server) *StreamIn { return &StreamIn{ diff --git a/stream_out.go b/stream_out.go index 4425e2c2..cf1ee05d 100644 --- a/stream_out.go +++ b/stream_out.go @@ -421,6 +421,17 @@ func (stream *StreamOut) WriteListStationURL(stationURLs []*StationURL) { } } +// WriteListDataHolder writes a NEX DataHolder type +func (stream *StreamOut) WriteListDataHolder(dataholders []*DataHolder) { + length := len(dataholders) + + stream.WriteUInt32LE(uint32(length)) + + for i := 0; i < length; i++ { + stream.WriteDataHolder(dataholders[i]) + } +} + // WriteDataHolder writes a NEX DataHolder type func (stream *StreamOut) WriteDataHolder(dataholder *DataHolder) { content := dataholder.Bytes(NewStreamOut(stream.Server))