techknight Well-Known Member Licensed User Longtime User Jan 12, 2017 #1 Is it possible to log a byte array into the log window without converting it? On the Buffer() array from Astreams there is a character or something getting in there thats causing the Bytestostring to crash, but I cannot tell what. Code: Copy Try RxPacket = RxPacket & BytesToString(Buffer, 0, Buffer.Length, "UTF8") Catch RxPacket = "" #IF DEBUG Log("Non string character detected in buffer, flushing.") #End If Return End Try Above code works fine until something gets in the buffer that causes a "Cannot parse as string" crash which ends up in the "Catch" routine. Of course the Try-Catch prevents my program from crashing and I eventually get the right response and everything is fine. BUT, I cannot help but wonder as to why... any ideas? Last edited: Jan 12, 2017
Is it possible to log a byte array into the log window without converting it? On the Buffer() array from Astreams there is a character or something getting in there thats causing the Bytestostring to crash, but I cannot tell what. Code: Copy Try RxPacket = RxPacket & BytesToString(Buffer, 0, Buffer.Length, "UTF8") Catch RxPacket = "" #IF DEBUG Log("Non string character detected in buffer, flushing.") #End If Return End Try Above code works fine until something gets in the buffer that causes a "Cannot parse as string" crash which ends up in the "Catch" routine. Of course the Try-Catch prevents my program from crashing and I eventually get the right response and everything is fine. BUT, I cannot help but wonder as to why... any ideas?
Erel B4X founder Staff member Licensed User Longtime User Jan 13, 2017 #2 You cannot treat raw bytes as a string. You can use ByteConverter.HexFromBytes to convert the bytes to a hex string. Upvote 0
You cannot treat raw bytes as a string. You can use ByteConverter.HexFromBytes to convert the bytes to a hex string.
techknight Well-Known Member Licensed User Longtime User Jan 13, 2017 #3 Its being transmitted as a HexString from the source, thats why its like this. Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jan 15, 2017 #4 If the bytes represent a valid string then you can use BytesToString to log the data. Generally speaking there is no good reason to send a hex string. It is better to send the bytes directly. Upvote 0
If the bytes represent a valid string then you can use BytesToString to log the data. Generally speaking there is no good reason to send a hex string. It is better to send the bytes directly.
techknight Well-Known Member Licensed User Longtime User Jan 17, 2017 #5 I like hex strings. its easier for me to read, perform operations on, etc.. Plus I am not changing 5+ years worth of work. Anyways, This answers my question. a Simple "no". I will leave the catch in there then. Seems to work as is. Upvote 0
I like hex strings. its easier for me to read, perform operations on, etc.. Plus I am not changing 5+ years worth of work. Anyways, This answers my question. a Simple "no". I will leave the catch in there then. Seems to work as is.
stanmiller Active Member Licensed User Longtime User Jan 18, 2017 #6 techknight said: I like hex strings. its easier for me to read, perform operations on, etc... Click to expand... Me too. Transmit as strings if practicable for command and control. String representation is not only portable but also easy to debug through WireShark. And if you need to compact and/or hide use RLE compression and obfuscate with symmetrical XOR character-based encryption. Last edited: Jan 18, 2017 Upvote 0
techknight said: I like hex strings. its easier for me to read, perform operations on, etc... Click to expand... Me too. Transmit as strings if practicable for command and control. String representation is not only portable but also easy to debug through WireShark. And if you need to compact and/or hide use RLE compression and obfuscate with symmetrical XOR character-based encryption.