/// <summary> /// Copy FRU String bytes out of Byte Array /// </summary> internal static FruByteString ReadByteString(byte language, byte[] data, int offset, out int nextOffset) { /* * The following presents the specification of the type/length byte. * 7:6 - type code * 00 - binary or unspecified * 01 - BCD plus (see below) * 10 - 6-bit ASCII, packed (overrides Language Codes) * 11 - Interpretation depends on Language Codes. 11b indicates 8-bit ASCII + Latin 1 if * the Language Code is English for the area or record containing the field, or 2-byte * UNICODE (least significant byte first) if the Language Code is not English. At least * two bytes of data must be present when this type is used. Therefore, the length * (number of data bytes) will always be >1 if data is present, 0 if data is not present. * 5:0 - number of data bytes. * 000000 indicates that the field is empty. When the type code is 11b, a length of * 000001 indicates 'end of fields'. I.e. Type/Length = C1h indicates 'end of fields'. */ byte lengthInfo = data[offset]; int length = lengthInfo & 0x3f; // 0011 1111 FruByteStringType encoding = (FruByteStringType)(lengthInfo >> 6); nextOffset = offset + 1 + length; byte[] readData = new byte[length]; if (data.Length >= nextOffset) { Array.Copy(data, offset + 1, readData, 0, length); } return(new FruByteString(language, encoding, readData)); }
private void Decode(byte language, byte[] data, FruByteStringType encoding) { switch (encoding) { case FruByteStringType.Binary: this.Text = IpmiSharedFunc.ByteArrayToHexString(data); break; case FruByteStringType.BcdPlus: this.Text = IpmiSharedFunc.DecodeBcdPlus(data); break; case FruByteStringType.Packed6BitAscii: data = ReplaceNonAsciiChars(data); this.Text = IpmiSharedFunc.DecodePacked6bitAscii(data); break; case FruByteStringType.Text: // replace non ASCII characters data = ReplaceNonAsciiChars(data); if ((this.Language == FruByteString.defaultLang) || (this.Language == FruByteString.EnLang)) { this.Text = System.Text.Encoding.ASCII.GetString(data).Trim(); } else { this.Text = System.Text.Encoding.Unicode.GetString(data).Trim(); } break; } }
protected FruByteString(byte language, FruByteStringType encoding, byte[] data) { this.Language = language; this.Data = data; this.Encoding = encoding; Decode(language, data, encoding); }