Skip to content

Commit

Permalink
Added type check to DataHolder reading
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed Apr 11, 2023
1 parent d65b2f2 commit 8fe373c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nex

import (
"errors"
"fmt"
"reflect"
"strings"
"time"
Expand Down Expand Up @@ -92,7 +94,14 @@ func (dataHolder *DataHolder) ExtractFromStream(stream *StreamIn) error {
dataHolder.length1 = stream.ReadUInt32LE()
dataHolder.length2 = stream.ReadUInt32LE()

newObjectInstance := reflect.New(reflect.TypeOf(dataHolderKnownObjects[dataHolder.typeName]).Elem()).Interface().(StructureInterface)
dataType := dataHolderKnownObjects[dataHolder.typeName]
if dataType == nil {
message := fmt.Sprintf("UNKNOWN DATAHOLDER TYPE: %s", dataHolder.typeName)
logger.Critical(message)
return errors.New(message)
}

newObjectInstance := reflect.New(reflect.TypeOf(dataType).Elem()).Interface().(StructureInterface)

dataHolder.objectData, _ = stream.ReadStructure(newObjectInstance)

Expand Down

0 comments on commit 8fe373c

Please sign in to comment.