summaryrefslogtreecommitdiffstats
path: root/vpp-common
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-12-16 13:07:56 +0100
committerMarek Gradzki <mgradzki@cisco.com>2016-12-20 13:59:56 +0100
commitf8273e10b19ecc82bdda81feef9982ce28d5de21 (patch)
tree98d2d9686bcf24f64c0c18c633554e8629f2e22e /vpp-common
parente3b9212110528217c2477f588ebccc0d76ee31e1 (diff)
HONEYCOMB-310: translation layer for acl plugin
Not covered by this patch (moved to subsequent commits): - postman collection - distinguish ingress/egress ACLs while reading assigned acls - proper support for acl tag - unit tests improvements - read for acls (not necessarily assigned) - initializers Change-Id: I5a198ce1a6e20d0b1d95b4d2d83d0464fb86580c Signed-off-by: Jan Srnicek <jsrnicek@cisco.com> Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vpp-common')
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/ByteDataTranslator.java32
1 files changed, 31 insertions, 1 deletions
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/ByteDataTranslator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/ByteDataTranslator.java
index 17aff0e2e..d24157bf6 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/ByteDataTranslator.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/ByteDataTranslator.java
@@ -16,14 +16,17 @@
package io.fd.hc2vpp.common.translate.util;
+import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
- * Trait providing logic for working with binary-based data
+ * Trait providing logic for working with binary/hex-based data
*/
public interface ByteDataTranslator {
+ char[] HEX_CHARS = "0123456789abcdef".toCharArray();
+
ByteDataTranslator INSTANCE = new ByteDataTranslator() {
};
@@ -70,6 +73,8 @@ public interface ByteDataTranslator {
} else if (value == BYTE_TRUE) {
return Boolean.TRUE;
}
+
+ char[] HEX_CHARS = "0123456789abcdef".toCharArray();
throw new IllegalArgumentException(String.format("0 or 1 was expected but was %d", value));
}
@@ -90,6 +95,8 @@ public interface ByteDataTranslator {
}
/**
+
+ char[] HEX_CHARS = "0123456789abcdef".toCharArray();
* Return (interned) string from byte array while removing \u0000. Strings represented as fixed length byte[] from
* vpp contain \u0000.
*/
@@ -105,4 +112,27 @@ public interface ByteDataTranslator {
default int toJavaByte(final byte vppByte) {
return Byte.toUnsignedInt(vppByte);
}
+
+ default String printHexBinary(@Nonnull final byte[] bytes) {
+ Objects.requireNonNull(bytes, "bytes array should not be null");
+ return printHexBinary(bytes, 0, bytes.length);
+ }
+
+ default String printHexBinary(@Nonnull final byte[] bytes, final int startIndex, final int endIndex) {
+ StringBuilder str = new StringBuilder();
+
+ appendHexByte(str, bytes[startIndex]);
+ for (int i = startIndex + 1; i < endIndex; i++) {
+ str.append(":");
+ appendHexByte(str, bytes[i]);
+ }
+
+ return str.toString();
+ }
+
+ default void appendHexByte(final StringBuilder sb, final byte b) {
+ final int v = b & 0xFF;
+ sb.append(HEX_CHARS[v >>> 4]);
+ sb.append(HEX_CHARS[v & 15]);
+ }
}