Allows to specify matches, action parameters as strings in PI

Some PI elements can encode in their value a string (e.g., when
a P4Runtime translation is used), for this reason we allow users
to specify matches and action parameters as strings.
From southbound, during decode, we interpret the elements as
string if the P4 model suggests that.

Change-Id: I5884de1500437ab647abc200d65de442e23bd1a8
diff --git a/protocols/p4runtime/utils/src/main/java/org/onosproject/p4runtime/ctl/codec/PacketMetadataCodec.java b/protocols/p4runtime/utils/src/main/java/org/onosproject/p4runtime/ctl/codec/PacketMetadataCodec.java
index 3f78085..876f84c 100644
--- a/protocols/p4runtime/utils/src/main/java/org/onosproject/p4runtime/ctl/codec/PacketMetadataCodec.java
+++ b/protocols/p4runtime/utils/src/main/java/org/onosproject/p4runtime/ctl/codec/PacketMetadataCodec.java
@@ -17,6 +17,7 @@
 package org.onosproject.p4runtime.ctl.codec;
 
 import com.google.protobuf.ByteString;
+import org.onlab.util.ImmutableByteSequence;
 import org.onosproject.net.pi.model.PiPacketMetadataId;
 import org.onosproject.net.pi.model.PiPipeconf;
 import org.onosproject.net.pi.runtime.PiPacketMetadata;
@@ -54,14 +55,18 @@
             P4InfoOuterClass.Preamble ctrlPktMetaPreamble,
             PiPipeconf pipeconf, P4InfoBrowser browser)
             throws P4InfoBrowser.NotFoundException {
-        final String packetMetadataName = browser
-                .packetMetadatas(ctrlPktMetaPreamble.getId())
-                .getById(message.getMetadataId()).getName();
-        final PiPacketMetadataId metadataId = PiPacketMetadataId
-                .of(packetMetadataName);
+        final P4InfoOuterClass.ControllerPacketMetadata.Metadata packetMetadata =
+                browser.packetMetadatas(ctrlPktMetaPreamble.getId())
+                .getById(message.getMetadataId());
+        final ImmutableByteSequence value;
+        if (browser.isTypeString(packetMetadata.getTypeName())) {
+            value = copyFrom(new String(message.getValue().toByteArray()));
+        } else {
+            value = copyFrom(message.getValue().asReadOnlyByteBuffer());
+        }
         return PiPacketMetadata.builder()
-                .withId(metadataId)
-                .withValue(copyFrom(message.getValue().asReadOnlyByteBuffer()))
+                .withId(PiPacketMetadataId.of(packetMetadata.getName()))
+                .withValue(value)
                 .build();
     }
 }