本文整理汇总了C#中System.IO.BinaryWriter.Write7BitEncodedInt方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.Write7BitEncodedInt方法的具体用法?C# BinaryWriter.Write7BitEncodedInt怎么用?C# BinaryWriter.Write7BitEncodedInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryWriter
的用法示例。
在下文中一共展示了BinaryWriter.Write7BitEncodedInt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public void Save(Stream stream)
{
using (var bw = new BinaryWriter(stream, Encoding.UTF8, leaveOpen: true))
{
// 1337 - signature that this is us
bw.Write7BitEncodedInt(1337);
bw.Write7BitEncodedInt(1); // version
bw.Write7BitEncodedInt(_dictionary.Length);
bw.Write(_dictionary);
_packer.Save(bw);
}
}
示例2: Save
public void Save(BinaryWriter writer)
{
symbols.Save(writer);
writer.Write7BitEncodedInt(offsets.Length);
foreach (var offset in offsets)
{
offset.Save(writer);
}
}
示例3: SaveLicense
/// <summary>
/// Saves the license.
/// </summary>
public static void SaveLicense(string user, string key, byte[] license)
{
var licfile = Path.Combine(AppDataPath, ".license");
var xkey = ProtectedData.Protect(Encoding.UTF8.GetBytes(key), null, DataProtectionScope.LocalMachine);
var lic = ProtectedData.Protect(license, null, DataProtectionScope.LocalMachine);
using (var fs = File.Create(licfile))
using (var bw = new BinaryWriter(fs))
{
bw.Write((byte)Utils.Rand.Next(0, 200));
bw.Write(user);
bw.Write7BitEncodedInt(xkey.Length);
bw.Write(xkey);
bw.Write7BitEncodedInt(lic.Length);
bw.Write(lic);
}
}
示例4: ReadCorruptedJournalFile
public void ReadCorruptedJournalFile()
{
string path = Path.GetFullPath("TestData\\ReadCorruptedJournal");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
JournalWriter jw = new JournalWriter(path, 324, false);
List<KeyValuePair<Key, Value>> items = new List<KeyValuePair<Key, Value>>();
for (int i = 0; i < 10; i++) {
Key randKey = Key.Random(20);
Value randValue = Value.Random(100);
jw.Add(randKey, randValue);
items.Add(new KeyValuePair<Key, Value>(randKey, randValue));
}
jw.Close();
// Reopen the file and add a partial record
var fileName = Config.JournalFile(path, 324);
var writer = new BinaryWriter(new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.None, 1024, false));
Key key = Key.Random(20);
writer.Write7BitEncodedInt(key.Length);
writer.Write(key.InternalBytes);
writer.Write7BitEncodedInt(0);
writer.Flush();
writer.Close();
JournalReader jr = new JournalReader(path, 324);
int j = 0;
foreach (var pair in jr.Enumerate()) {
Assert.AreEqual(items[j].Key, pair.Key);
Assert.AreEqual(items[j].Value, pair.Value);
j++;
}
jr.Close();
}
示例5: WriteMetadata
void WriteMetadata()
{
MemoryStream ms = new MemoryStream ();
BinaryWriter writer = new BinaryWriter (ms);
writer.Write (Encoding.ASCII.GetBytes ("@RAZORDB"));
writer.Write7BitEncodedInt (totalBlocks + 1);
writer.Write7BitEncodedInt (dataBlocks);
writer.Write7BitEncodedInt (indexBlocks);
byte[] metadata = ms.ToArray ();
Array.Copy (metadata, _buffer, metadata.Length);
// Commit the block to disk and wait for the operation to complete
WriteBlock ();
_fileStream.EndWrite (_async);
}