internal int ImportBinary(XMLElement elem, int offs, ByteBuffer buf, string fieldName) { if (elem == null || elem.IsNullValue()) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, -1); offs += 4; } else if (elem.IsStringValue()) { string hexStr = elem.GetStringValue(); int len = hexStr.Length; if (hexStr.StartsWith("#")) { buf.Extend(offs + 4 + len / 2 - 1); Bytes.Pack4(buf.arr, offs, -2 - GetHexValue(hexStr[1])); offs += 4; for (int j = 2; j < len; j += 2) { buf.arr[offs++] = (byte) ((GetHexValue(hexStr[j]) << 4) | GetHexValue(hexStr[j + 1])); } } else { buf.Extend(offs + 4 + len / 2); Bytes.Pack4(buf.arr, offs, len / 2); offs += 4; for (int j = 0; j < len; j += 2) { buf.arr[offs++] = (byte) ((GetHexValue(hexStr[j]) << 4) | GetHexValue(hexStr[j + 1])); } } } else { XMLElement ref_Renamed = elem.GetSibling("ref"); if (ref_Renamed != null) { buf.Extend(offs + 4); Bytes.Pack4(buf.arr, offs, MapId(GetIntAttribute(ref_Renamed, "id"))); offs += 4; } else { XMLElement item = elem.GetSibling("element"); int len = (item == null) ? 0 : item.Counter; buf.Extend(offs + 4 + len); Bytes.Pack4(buf.arr, offs, len); offs += 4; while (--len >= 0) { if (item.IsIntValue()) { buf.arr[offs] = (byte) item.GetIntValue(); } else if (item.IsRealValue()) { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. buf.arr[offs] = (byte) item.GetRealValue(); } else { ThrowException("Conversion for field " + fieldName + " is not possible"); } item = item.NextSibling; offs += 1; } } } return offs; }