Sizeof(const char **) on 32 bit system - pointers
What's the value of the expression above? Is there any difference in running it in 32 or 64 bit (I'm on 32 bit)
Thank you
Value of expression Sizeof(const char **) is 8 on 64 bit machine and 4 and 32 bit machine.
Edit :
1 byte = 8 bits
64/8 = 8 bytes and 32/8 = 4 bytes.
Related
Parsing bytes as BCD with Indy C++ Builder
I am trying to parse the length of a message received. The length is in BCD. When I use ReadSmallInt(), I get a reading interpreted as a hex value, not as BCD. So, if I have a message like this: 00 84 60 00 00 00 19 02 10 70 38 00 00 0E C0 00 00 16 45 93 56 00 01 79 16 62 00 00 00 00 00 00 08 00 00 00 00 02 10 43 02 04 02 35 31 35 31 35 31 35 31 35 31 35 31 53 41 4C 45 35 31 30 30 31 32 33 34 35 36 37 38 31 32 33 34 35 36 37 38 39 30 31 32 33 I am expecting ReadSmallInt() to return 84, but instead it is returning 132, which is correct if you are reading a hex value instead of a BCD one. According to this answer, ReadSmallInt() reads BCD, as in the examples it gets 11 and 13 (BCD) as lengths instead of 17 and 19 (hex). I have fixed this with duct tape, but is there a more elegant way? int calculated_length; // getting the length in Hexa calculated_length = AContext->Connection->IOHandler->ReadSmallInt(); // converting from hex binary to hex string UnicodeString bcdLength = UnicodeString().sprintf(L"%04x", calculated_length); // converting from hex string to int calculated_length = bcdLength.ToInt(); ucBuffer.Length = calculated_length -2; AContext->Connection->IOHandler->ReadBytes(ucBuffer, calculated_length - 2);
According to this answer, ReadSmallInt reads BCD That is incorrect. You have misinterpreted what that answer is saying. NOTHING in that answer indicates that ReadSmallInt() reads in a Binary Coded Decimal, because it doesn't, as Indy DOES NOT support reading/writing BCDs at all. ReadSmallInt() simply reads in 2 bytes and returns them as-is as a 16-bit decimal integer (swapping the byte order, if needed). So, if you need to read in a BCD instead, you will have to read in the bytes and then parse them yourself. Or find a BCD library to handle it for you. If you re-read that other question again more carefully, in the 2 examples it gives: 24 24 00 11 12 34 56 FF FF FF FF 50 00 8B 9B 0D 0A 24 24 00 13 12 34 56 FF FF FF FF 90 02 00 0A 8F D4 0D 0A The 3rd and 4th bytes represent the message lengths (x00 x11 and x00 x13, respectively). As 16-bit values in network byte order, they represent decimal integers 17 and 19, respectively. And if you count the bytes present, you will see those values are the correct byte lengths of those messages. So, there are no BCDs involved here. That is different than your example. Bytes x00 x84 in network byte order represent decimal integer 132. But your message is 84 bytes in size, not 132 bytes. So clearly the bytes x00 x84 DO NOT represent a 16-bit decimal value, so ReadSmallInt() is the wrong method to use in the first place. In your "duct tape" code, you are taking the decimal value that ReadSmallInt() returns (132), converting it to a hex string ('0084'), and then parsing that to a decimal value (84). There is no method in Indy that will do that kind of conversion for you. That "works" in your case, but whether or not that is the correct conversion to perform, I could not say for sure as you have not provided any details about the protocol you are dealing with. But, if you think the bytes represent a BCD then you should interpret the bytes in terms of an actual BCD. In a packed BCD, a byte can represent a 2-digit number. In this case, byte x84 (10000100b) contains two nibbles 1000b (8) and 0100b (4), thus put together they form decimal 84, which is calculated as follows: BYTE b = 0x84; int len = (int((b >> 4) & 0x0F) * 10) + int(b & 0x0F); Now, how that extends to multiple bytes in a BCD, I'm not sure, as my experience with BCDs is very limited. But, you are going to have to figure that out if you need to handle message lengths greater than 99 bytes, which is the highest decimal that a single BCD byte can represent.
Decoding Thrift Object what are these extra bytes?
I'm working on writing a pure JS thrift decoder that doesn't depend on thrift definitions. I have been following this handy guide which has been my bible for the past few days: https://erikvanoosten.github.io/thrift-missing-specification/ I almost have my parser working, but there is a string type that throws a wrench into the program, and I don't quite understand what it's doing. Here is an excerpt of the hexdump, which I did my best to annotate: Correctly parsing: 000001a0 0a 32 30 32 31 2d 31 31 2d 32 34 16 02 00 18 07 |.2021-11-24.....| ........................blah blah blah............| | | Object End-| | | 0x18 & 0xF = 0x8 = Binary-| | The binary sequence is 0x7 characters long-| 000001b0 53 65 61 74 74 6c 65 18 02 55 53 18 02 55 53 18 |Seattle..US..US.| S E A T T L E |___| U S |___| U S Another string, 2 bytes long |------------| So far so good. But then I get to this point: There string I am trying to extract is "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4592.0 Safari/537.36 Edg/94.0.975.1" and is 134 bytes long. 000001c0 09 54 61 68 6f 65 2c 20 43 41 12 12 00 00 08 c8 |.Tahoe, CA......| Object ends here-| | | 0x8 & 0xF = 0x8 = Binary -| | 0xc8 bytes long (200)-| 000001d0 01 86 01 4d 6f 7a 69 6c 6c 61 2f 35 2e 30 20 28 |...Mozilla/5.0 (| | | | M o z i l l a ???? |--|-134, encoded as var-int 000001e0 4d 61 63 69 6e 74 6f 73 68 3b 20 49 6e 74 65 6c |Macintosh; Intel| As you can see, I have a byte sequence 0x08 0xC8 0x01 0x86 0x01 which contains the length of the string I'm looking for, is followed by the string I'm looking for but has 3 extra bytes that are unclear in purpose. The 0x01 is especially confusing as it neither a type identifier, nor seems to have a concrete value. What am I missing?
Thrift supports pluggable serialization schemes. In tree you have binary, compact and json. Out of tree anything goes. From the looks of it you are trying to decode compact protocol, so I'll answer accordingly. Everything sent and everything returned in a Thrift RPC call is packaged in a struct. Every field in a struct has a 1 byte type and a 2 byte field ID prefix. In compact protocol field ids, when possible, are delta encoded into the type and all ints are compressed down to just the bits needed to store them (and some flags). Because ints can now take up varying numbers of bytes we need to know when they end. Compact protocol encodes the int bits in 7 bits of a byte and sets the high order bit to 1 if the next byte continues the int. If the high order bit is 0 the int is complete. Thus the int 5 (101) would be encoded in one byte as 0000101. Compact knows this is the end of the int because the high order bit is 0. In your case, the int 134 (binary 10000110) will need 2 bytes to encode because it is more than 7 bits. The fist 7 bits are stored in byte 1 with the 0x80 bit set to flag "the int continues". The second and final byte encodes the last bit (00000001). What you thought was 134 was just the encoding of the first seven bits. The stray 1 was the final bit of the 134. I'd recommend you use the in tree source to do any needed protocol encoding/decoding. It's already written and tested: https://github.com/apache/thrift/blob/master/lib/nodejs/lib/thrift/compact_protocol.js
The byte sequence reads as follows 0x08: String type, the next 2 bytes define the elementId 0xC8 0x01: ElementId, encoded in 16 bits 0x86 0x01: String length, encoded as var int It turns out that if the type identifier does not contain bits defining the elementId, the elementId will be stored in the next 2 bytes.
Unknown CRC Method
I having following modbus polling query but i am unable find the correct crc method,crc position and crc value please guide me to find correct crc method,crc position and crc value for the following query 01 37 37 1D 31 31 31 1D 30 1D 31 03 32 35 30 34 39 04 01 37 37 1D 31 31 31 1D 30 1D 32 03 32 35 30 34 33 04 01 37 37 1D 31 31 31 1D 30 1D 33 03 35 37 38 31 34 04 01 37 37 1D 31 31 31 1D 30 1D 34 03 32 35 30 33 31 04 01 37 37 1D 31 31 31 1D 30 1D 35 03 35 37 37 39 34 04 for the above modbus polling query i am not getting which one is crc value and what type of crc used. How it is came and 77 is id of the device. Please guide me.. I am getting following response from the device for polling 01 37 37 02 33 1D 30 39 33 31 39 30 39 34 38 32 30 30 37 31 31 42 20 30 30 30 30 30 30 30 38 34 30 30 30 30 30 30 30 30 30 30 30 30 30 30 37 38 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 35 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 03 34 37 33 38 35 04
First of all: The MODBUS over Serial Line standard is available here. This completely specifies low-level interface to MODBUS. The MODBUS Application Protocol Specification is available here. Higher-level MODBUS commands are specified here. Both of these standards are fairly short, easy to read and understand, and contain nice diagrams, so I highly recommend you look at them for answers. Your data doesn't appear to conform to these standards, which makes it hard to answer your questions! The serial line standard describes two communication methods, RTU and ASCII, but only the RTU method uses a CRC. So you must be using the RTU communication method since you're asking about CRC. Assuming the RTU communication method, then the slave address should be the first byte, and the function code should be the second byte. That would mean that the slave address is 01, and the function code is 37. But that's not right, because the Application Protocol Specification page 11 lists all the function codes, and 37 is not a valid function code. Also, the slave address 01 doesn't match the slave address 77 that you claim to be using. But let's ignore that for the moment. Your specific questions are about CRC. The RTU communication method is the only one which uses a CRC. The ASCII communication method uses a Longitudinal Redundancy Check (LRC), which is different. The RTU communication method uses a CRC-16, meaning the CRC has 16 bits = 2 bytes. The details are contained in the serial line standard, and there is even some sample C code for computing the CRC there. There are also multiple implementations in various languages available if you google, but do be careful because there are several different CRC-16 definitions and you need to make sure that what you use matches the MODBUS standard. The CRC position in a MODBUS frame is at the very end of the frame. The last two bytes (16 bits) are the CRC. The low-order byte of the CRC is appended first, followed by the high-order byte. The MODBUS queries that you provide do NOT appear to have a CRC appended to them at all. But, as I mentioned earlier, the MODBUS queries that you provide don't even look like they use the RTU communication method, which is the only method that uses a CRC. Since your data doesn't seem to follow the RTU communication method, perhaps it uses the ASCII communication method, which is described starting on page 16 of the serial line standard. The ASCII communication method always starts with an ASCII : character, which is 3A in hex. The ASCII communication method always ends with ASCII cr and lf characters, which are 0D and 0A in hex. All other characters between these must be 0-9 or A-F characters, which are 30 through 39 and 41 through 46 in hex. Your message does not obey any of these requirements - it doesn't start with 3A, it doesn't end with 0D 0A, and it contains other characters that are not 30 through 39 or 41 through 46. If we ignore that and assume that your data follows the ASCII communication method, then: The LRC field would be the last two bytes before the 0D 0A at the end. Page 18 of the serial line standard describes how LRC is computed. It is very simple: The LRC is calculated by adding together successive 8–bit bytes of the message, discarding any carries, and then two’s complementing the result. It is performed on the bytes of the message, before the encoding of each byte in the two ASCII characters corresponding to the hexadecimal representation of each nibble. The computation does not include the 'colon' character that begins the message, and does not include the CRLF pair at the end of the message. The resulting LRC is ASCII encoded into two bytes and placed at the end of the ASCII mode frame before the CRLF. Page 38 of the serial line standard give example C code for generating the LRC. It is only 9 lines of code. Your data does not follow either of the communication methods. We would need to know more about where your data came from to figure out what went wrong. Perhaps the data is somehow corrupted by multiple devices, or perhaps the sensor that measures the data has incorrect timing or voltage or something, causing it to mis-understand the values being sent. Perhaps there is some kind of parity mis-match, causing some bytes to be thrown away. But we just can't tell without more information.
TCPDF - Problem with Alphanumerical characters (wrong size)
I have a size problem when using TCPDF to generate QR code with only ALPHANUMERICAL characters. My objective: generate the longest URL (with a random part), but keeping the QR code at its lowest size, i.e. 21x21 modules (version1). Documentation (QRcode.com) reports that using only alphanumerical characters set (thonky.com), URL can be 25 characters long with ERC set to L. Using write2DBarCode with this 25 Alphanumerical URL leads to version1 (21x21mod) QR as expected $pdf->write2DBarcode('HTTP://SITE-COM/123456789', 'QRCODE,L', 20, 20, 40, 40, $style, 'N'); but changing to this other URL, with also 25 Alphanumerical, I get a version 2 (25x25mod) QR code, whereas a version 1 could be done (Tested on Nayuki) $pdf->write2DBarcode('HTTP://TXT-CH/AYAWEQYAF4A', 'QRCODE,L', 20, 70, 40, 40, $style, 'N'); I join the TCPDF Outputs of the 2 QR codes given as examples TCPDF Outputs Thank you in advance for your help on this wonderful TCPDF library.
Short answer: The TCPDF software that you are using is suboptimal. It is generating a full 4-bit terminator even when a shorter one suffices. Please contact the software's authors to fix the problem. You can link them to this thread. So I cropped your image into two QR Code images, and submitted them to ZXing Decoder Online and KaarPoSoft QR Decode with debug output. ZXing, first barcode: Decode Succeeded Raw text HTTP://SITE-COM/123456789 Raw bytes 20 83 1a a6 5f 9f d5 b4 75 3e 8d 20 48 81 23 db 91 8a 80 Barcode format QR_CODE Parsed Result Type URI Parsed Result HTTP://SITE-COM/123456789 ZXing, second barcode: Decode Succeeded Raw text HTTP://TXT-CH/AYAWEQYAF4A Raw bytes 20 cb 1a a6 5f 9f d6 5e ae 82 ca 0f 21 e2 52 18 11 53 94 00 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 Barcode format QR_CODE Parsed Result Type URI Parsed Result HTTP://TXT-CH/AYAWEQYAF4A KaarPoSoft, first barcode: Debug output skew_limit=7.21875 skew=0 left=31 right=427 top=27 bottom=423 size=397 matchVersion version=1 finder0=64 finder1=64 finder2=64 matchVersion version=1 timing0=1 timing1=1 alignment=1 matchVersion version=1 format_NW =14 0 format_NESW =14 1 format = 14 ecl = 1 mask = 6 matchVersion version=1 grades(F(V)TAF): 4444->4 findModuleSize matchVersion version=1 grade=4 findModuleSize version=1 grade=4 error_correction_level=1 mask=6 getCodewords mask=6 length=26 getCodewords = 32,131,26,166,95,159,213,180,117,62,141,32,72,129,35,219,145,138,128,62,191,105,157,147,176,164 setBlocks n_blocks_first=1 n_blocks_second=0 n_blocks=1 n_block_words_first=19 n_block_words_second=0 n_block_ec_words=7 total=26 setBlocks block 0 (26): 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 RS calculateSyndroms: No errors correctErrors in = 32,131,26,166,95,159,213,180,117,62,141,32,72,129,35,219,145,138,128,62,191,105,157,147,176,164 correctErrors out = 32,131,26,166,95,159,213,180,117,62,141,32,72,129,35,219,145,138,128 error_grade=4 extractData bytes in (19) = 32,131,26,166,95,159,213,180,117,62,141,32,72,129,35,219,145,138,128 extractData mode = 2 extractAlphanum charcount = 16 extractData mode = 1 extractNumeric charcount = 9 extractData mode = 0 extractData data(25) = 72,84,84,80,58,47,47,83,73,84,69,45,67,79,77,47,49,50,51,52,53,54,55,56,57 KaarPoSoft, second barcode: Debug output skew_limit=7.015625 skew=1 left=21 right=417 top=30 bottom=425 size=396.5 findModuleSize matchVersion version=1 grade=0 matchVersion version=2 finder0=64 finder1=64 finder2=64 matchVersion version=2 timing0=1 timing1=1 alignment=1 matchVersion version=2 format_NW =14 0 format_NESW =14 1 format = 14 ecl = 1 mask = 6 matchVersion version=2 grades(F(V)TAF): 4444->4 findModuleSize matchVersion version=2 grade=4 findModuleSize version=2 grade=4 error_correction_level=1 mask=6 getCodewords mask=6 length=44 getCodewords = 32,203,26,166,95,159,214,94,174,130,202,15,33,226,82,24,17,83,148,0,236,17,236,17,236,17,236,17,236,17,236,17,236,17,87,194,99,197,7,184,131,204,163,52 setBlocks n_blocks_first=1 n_blocks_second=0 n_blocks=1 n_block_words_first=34 n_block_words_second=0 n_block_ec_words=10 total=44 setBlocks block 0 (44): 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43 RS calculateSyndroms: No errors correctErrors in = 32,203,26,166,95,159,214,94,174,130,202,15,33,226,82,24,17,83,148,0,236,17,236,17,236,17,236,17,236,17,236,17,236,17,87,194,99,197,7,184,131,204,163,52 correctErrors out = 32,203,26,166,95,159,214,94,174,130,202,15,33,226,82,24,17,83,148,0,236,17,236,17,236,17,236,17,236,17,236,17,236,17 error_grade=4 extractData bytes in (34) = 32,203,26,166,95,159,214,94,174,130,202,15,33,226,82,24,17,83,148,0,236,17,236,17,236,17,236,17,236,17,236,17,236,17 extractData mode = 2 extractAlphanum charcount = 25 extractData mode = 0 extractData data(25) = 72,84,84,80,58,47,47,84,88,84,45,67,72,47,65,89,65,87,69,81,89,65,70,52,65 Both QR Codes appear to have no problems regarding error correction or format violations. From the KaarPoSoft output, we can see the segments in the QR Codes. The first barcode has two segments: Alphanumeric mode, count = 16, text = "HTTP://SITE-COM/". Segment bit length = 4 (mode) + 9 (count) + 88 (data) = 101 bits. Numeric mode, count = 9, text = "123456789". Segment bit length = 4 (mode) + 10 (count) + 30 (data) = 44 bits. The second barcode has one segment: Alphanumeric mode, count = 25, text = "HTTP://TXT-CH/AYAWEQYAF4A". Segment bit length = 4 (mode) + 9 (count) + 138 (data) = 151 bits. Now, a QR Code at version 1 with low error correction level has capacity for 19 data codeword bytes, or 152 bits. The first barcode uses 101 + 44 = 145 bits = 19 bytes (rounded up), so it fits. The second barcode uses 151 bits = 19 bytes (rounded up), so it fits. So in theory, both lists of segments of text data should fit in version 1 low ECC. According to the QR spec, after the list of segments ends, these bits are appended: (TERM) Up to four "0" bits (but less if the data capacity is reached) for the terminator pseudo-mode. (BITPAD) Zero to seven "0" bits to fill up the last partial byte. (BYTEPAD) Alternating bytes of 0xEC and 0x11 until the data capacity is reached. Let's dissect what actually happened. Convert the ZXing hexadecimal byte output to binary, and annotate the fields. First barcode: 20 83 1a a6 5f 9f d5 b4 75 3e 8d 20 48 81 23 db 91 8a 80 0010 000010000 [88 bits] 0001 0000001001 [30 bits] 0000 000 (Total length = 152 bits) ^Mode ^Count ^Data ^Mode ^Count ^Data ^TERM ^BITPAD Second barcode: 20 cb 1a a6 5f 9f d6 5e ae 82 ca 0f 21 e2 52 18 11 53 94 00 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 0010 000011001 [138 bits] | 0000 00000 11101100 00010001 [...] (Total length = 272 bits) ^Mode ^Count ^Data | ^TERM ^BITPAD ^BYTEPAD Note that in the second barcode, at the position | just before the TERMinator, there are 151 bits on the left side. The terminator is normally four "0" bits, but is allowed to be shortened if the capacity (of 152 bits) is reached. So the optimal terminator is a single bit of "0", and then there must be no bit padding and no byte padding.
output of kamailio shared memory
I am trying to monitor the memory usage of kamailio. The PKG memory I have arranged, though the shared memory is something else. According to documentation you can get the shared memory like this: kamcmd mod.stats all shm In my case, I get the following: Module: core { msg_lump_cloner(984): 1560 dns_cache_mk_bad_entry(867): 192 dns_cache_mk_rd_entry(1216): 232 build_req_buf_from_sip_req(2155): 2752 sip_msg_shm_clone(495): 822664 tcpconn_new(957): 16416728 counters_prefork_init(207): 30720 cfg_clone_str(130): 208 cfg_shmize(217): 976 init_pt(105): 4200 cfg_parse_str(906): 80 init_pt(106): 16 init_pt(111): 40 create_avp(175): 10368 register_timer(1012): 720 cfg_register_ctx(47): 128 init_tcp(4643): 8192 init_tcp(4637): 32768 init_tcp(4629): 8 init_tcp(4622): 8 init_tcp(4615): 8 init_tcp(4609): 8 init_tcp(4597): 8 init_avps(90): 8 init_avps(89): 8 init_dst_blacklist(437): 16384 init_dst_blacklist(430): 8 timer_alloc(515): 96 init_dns_cache(366): 8 init_dns_cache(358): 16384 init_dns_cache(351): 16 init_dns_cache(345): 8 init_timer(284): 8 init_timer(283): 16384 init_timer(282): 8 init_timer(281): 8 init_timer(270): 8 init_timer(238): 8 init_timer(221): 278544 init_timer(220): 8 init_timer(207): 8 cfg_child_cb_new(830): 64 sr_cfg_init(361): 8 sr_cfg_init(354): 8 sr_cfg_init(347): 8 sr_cfg_init(335): 8 sr_cfg_init(323): 24 shm_core_lock_init(153): 8 Total: 17660616 } ... [ list of modules here, snipped because not relevant I think] ... So I guess the one I need is Total: 17660616. However, what does this mean? Is it the total allocated memory? Available memory?
The commands you used is for seeing the used of shared memory per module. If you want the statistics for total used and free shared memory, then use the command: kamctl stats shmem or: kamcmd stats.get_statistics shmem: The output will be like: shmem:fragments = 179 shmem:free_size = 127471848 shmem:max_used_size = 7269016 shmem:real_used_size = 6745880 shmem:total_size = 134217728 shmem:used_size = 5106728 The free_size value is the one you have to monitor for available shared memory.