package com.inductiveautomation.opcua.stack.core.types.builtin;

import javax.annotation.Nullable;
import java.util.Arrays;

import com.google.common.base.Objects;

public class ByteString {

    public static final ByteString NullValue = new ByteString(null);

    private final byte[] bytes;

    public ByteString(@Nullable byte[] bytes) {
        this.bytes = bytes;
    }

    @Nullable
    public byte[] bytes() {
        return bytes;
    }

    public int length() {
        return bytes != null ? bytes.length : 0;
    }

    public boolean isNull() {
        return bytes == null;
    }

    public boolean isNotNull() {
        return bytes != null;
    }

    public static ByteString of(byte[] bs) {
        return new ByteString(bs);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ByteString that = (ByteString) o;

        return Arrays.equals(bytes, that.bytes);
    }

    @Override
    public int hashCode() {
        return bytes != null ? Arrays.hashCode(bytes) : 0;
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this)
                .add("bytes", Arrays.toString(bytes))
                .toString();
    }

}

@@ -156,16 +156,189 @@
 Objects;
+%0Aimport com.inductiveautomation.opcua.stack.core.types.builtin.unsigned.UByte;%0A%0Aimport static com.inductiveautomation.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte;
 %0A%0Apublic
@@ -913,32 +913,285 @@
 ing(bs);%0A    %7D%0A%0A
+    @Nullable%0A    public UByte%5B%5D uBytes() %7B%0A        if (bytes == null) return null;%0A%0A        UByte%5B%5D bs = new UByte%5Bbytes.length%5D;%0A        for (int i = 0; i %3C bytes.length; i++) %7B%0A            bs%5Bi%5D = ubyte(bytes%5Bi%5D);%0A        %7D%0A        return bs;%0A    %7D%0A%0A
     @Override%0A  

Add uBytes() helper to ByteString