Issue #262 has been updated by Philipp  Buluschek.

I have just checked the Integers.readLong() method, and I think that building 
two ByteBuffer Objects, assigning one byte array and  iterating over the whole 
thing twice (once in ByteBuffer's getLong()) is really suboptimal. I agree that 
using JRE methods is preferable to building your own - but only if they do what 
you want...

The following implementation only assigns the output long and iterates once.

<pre>
public static long readLong(byte[] src, int pos, int size) {
  long value = 0;
  for (int i = 0; i < size; i++){
     value += ((long) src[pos + i] & 0xffL) << (8 * i);
  }
  return value;
}
</pre>



----------------------------------------
Bug #262: Check byte-order writing
http://zb4o.aaloa.org/redmine/issues/262#change-773

Author: Philipp  Buluschek
Status: Feedback
Priority: Urgent
Assignee: Stefano Lenzi
Category: zigbee.common
Target version: org.aaloa.zb4osgi.zigbee.common-0.5.0
Has a patch: No
Has license agreement signed: No


I implemented the writing of ZigBee data type IEEE_Address (see 
ZigBeeType.IEEEAddress) in ByteArrayOutputStreamSerializer. The original 
Java-data type was String, but I changed it to Long as it is much more adapted 
(as it's also what is returned from SimpleDriver.getIEEEAddress() ).

Writing the IEEE Address (as a long) in ByteArrayOutputStreamSerializer, I 
supposed the code should look like:
@
case IEEEAddress:
  final Long l = (Long) data;
  append_long(l.longValue());
  break;@

But noticed that, the IEEE address gets written byte-order reversed over the 
air. In particular, the ZigBee Spec (1.2.1.3) says that the least significant 
byte must be sent first. But the implementation of Integers.writeLong() does 
the reverse (writes msb first to the buffer). For my case, I simply added a 
implementation of the reversed writing - so not a problem.

But I now wonder - all other data types (larger than 1 byte) are written in the 
same manner as long in Integers.writeXXX(). Should they all be reversed?






-- 
DO NOT ANSWER TO THIS E-MAIL ADDRESS, NO ONE WILL READ IT. PLEASE WRITE TO 
[email protected]
ZigBee 4 OSGi - Redmine E-Mail Notificatioon
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://zb4o.aaloa.org/redmine
_______________________________________________
Dev mailing list
[email protected]
http://zb4osgi.aaloa.org/mailman/listinfo/dev

Reply via email to