Skip to content

Commit

Permalink
Skip over corsaro tags when returning initial packet string for rsdos
Browse files Browse the repository at this point in the history
Also added a getRsdosPacketSize() method that accounts for any
tag header that may be present.
  • Loading branch information
salcock committed May 2, 2021
1 parent f42b805 commit 472e826
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/pyavro_stardust/rsdos.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ cdef class AvroRsdos(AvroRecord):
cpdef void setSchemaVersion(self, const unsigned int schemaversion)
cpdef void resetRecord(self)
cpdef bytes getRsdosPacketString(self)
cpdef unsigned int getRsdosPacketSize(self)
cpdef int setRsdosPacketString(self, const unsigned char[:] buf,
const unsigned int maxlen)

Expand Down
34 changes: 31 additions & 3 deletions src/pyavro_stardust/rsdos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ cdef class AvroRsdos(AvroRecord):
self.attributes_l[<int>ATTR_RSDOS_PACKET_CNT],
self.attributes_l[<int>ATTR_RSDOS_BYTE_CNT],
self.attributes_l[<int>ATTR_RSDOS_MAX_PPM_INTERVAL],
self.pktcontentlen)
self.getRsdosPacketSize())

cpdef dict asDict(self):
cdef dict result

if self.pktcontentlen == 0:
if self.getRsdosPacketSize() == 0:
initpkt = None
else:
initpkt = self.getRsdosPacketString()
Expand Down Expand Up @@ -106,13 +106,41 @@ cdef class AvroRsdos(AvroRecord):
super(AvroRsdos, self).resetRecord()

cpdef bytes getRsdosPacketString(self):
return <bytes>self.packetcontent[:self.pktcontentlen]
cdef unsigned int tagheadersize

tagheadersize = 0

# Ideally, we would be able to pull the size out of libtrace or
# libcorsaro, but for now we'll just have to hard-code the size here
if self.schemaversion == 1:
tagheadersize = 35 + (4 * 8)

if self.pktcontentlen <= tagheadersize:
return None

return <bytes>self.packetcontent[tagheadersize:self.pktcontentlen]

cpdef unsigned int getRsdosPacketSize(self):
cdef unsigned int tagheadersize

tagheadersize = 0

# Ideally, we would be able to pull the size out of libtrace or
# libcorsaro, but for now we'll just have to hard-code the size here
if self.schemaversion == 1:
tagheadersize = 35 + (4 * 8)

if self.pktcontentlen <= tagheadersize:
return 0

return self.pktcontentlen - tagheadersize

cpdef int setRsdosPacketString(self, const unsigned char[:] buf,
const unsigned int maxlen):

cdef parsedString astr


astr = read_string(buf, maxlen, addNullTerm=False)
if astr.toskip == 0:
return 0
Expand Down

0 comments on commit 472e826

Please sign in to comment.