package com.novadart.reactnativenfc.parser;

import android.nfc.Tag;

import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
import com.novadart.reactnativenfc.NfcDataType;

public class TagParser {

    public static WritableMap parse(Tag tag){
        WritableMap result = new WritableNativeMap();

        result.putString("type", NfcDataType.TAG.name());

        WritableMap data = new WritableNativeMap();

        WritableArray techList = new WritableNativeArray();
        String[] techListStr = tag.getTechList();
        if(techListStr != null){
            for (String s: techListStr) {
                techList.pushString(s);
            }
        }

        data.putArray("techList",techList);
        data.putString("description",tag.toString());
        data.putString("id",ByteArrayToHexString(tag.getId()));
        result.putMap("data",data);
        return result;
    }

    public static String ByteArrayToHexString(byte[] inarray) {
        int i, j, in;
        String[] hex = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
        String out = "";

        for (j = 0; j < inarray.length; ++j) {
            in = (int) inarray[j] & 0xff;
            i = (in >> 4) & 0x0f;
            out += hex[i];
            i = in & 0x0f;
            out += hex[i];
        }
        return out;
    }


}

@@ -927,16 +927,24 @@
 ng(%22id%22,
+ convert
 ByteArra
@@ -1038,29 +1038,30 @@
     %7D%0A%0A    p
-ublic
+rivate
  static Stri
@@ -1063,16 +1063,23 @@
  String 
+convert
 ByteArra

rename method