public void TestStringEncoderEmptyString() { const int n = 10; var encoder = new StringEncoder(); for (int i = 0; i < n; i++) { encoder.Write(string.Empty); } var data = encoder.ToArray(); using var stream = new MemoryStream(data); var decoder = new StringDecoder(stream); for (int i = 0; i < n; i++) { Assert.AreEqual(string.Empty, decoder.Read()); } }
public override byte[] ToArray() { using var stream = new MemoryStream(); // Read the feature flag that might be used in the future. stream.WriteByte(0); // TODO: [alekseyk] Maybe pass the writer directly instead of using ToArray()? stream.WriteVarUint8Array(_keyClockEncoder.ToArray()); stream.WriteVarUint8Array(_clientEncoder.ToArray()); stream.WriteVarUint8Array(_leftClockEncoder.ToArray()); stream.WriteVarUint8Array(_rightClockEncoder.ToArray()); stream.WriteVarUint8Array(_infoEncoder.ToArray()); stream.WriteVarUint8Array(_stringEncoder.ToArray()); stream.WriteVarUint8Array(_parentInfoEncoder.ToArray()); stream.WriteVarUint8Array(_typeRefEncoder.ToArray()); stream.WriteVarUint8Array(_lengthEncoder.ToArray()); // Append the rest of the data from the RestWriter. // Note it's not the 'WriteVarUint8Array'. stream.Write(base.ToArray()); return(stream.ToArray()); }
public void TestStringEncoder() { const int n = 100; var words = new List <string>(n); var encoder = new StringEncoder(); for (int i = 0; i < n; i++) { var v = Guid.NewGuid().ToString(); words.Add(v); encoder.Write(v); } var data = encoder.ToArray(); using var stream = new MemoryStream(data); var decoder = new StringDecoder(stream); for (int i = 0; i < words.Count; i++) { Assert.AreEqual(words[i], decoder.Read()); } }