[mkgmap-dev] methods to write signed / unsigned integers
From Steve Ratcliffe steve at parabola.me.uk on Sun Feb 18 21:37:19 GMT 2018
Hi Gerd, Ticker For ImgFileWriter I think we should just have put1(int), put2(int), put3(int) and put4(int) and remove put(byte), putChar(char) and putInt(int). So each method takes an int, so no casting is needed. There is no difference between writing unisigned and signed for any value that fits into an int. To write unsigned values greater than 2G then technically you need a long, so an unsigned version could be added as a default method on the interface put4u(long val) rather than having to implement across multiple implementations. Although I don't think it is necessary if you want to add signed/unsigned methods that range check the value, then again add them as default method on the interface. I've attached a patch that implements this. Reading is different, we do need signed/unsigned versions. I'd suggest that again have get{1,2,3,4} and remove getChar and getInt special cases, and then get1u() etc for unsigned results. All of these returning int probably, depending on what results in the best looking code. I have not done a patch for that. ..Steve > we have various methods to write an integer with 1, 2, 3, or 4 bytes to an img file. > I always feel unsure what method to use because none of them makes > clear what happens with negative values. > > Besides that some of the existing routines seem to throw misleading exceptions, > e.g. FileBackedImgFileWriter seems to assume that it is only used for the mdr tmp file and creates texts like this: > throw new MapFailedException("could not write3 to mdr tmp file"); > throw new MapFailedException("could not write put3 to mdr tmp file"); > > Only the javadoc for put1() and put2() tell me the range (0..255 or 0..65535) . > > If I got that right put3() allows negative values, so I think it is NOT 0..16777215 but -8388608 .. 8388607 ? > > I'd like to improve the readability of the code, but I don't want to mess up anything. > Would it be possible to add comments to all the methods? > > Gerd > > > > _______________________________________________ > mkgmap-dev mailing list > mkgmap-dev at lists.mkgmap.org.uk > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev > -------------- next part -------------- A non-text attachment was scrubbed... Name: img-write.patch Type: text/x-patch Size: 77668 bytes Desc: not available URL: <http://www.mkgmap.org.uk/pipermail/mkgmap-dev/attachments/20180218/42a0171d/attachment-0001.bin>
- Previous message: [mkgmap-dev] methods to write signed / unsigned integers
- Next message: [mkgmap-dev] methods to write signed / unsigned integers
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the mkgmap-dev mailing list