logo separator

[mkgmap-dev] methods to write signed / unsigned integers

From Gerd Petermann gpetermann_muenchen at hotmail.com on Mon Feb 19 07:13:19 GMT 2018

Hi Steve,

thanks, I think that this improves the code. Small problem:
I think you forgot to remove / adapt some comments in BufferedImgFileWriter,
e.g. for put1 and put2.

I'd prefer to replace them by an @override annotation.


Von: mkgmap-dev <mkgmap-dev-bounces at lists.mkgmap.org.uk> im Auftrag von Steve Ratcliffe <steve at parabola.me.uk>
Gesendet: Sonntag, 18. Februar 2018 22:37:19
An: mkgmap-dev at lists.mkgmap.org.uk
Betreff: Re: [mkgmap-dev] methods to write signed / unsigned integers

Hi Gerd, Ticker

For ImgFileWriter I think we should just have put1(int), put2(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.


> 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

More information about the mkgmap-dev mailing list