2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.homematic.internal.communicator.message;
18 * Helper class with common RPC funtions.
20 * @author Gerhard Riegler - Initial contribution
22 public class RpcUtils {
25 * Dumps decoded RPC data.
27 public static String dumpRpcMessage(String methodName, Object[] responseData) {
28 StringBuilder sb = new StringBuilder();
29 if (methodName != null) {
30 sb.append(methodName);
33 dumpCollection(responseData, sb, 0);
37 private static void dumpCollection(Object[] c, StringBuilder sb, int indent) {
39 for (int in = 0; in < indent - 1; in++) {
45 if (o instanceof Map) {
46 dumpMap((Map<?, ?>) o, sb, indent + 1);
47 } else if (o instanceof Object[]) {
48 dumpCollection((Object[]) o, sb, indent + 1);
50 for (int in = 0; in < indent; in++) {
58 for (int in = 0; in < indent - 1; in++) {
65 private static void dumpMap(Map<?, ?> c, StringBuilder sb, int indent) {
67 for (int in = 0; in < indent - 1; in++) {
72 for (Map.Entry<?, ?> me : c.entrySet()) {
73 Object o = me.getValue();
74 for (int in = 0; in < indent; in++) {
77 sb.append(me.getKey());
79 if (o instanceof Map<?, ?>) {
81 dumpMap((Map<?, ?>) o, sb, indent + 1);
82 } else if (o instanceof Object[]) {
84 dumpCollection((Object[]) o, sb, indent + 1);
91 for (int in = 0; in < indent - 1; in++) {