VOL-3705 Create option in kafka-topic-export to report ONU serial no in metrics in Hex format instead of ASCII chars

Change-Id: Id54f729efe4f9fee2accb3b18e97328b5e5db1ca
diff --git a/utils/utils.go b/utils/utils.go
new file mode 100644
index 0000000..cc0337a
--- /dev/null
+++ b/utils/utils.go
@@ -0,0 +1,42 @@
+// Copyright 2018 Open Networking Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//Package utils gives type conversion helpers
+package utils
+
+import (
+	"encoding/hex"
+	"gerrit.opencord.org/kafka-topic-exporter/common/logger"
+	"strings"
+)
+
+var OnuSNhex bool
+
+//OnuSnHexEncode converts ONU sn from human readable format like 'SCOM00001B6D' to hex like '53434F4D00001B6D'
+func OnuSnHexEncode(onuSn string) ( string) {
+        if len(onuSn) != 12 {
+                logger.Warn("ignoring serial to hex encode, 12 chars are expected for onuSn but %d are provided", len(onuSn))
+                return onuSn
+        }
+
+        output := hex.EncodeToString([]byte(onuSn[0:4])) + onuSn[4:12]
+        return strings.ToUpper(output)
+}
+
+func GetOnuSN(onuSN string) (string) {
+	if OnuSNhex  {
+                return OnuSnHexEncode(onuSN)
+        } else {
+                return onuSN
+        }
+}