本文整理汇总了C#中Brunet.Util.MemBlock.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# MemBlock.GetString方法的具体用法?C# MemBlock.GetString怎么用?C# MemBlock.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Brunet.Util.MemBlock
的用法示例。
在下文中一共展示了MemBlock.GetString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadString
public static string ReadString(MemBlock b, int offset, out int bytelength)
{
int null_idx = b.IndexOf(0, offset);
int raw_length = null_idx - offset;
bytelength = raw_length + 1; //One for the null
Encoding e;
/*
* Benchmarks of mono show this to be about twice as fast as just
* using UTF8. That really means UTF8 could be optimized in mono
*/
if( b.IsAscii(offset, raw_length) ) {
e = Encoding.ASCII;
} else {
e = Encoding.UTF8;
}
return b.GetString(e, offset, raw_length);
}
示例2: HandleData
virtual public void HandleData(MemBlock data, ISender return_path, object state)
{
Address addr = GetAddress(return_path);
if(addr == null) {
return;
}
_ondemand.Set(addr);
try {
_sub.Handle(data, return_path);
} catch {
string d_s = data.GetString(System.Text.Encoding.ASCII);
ProtocolLog.WriteIf(ProtocolLog.Exceptions, String.Format(
"Error handling packet from {0}, containing {1}",
return_path, d_s));
}
}