Appends a value to the message. The type of the value is read from a D-Bus signature and used to marshall the value.
538 if (Debug.debug) Debug.print(Debug.VERBOSE, (Object)
bytecounter);
539 if (Debug.debug) Debug.print(Debug.VERBOSE,
"Appending type: " + ((
char) sigb[i]) +
" value: " + data);
544 case ArgumentType.BYTE:
547 case ArgumentType.BOOLEAN:
548 appendint(((Boolean) data).booleanValue() ? 1 : 0, 4);
550 case ArgumentType.DOUBLE:
551 long l = Double.doubleToLongBits(((Number) data).doubleValue());
554 case ArgumentType.FLOAT:
555 int rf = Float.floatToIntBits(((Number) data).floatValue());
558 case ArgumentType.UINT32:
559 appendint(((Number) data).longValue(), 4);
561 case ArgumentType.INT64:
562 appendint(((Number) data).longValue(), 8);
564 case ArgumentType.UINT64:
573 case ArgumentType.INT32:
574 appendint(((Number) data).intValue(), 4);
576 case ArgumentType.UINT16:
577 appendint(((Number) data).intValue(), 2);
579 case ArgumentType.INT16:
580 appendint(((Number) data).shortValue(), 2);
582 case ArgumentType.STRING:
583 case ArgumentType.OBJECT_PATH:
586 String payload = data.toString();
587 byte[] payloadbytes = null;
589 payloadbytes = payload.getBytes(
"UTF-8");
590 }
catch (UnsupportedEncodingException UEe) {
591 if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(UEe);
592 throw new DBusException(getString(
"utf8NotSupported"));
594 if (Debug.debug) Debug.print(Debug.VERBOSE,
"Appending String of length " + payloadbytes.length);
600 case ArgumentType.SIGNATURE:
605 if (data instanceof Type[])
606 payload = Marshalling.getDBusType((Type[]) data);
608 payload = (String) data;
609 byte[] pbytes = payload.getBytes();
615 case ArgumentType.ARRAY:
621 if (data instanceof Object[])
622 Debug.print(Debug.VERBOSE,
"Appending array: " + Arrays.deepToString((Object[]) data));
625 byte[] alen =
new byte[4];
631 if (data.getClass().isArray() &&
632 data.getClass().getComponentType().isPrimitive()) {
635 int len = Array.getLength(data);
637 case ArgumentType.BYTE:
638 primbuf = (byte[]) data;
640 case ArgumentType.INT16:
641 case ArgumentType.INT32:
642 case ArgumentType.INT64:
643 primbuf =
new byte[len * algn];
644 for (
int j = 0, k = 0; j < len; j++, k += algn)
645 marshallint(Array.getLong(data, j), primbuf, k, algn);
647 case ArgumentType.BOOLEAN:
648 primbuf =
new byte[len * algn];
649 for (
int j = 0, k = 0; j < len; j++, k += algn)
650 marshallint(Array.getBoolean(data, j) ? 1 : 0, primbuf, k, algn);
652 case ArgumentType.DOUBLE:
653 primbuf =
new byte[len * algn];
654 if (data instanceof
float[])
655 for (
int j = 0, k = 0; j < len; j++, k += algn)
656 marshallint(Double.doubleToRawLongBits(((
float[]) data)[j]),
659 for (
int j = 0, k = 0; j < len; j++, k += algn)
660 marshallint(Double.doubleToRawLongBits(((
double[]) data)[j]),
663 case ArgumentType.FLOAT:
664 primbuf =
new byte[len * algn];
665 for (
int j = 0, k = 0; j < len; j++, k += algn)
667 Float.floatToRawIntBits(((
float[]) data)[j]),
671 throw new MarshallingException(getString(
"arraySentAsNonPrimitive"));
674 }
else if (data instanceof List) {
675 Object[] contents = ((List) data).toArray();
678 for (Object o : contents)
681 }
else if (data instanceof Map) {
684 for (Map.Entry<Object, Object> o : ((Map<Object, Object>) data).entrySet())
688 Vector<Type> temp =
new Vector<Type>();
689 byte[] temp2 =
new byte[sigb.length - diff];
690 System.arraycopy(sigb, diff, temp2, 0, temp2.length);
691 String temp3 =
new String(temp2);
692 int temp4 = Marshalling.getJavaType(temp3, temp, 1);
697 Object[] contents = (Object[]) data;
700 for (Object o : contents)
705 Debug.print(Debug.VERBOSE,
"start: " + c +
" end: " + bytecounter +
" length: " + (bytecounter - c));
708 case ArgumentType.STRUCT1:
712 if (data instanceof Container)
713 contents = ((Container) data).getParameters();
715 contents = (Object[]) data;
718 for (i++; sigb[i] != ArgumentType.STRUCT2; i++)
721 case ArgumentType.DICT_ENTRY1:
723 if (data instanceof Map.Entry) {
725 i =
appendone(sigb, i, ((Map.Entry) data).getKey());
727 i =
appendone(sigb, i, ((Map.Entry) data).getValue());
730 contents = (Object[]) data;
732 for (i++; sigb[i] != ArgumentType.DICT_ENTRY2; i++)
736 case ArgumentType.VARIANT:
739 if (data instanceof Variant) {
740 Variant var = (Variant) data;
741 appendone(
new byte[]{ArgumentType.SIGNATURE}, 0, var.getSig());
742 appendone((var.getSig()).getBytes(), 0, var.getValue());
743 }
else if (data instanceof Object[]) {
744 contents = (Object[]) data;
745 appendone(
new byte[]{ArgumentType.SIGNATURE}, 0, contents[0]);
746 appendone(((String) contents[0]).getBytes(), 0, contents[1]);
748 String sig = Marshalling.getDBusType(data.getClass())[0];
749 appendone(
new byte[]{ArgumentType.SIGNATURE}, 0, sig);
755 }
catch (ClassCastException CCe) {
756 if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, CCe);
757 throw new MarshallingException(MessageFormat.format(getString(
"unconvertableType"),
new Object[]{data.getClass().getName(), sigb[sigofs]}));
void appendBytes(byte[] buf)
Definition: Message.java:289
void ensureBuffers(int num)
Definition: Message.java:275
void preallocate(int num)
Definition: Message.java:262
static byte [][] padding
Definition: Message.java:136
boolean big
Definition: Message.java:155
void pad(byte type)
Definition: Message.java:764
long bytecounter
Definition: Message.java:157
void appendint(long l, int width)
Definition: Message.java:391
int appendone(byte[] sigb, int sigofs, Object data)
Definition: Message.java:535
void marshallint(long l, byte[] buf, int ofs, int width)
Definition: Message.java:406
void appendByte(byte b)
Definition: Message.java:312
static int getAlignment(byte type)
Definition: Message.java:782