public static char ToValue(byte[] table, int index) { UnionChar bt = new UnionChar(); bt.SetBytes(table, index); return(bt.value); }
public static byte[] ToBytes(char val) { UnionChar bt = new UnionChar(); bt.value = val; return(bt.bytes); }
// Ex string : size = sizeof(short) + sizeof(char) * num public static byte[] ToBytes(string val) { short byteSize = (short)(val.Length * sizeof(char)); byte[] bt = new byte[byteSize + sizeof(short)]; int idx = 0; // Set ByteSize field UnionShort uniSize = new UnionShort(); uniSize.value = byteSize; bt[idx++] = uniSize.b0; bt[idx++] = uniSize.b1; // Set String field UnionChar uniCh = new UnionChar(); foreach (char ch in val.ToCharArray()) { uniCh.value = ch; foreach (byte b in uniCh.bytes) { bt[idx++] = b; } } return(bt); }
public static byte[] ToBytes(char val) { return(UnionChar.ToBytes(val)); }
public static int ToValue(out char ret, byte[] bytes, int index) { ret = UnionChar.ToValue(bytes, index); return(UnionChar.Size); }