当前位置: 首页>>代码示例>>C#>>正文


C# MemBlock.ToString方法代码示例

本文整理汇总了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);
      }
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:62,代码来源:AddressParser.cs


注:本文中的Brunet.Util.MemBlock.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。