mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-08-21 23:19:14 +00:00
add most basic error handling on the decode side
This commit is contained in:
@@ -15,8 +15,13 @@ type DataPacketChunk struct {
|
||||
Data DataPacketChunkData
|
||||
}
|
||||
|
||||
func DecodeDataPacketChunk(bytes []byte) DataPacketChunk {
|
||||
chunk := DecodeChunk(bytes)
|
||||
func DecodeDataPacketChunk(bytes []byte) (DataPacketChunk, error) {
|
||||
chunk, err := DecodeChunk(bytes)
|
||||
|
||||
if err != nil {
|
||||
return DataPacketChunk{}, err
|
||||
}
|
||||
|
||||
data := DataPacketChunkData{}
|
||||
|
||||
if chunk.Header.HasSubchunks && chunk.ChunkData != nil && chunk.Header.DataLen > 0 {
|
||||
@@ -25,14 +30,20 @@ func DecodeDataPacketChunk(bytes []byte) DataPacketChunk {
|
||||
for offset < int(chunk.Header.DataLen) {
|
||||
switch id := binary.LittleEndian.Uint16(chunk.ChunkData[offset : offset+2]); id {
|
||||
case 0x0000:
|
||||
packet_header := DecodePacketHeaderChunk(chunk.ChunkData[offset:])
|
||||
packet_header, err := DecodePacketHeaderChunk(chunk.ChunkData[offset:])
|
||||
if err != nil {
|
||||
return DataPacketChunk{}, err
|
||||
}
|
||||
data.PacketHeader = &packet_header
|
||||
offset += 4
|
||||
if packet_header.Chunk.Header.DataLen > 0 {
|
||||
offset = offset + int(packet_header.Chunk.Header.DataLen)
|
||||
}
|
||||
case 0x0001:
|
||||
tracker_list := DecodeDataTrackerListChunk(chunk.ChunkData[offset:])
|
||||
tracker_list, err := DecodeDataTrackerListChunk(chunk.ChunkData[offset:])
|
||||
if err != nil {
|
||||
return DataPacketChunk{}, err
|
||||
}
|
||||
data.TrackerList = &tracker_list
|
||||
offset += 4
|
||||
if tracker_list.Chunk.Header.DataLen > 0 {
|
||||
@@ -46,7 +57,8 @@ func DecodeDataPacketChunk(bytes []byte) DataPacketChunk {
|
||||
}
|
||||
|
||||
return DataPacketChunk{
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
}
|
||||
Chunk: chunk,
|
||||
Data: data,
|
||||
},
|
||||
nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user