package meerkat.util;

import com.google.protobuf.ByteString;

/**
 * Convert to/from Hex
 */
public class Hex {
    /**
     * Encode a {@link ByteString}  as a hex string.
     * @param str
     * @return
     */
    public static String encode(ByteString str) {
        StringBuilder s = new StringBuilder();
        for (byte b : str) {
            s.append(Integer.toHexString(((int) b) & 0xff));
        }
        return s.toString();
    }

    public static String encode(byte[] bytes) {
        return encode(ByteString.copyFrom(bytes));
    }
}

