X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 6A1D69FB2D0 for ; Mon, 10 Jul 2006 14:55:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 18422-02 for ; Mon, 10 Jul 2006 14:54:57 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id D50E89FB284 for ; Mon, 10 Jul 2006 14:54:56 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Fzzxt-0007C7-0a for pgsql-jdbc@postgresql.org; Mon, 10 Jul 2006 19:54:37 +0200 Received: from 83.145.96.118 ([83.145.96.118]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 10 Jul 2006 19:54:37 +0200 Received: from Marc.Herbert by 83.145.96.118 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 10 Jul 2006 19:54:37 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Marc Herbert Subject: Re: java & endianness [Re: Binary tx format for an array?] Date: Mon, 10 Jul 2006 19:54:20 +0200 Lines: 58 Message-ID: References: <30b57570606211026o66e337c9s658387db0b32aeed@mail.gmail.com> <17160.1150929667@sss.pgh.pa.us> <30b57570606220116h2f216c1eue74e5cfbb41bd5bc@mail.gmail.com> <1048.1150995309@sss.pgh.pa.us> <1151003773.21238.13.camel@archimedes> <1152548310.30994.260.camel@archimedes> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 83.145.96.118 User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4 (Jumbo Shrimp, linux) Cancel-Lock: sha1:WZGQJuxg2GvIagXrw2FPKfGieWQ= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/27 X-Sequence-Number: 15453 Mark Lewis writes: >> > public void SendInteger4(int val) throws IOException >> > { >> > SendChar((val >> 24)&255); >> > SendChar((val >> 16)&255); >> > SendChar((val >> 8)&255); >> > SendChar(val&255); >> > } >> >> This code is like copied/pasted from the JDK: >> >> * @since JDK1.0 >> DataOutputStream#writeInt() >> >> >> Any reason for duplicating it in the driver? > > Well, in the general case you can only use DataOutputStream's writeInt() > method if everything is in big-endian byte order, which is true in this > case but not universally so. My point is that it IS universally true in the Java universe AND in the networking universe. There simply cannot be two opposed networking universes... that would mean we'd have two Internets for instance? So I think the whole point of Java is that everything is big-endian, so you do not need to know about endianness anymore. IMHO this is a success. > Here it IS big-endian, so the choice is between duplicating one > method a few lines long, or wrapping the main OutputStream in an > extra DataOutputStream which would only be used when writing > big-endian integers. Not sure if one solution is better than the > other. OK you can bypass/copy-paste some JDK code for performance reasons. But then you can not honestly complain Java does a poor job of hiding endianness when you fiddled with the machine internals instead of safely staying outside. Moreover you don't really need to think about endianness when simply copy/pasting this code. > It's in the java.nio stuff, look at the javadoc for > ByteBuffer.order() for a starting point. Interesting. Looks like you need this only when dealing with badly-behaved applications that do not use the network order, right? Should be very seldom, don't you think? Thanks for answering.