static void AppendSpecial(Timestamp t, List <VTTQ> list) { list.Add(VTTQ.Make(DataValue.FromString(""), t + Duration.FromSeconds(10), t, Quality.Good)); list.Add(VTTQ.Make(DataValue.FromString("A"), t + Duration.FromSeconds(11), t, Quality.Good)); list.Add(VTTQ.Make(DataValue.FromString("Ä"), t + Duration.FromSeconds(18), t, Quality.Good)); list.Add(VTTQ.Make(DataValue.FromString("AB"), t + Duration.FromSeconds(19), t, Quality.Good)); list.Add(VTTQ.Make(DataValue.FromString("ÖÜÄ"), t + Duration.FromSeconds(30), t, Quality.Good)); list.Add(VTTQ.Make(DataValue.FromString(new string('P', 255)), t + Duration.FromSeconds(34), t, Quality.Good)); list.Add(VTTQ.Make(DataValue.FromString(new string('a', 500)), t + Duration.FromSeconds(38), t, Quality.Good)); list.Add(VTTQ.Make(DataValue.FromString(new string('ä', 9000)), t + Duration.FromMilliseconds(55005), t, Quality.Good)); list.Add(VTTQ.Make(DataValue.Empty, t + Duration.FromSeconds(30), t, Quality.Good)); }
static void AppendAllSame(Timestamp t, int n, List <VTTQ> list) { for (int i = 0; i < n; ++i) { var vtq = VTTQ.Make( DataValue.FromDouble(-17.1321), t + Duration.FromSeconds(10), t + Duration.FromSeconds(10), Quality.Bad); list.Add(vtq); } }
static void AppendSemiRegular(Timestamp t, int n, List <VTTQ> list) { for (int i = 0; i < n; ++i) { var vtq = VTTQ.Make( DataValue.FromDouble(0.54321 + i), t + Duration.FromSeconds(i * 60), t + Duration.FromSeconds(i * 60) + Duration.FromMilliseconds(i), Quality.Good); list.Add(vtq); } }
static void AppendRegular(Timestamp t, int n, List <VTTQ> list) { Random rand = new Random(78412); for (int i = 0; i < n; ++i) { var vtq = VTTQ.Make( DataValue.FromDouble(17.54321), t + Duration.FromSeconds(i * 5), t + Duration.FromSeconds(i * 5) + Duration.FromMilliseconds(2L * rand.Next(int.MinValue, int.MaxValue)), Quality.Good); list.Add(vtq); } }
static void AppendRandom(Timestamp t, int n, List <VTTQ> list) { Random rand = new Random(2808); for (int i = 0; i < n; ++i) { var tt = t + Duration.FromMilliseconds(i * rand.Next(0, 5000000)); var vtq = VTTQ.Make( DataValue.FromDouble(rand.NextDouble()), tt, tt + Duration.FromMilliseconds(-1 * (i)), Quality.Uncertain); list.Add(vtq); } }
public static List <VTTQ> Deserialize(BinaryReader reader) { int binaryVersion = reader.ReadByte(); if (binaryVersion == 0) { throw new IOException("Failed to deserialize VTTQ[]: Version byte is zero"); } if (binaryVersion > Common.CurrentBinaryVersion) { throw new IOException("Failed to deserialize VTTQ[]: Wrong version byte"); } if (reader.ReadByte() != Code) { throw new IOException("Failed to deserialize VTTQ[]: Wrong start byte"); } int N = reader.ReadInt32(); if (N > Common.MaxListLen) { throw new System.Exception($"VTTQ_Serializer: May not deserialize more than {Common.MaxListLen} items"); } var res = new List <VTTQ>(N); if (N == 0) { return(res); } long timeBase = reader.ReadInt64(); long diffBase = reader.ReadInt64(); string valBase = reader.ReadString(); char[] buffer = new char[255]; char[] mapCode2Char = Common.mapCode2Char; for (int k = 0; k < N; ++k) { int control = reader.ReadByte(); Quality q = (Quality)(control & 0x03); long time = timeBase; long diff = diffBase; string val = valBase; if ((control & 0x10) == 0) { long diffFactor = ((control & 0x20) == 0) ? 1 : 1000; int codeByteCount = (control & 0xC0) >> 6; if (codeByteCount == 0) { diff = diffFactor * reader.ReadSByte(); } else if (codeByteCount == 1) { diff = diffFactor * reader.ReadInt16(); } else if (codeByteCount == 2) { diff = diffFactor * reader.ReadInt32(); } else if (codeByteCount == 3) { diff = diffFactor * reader.ReadInt64(); } } time += diff; if ((control & 0x04) == 0) { if ((control & 0x08) == 0) { int countBytes = reader.ReadByte(); int j = 0; for (int i = 0; i < countBytes; i++) { int b = reader.ReadByte(); int b0 = (0xF0 & b) >> 4; int b1 = (0x0F & b); buffer[j++] = mapCode2Char[b0]; if (b1 == 0x0F) { break; } buffer[j++] = mapCode2Char[b1]; } val = new string(buffer, 0, j); } else { val = reader.ReadString(); } } long diffDB = 0; int diffControl = reader.ReadByte(); if ((diffControl & 0x80) == 0) { int abs = diffControl & 0x3F; diffDB = (diffControl & 0x40) == 0 ? abs : -abs; } else { long diffFactor = (diffControl & 0x40) == 0 ? 1 : -1; int codeByteCount = (diffControl & 0x30) >> 4; if (codeByteCount == 0) { diffDB = diffFactor * reader.ReadByte(); } else if (codeByteCount == 1) { diffDB = diffFactor * reader.ReadUInt16(); } else if (codeByteCount == 2) { diffDB = diffFactor * reader.ReadUInt32(); } else if (codeByteCount == 3) { diffDB = diffFactor * reader.ReadInt64(); } } res.Add(VTTQ.Make(DataValue.FromJSON(val), Timestamp.FromJavaTicks(time), Timestamp.FromJavaTicks(time + diffDB), q)); timeBase = time; diffBase = diff; valBase = val; } return(res); }