static public byte[] Unpack(byte[] iBuf) { var PureMemStream = new MemoryStream(iBuf); var MS = new QuickStream(PureMemStream); if (MS.ReadString(6) != "JXSDA\x1a") { Fout("Data is not JXSDA packed data"); return(null); } var ubit = MS.ReadByte(); var pbit = MS.ReadByte(); var rest = MS.ReadByte(); var dsiz = MS.ReadInt(); var dict = new Dictionary <long, long>(); var restbank = new List <byte>(); P($"Unpack data: ubit:{ubit}; pbit:{pbit}; rest:{rest}; dsiz:{dsiz}"); for (int i = 0; i < dsiz; ++i) { switch (ubit) { case 64: dict[i] = MS.ReadLong(); break; case 32: dict[i] = MS.ReadInt(); break; case 16: dict[i] = MS.ReadShort(); break; default: Fout($"Invalid ubit value {ubit} while reading dictionary"); return(null); } } for (byte i = 0; i < rest; i++) { restbank.Add(MS.ReadByte()); } var UPWrite = new MemoryStream(); var U = new QuickStream(UPWrite); while (!MS.EOF) { try { long value = 0; switch (pbit) { case 32: value = MS.ReadInt(); break; case 16: value = MS.ReadShort(); break; case 8: value = MS.ReadByte(); break; default: Fout($"Invalud pbit value {pbit} in reading bytes to unpack"); break; } if (!dict.ContainsKey(value)) { Fout($"Undefined dictionary index {value}/{value:X2}"); return(null); } switch (ubit) { case 64: U.WriteLong(dict[value]); break; case 32: U.WriteInt((int)dict[value]); break; case 16: U.WriteShort((short)dict[value]); break; default: Fout($"Invalud ubit value ({ubit}) in writing bytes in unpacking"); return(null); } } catch (Exception e) { Fout($".NET error unpacking: {e.Message}"); return(null); } } foreach (byte b in restbank) { U.WriteByte(b); } var result = UPWrite.ToArray(); MS.Close(); U.Close(); return(result); // temp }