Python method for storing list of bytes in network (big-endian) byte order to file (little-endian) -


My current task is to slash the TCPDump data, which contains P2P messages and I have trouble with the data of that piece I'm getting what I get and write a file on my x86 machine. I suspect that I have a simple and endless issue with the bytes typing to file

I have a byte Is a list of which P2P is a piece of video and an application Su-Pikepi package BTW has been processed using.

Bytes = [14, 254, 23, 35, 34, 67, etc ...]

I'm looking for a way to store these Yes bytes, currently in a file in my python application held in a list.

Currently I write pieces as follows:

  def write write (self, file name, trunkindex, bytes, ipsrc, ipdst, ts): file = Open (filename, AB ") Writing them in a file via #bytes if not already fragmented, do not self. PPCMap [IPDST]. Has_key: For Byte In Bytes: file.write ( '% C'% byte) file.flush () self.procLog.info ("% d)"% (lanes (bits), pieces index, filename) pieces (% D) bytes Written # Remember that this piece is in the time of duplicates. Self.piecemap [ipdst] [pieceindex] = True # Todo: Assemble the data like file.close ()  

As you can see from the loop, I write the bytes in the file as the same order as I process them by wire (i.e. network or large-edi sequence).

enough to say, video Which is a payload of pieces, does not playback well in the VoLC: - D

It seems that they need to change them in bitternational order but in Python, this is not the best way to reach it.

UPDATE

The solution is that worked out for me (Writing the Endian issues related to P2P fragments):

  Def writing grind (self, filename, pieceindex, bytes , IPSRC, IPDST, TS): File = Open (file name, "R + Minister ") if not Speepismap [Aipeedisti]. HS_ (PsychedX): little = straight pockets '& lt;' + B * * lane (bytes), * bytes) #Picture index file. Find offset based on CEK (PieceEndex * SpeciesSize) file. Write (short) file.flush () self.procLog. Written information ("% d" bytes written in "% (lane (bytes), tiki index, filename) from% (% D) to% s is written. # Remember that this piece is now when the duplicate itself is called SPIPEMAP [IPDST] [ Pseudex] = true file.close ()  

The Python Python structure module was used to resolve and was especially susceptible:

  little = Struct pack ('& lt;' + 'B' * lane), * bytes)  

Thanks for those people who are available with helpful tips Ia The s.

You can also use one:

  array import array Instead of  
  f.write (struct.pack ('& lt;' + ''), instead of f .write ('b', bytes))  

B <* * * Lane (bytes), * Bytes))

which is a bit short

  f.write (struct.pack ('b '* Lane (bytes), * bytes) # the & lt; is unnecessary;  

If any LAN (byte) can be "big"

  F.write (struct.pack ('% db'% lan (bytes), * bytes))  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -