本文整理汇总了C#中Brunet.Util.MemBlock.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MemBlock.ToString方法的具体用法?C# MemBlock.ToString怎么用?C# MemBlock.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Brunet.Util.MemBlock
的用法示例。
在下文中一共展示了MemBlock.ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/**
* Read the address out of the buffer This makes a copy
* and calls Parse on the copy. This is a "convienience" method.
* @throw ParseException if the buffer is not a valid address
*/
static public Address Parse(MemBlock mb)
{
#if BRUNET_SIMULATOR
Address a = null;
#else
//Read some of the least significant bytes out,
//AHAddress all have last bit 0, so we skip the last byte which
//will have less entropy
ushort idx = (ushort)NumberSerializer.ReadShort(mb, Address.MemSize - 3);
Address a = _mb_cache[idx];
if( a != null ) {
if( a.ToMemBlock().Equals(mb) ) {
return a;
}
}
#endif
//Else we need to read the address and put it in the cache
try {
if( 2 * mb.Length < mb.ReferencedBufferLength ) {
/*
* This MemBlock is much smaller than the array
* we are referencing, don't keep the big one
* in scope, instead make a copy
*/
mb = MemBlock.Copy((ICopyable)mb);
}
int add_class = Address.ClassOf(mb);
switch (add_class) {
case AHAddress.ClassValue:
a = new AHAddress(mb);
break;
case DirectionalAddress.ClassValue:
a = new DirectionalAddress(mb);
break;
default:
a = null;
throw new ParseException("Unknown Address Class: " +
add_class + ", buffer:" +
mb.ToString());
}
#if BRUNET_SIMULATOR
return SimulatorCache(a);
#else
//Cache this result:
_mb_cache[ idx ] = a;
return a;
#endif
}
catch(ArgumentOutOfRangeException ex) {
throw new ParseException("Address too short: " +
mb.ToString(), ex);
}
catch(ArgumentException ex) {
throw new ParseException("Could not parse: " +
mb.ToString(), ex);
}
}