Skip to content

Commit

Permalink
Added DataHolder list methods to streams
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed Aug 31, 2023
1 parent dbb309e commit f03f668
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions stream_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataHolder> 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<DataHolder> 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{
Expand Down
11 changes: 11 additions & 0 deletions stream_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f03f668

Please sign in to comment.