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


C# Span.Write方法代码示例

本文整理汇总了C#中Span.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Span.Write方法的具体用法?C# Span.Write怎么用?C# Span.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Span的用法示例。


在下文中一共展示了Span.Write方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryEncodeCodePoint

        public static bool TryEncodeCodePoint(UnicodeCodePoint codePoint, Span<byte> buffer, out int encodedBytes)
        {
            if (!UnicodeCodePoint.IsSupportedCodePoint(codePoint))
            {
                encodedBytes = default(int);
                return false;
            }

            // TODO: Can we add this in UnicodeCodePoint class?
            // Should be represented as Surrogate?
            encodedBytes = ((uint)codePoint >= 0x10000) ? 4 : 2;

            if (buffer.Length < encodedBytes)
            {
                codePoint = default(UnicodeCodePoint);
                encodedBytes = default(int);
                // buffer too small
                return false;
            }

            if (encodedBytes == 2)
            {
                unchecked
                {
                    buffer.Write((ushort)codePoint);
                }
            }
            else
            {
                unchecked
                {
                    uint highSurrogate = ((uint)codePoint >> 10) + UnicodeConstants.Utf16HighSurrogateFirstCodePoint;
                    uint lowSurrogate = ((uint)codePoint & MaskLow10Bits) + UnicodeConstants.Utf16LowSurrogateFirstCodePoint;

                    buffer.Write(highSurrogate | (lowSurrogate << 16));
                }
            }
            return true;
        }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:39,代码来源:Utf16LittleEndianEncoder.cs

示例2: TryEncodeCodePoint

        public static bool TryEncodeCodePoint(UnicodeCodePoint codePoint, Span<byte> buffer, out int encodedBytes)
        {
            if (!UnicodeCodePoint.IsSupportedCodePoint(codePoint))
            {
                encodedBytes = default(int);
                return false;
            }

            encodedBytes = UnicodeCodePoint.IsBmp(codePoint) ? 2 : 4;

            if (buffer.Length < encodedBytes)
            {
                codePoint = default(UnicodeCodePoint);
                encodedBytes = default(int);
                // buffer too small
                return false;
            }

            if (encodedBytes == 2)
            {
                unchecked
                {
                    buffer.Write((ushort)codePoint);
                }
            }
            else
            {
                unchecked
                {
                    uint codePointValue = (uint)codePoint;
                    uint highSurrogate = ((codePointValue - 0x010000u) >> 10) + UnicodeConstants.Utf16HighSurrogateFirstCodePoint;
                    uint lowSurrogate = (codePointValue & MaskLow10Bits) + UnicodeConstants.Utf16LowSurrogateFirstCodePoint;
                    buffer.Write(highSurrogate | (lowSurrogate << 16));
                }
            }
            return true;
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:37,代码来源:Utf16LittleEndianEncoder.cs

示例3: TryEncodeCodePoint

        public static bool TryEncodeCodePoint(UnicodeCodePoint codePoint, Span<byte> buffer, out int encodedBytes)
        {
            if (!UnicodeCodePoint.IsSupportedCodePoint(codePoint))
            {
                encodedBytes = 0;
                return false;
            }

            encodedBytes = GetNumberOfEncodedBytes(codePoint);
            if (encodedBytes > buffer.Length)
            {
                encodedBytes = 0;
                return false;
            }

            switch (encodedBytes)
            {
                case 1:
                    buffer[0] = (byte)(b0111_1111U & codePoint.Value);
                    return true;
                case 2:
                    byte b0 = (byte)(((codePoint.Value >> 6) & b0001_1111U) | b1100_0000U);
                    byte b1 = (byte)(((codePoint.Value >> 0) & b0011_1111U) | b1000_0000U);
                    buffer.Write((ushort)(b0 | b1 << 8));
                    return true;
                case 3:
                    b0 = (byte)(((codePoint.Value >> 12) & b0000_1111U) | b1110_0000U);
                    b1 = (byte)(((codePoint.Value >> 6) & b0011_1111U) | b1000_0000U);
                    buffer.Write((ushort)(b0 | b1 << 8));
                    buffer[2] = (byte)(((codePoint.Value >> 0) & b0011_1111U) | b1000_0000U);
                    return true;
                case 4:
                    b0 = (byte)(((codePoint.Value >> 18) & b0000_0111U) | b1111_0000U);
                    b1 = (byte)(((codePoint.Value >> 12) & b0011_1111U) | b1000_0000U);
                    byte b2 = (byte)(((codePoint.Value >> 6) & b0011_1111U) | b1000_0000U);
                    byte b3 = (byte)(((codePoint.Value >> 0) & b0011_1111U) | b1000_0000U);
                    buffer.Write((uint)(b0 | b1 << 8 | b2 << 16 | b3 << 24));
                    return true;
                default:
                    return false;
            }
        }
开发者ID:antiufo,项目名称:Shaman.ValueString,代码行数:42,代码来源:Utf8Encoder.cs

示例4: EmitExpImpl

        private EmitValHLSL EmitExpImpl(MidMethodApp app, Span span)
        {
            // Make sure we've emitted the method.
            var method = GetMethod(app.MethodDecl);

            Span builder = new Span();
            builder.Write("{0}(", method);

            var resultType = EmitType(app.MethodDecl.ResultType);
            var resultVar = resultType.CreateVal(
                _shared.GenerateName(app.MethodDecl.Name.ToString()));

            DeclareLocal(resultVar, span);

            bool first = true;
            AddArgs(
                resultVar,
                ref first,
                builder);

            foreach (var a in app.Args)
            {
                var argVal = EmitVal(a, span);
                AddArgs(
                    argVal,
                    ref first,
                    builder);
            }
            builder.WriteLine(");");

            span.Add(builder);
            return resultVar;
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:33,代码来源:EmitContextHLSL.cs

示例5: DeclareParam

        // Declare function parameters
        private void DeclareParam(
            EmitValHLSL val,
            string prefix,
            string semantic,
            ref bool first,
            Span span)
        {
            var decls = DeclareBase(
                val,
                prefix,
                semantic,
                "");

            foreach (var d in decls)
            {
                if (!first)
                    span.WriteLine(",");
                first = false;
                span.Write(d);
            }
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:22,代码来源:EmitContextHLSL.cs

示例6: AddArgsImpl

        private void AddArgsImpl(
            SimpleValHLSL val,
            ref bool first,
            Span span)
        {
            if (!first)
                span.Write(", ");
            first = false;

            span.Write("{0}", val);
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:11,代码来源:EmitContextHLSL.cs

示例7: Array

        public IEmitVal Array(
            IEmitType elementType,
            IEmitVal[] elements)
        {
            var span = new Span();
            span.WriteLine("{");
            foreach (var e in elements)
            {
                span.WriteLine("\t{0},", e);
            }
            span.Write("}");

            return new EmitValCPP(
                Target,
                span.ToString(),
                Target.Array(elementType, elements.Length),
                true);
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:18,代码来源:EmitTargetCPP.cs

示例8: EmitGlobalStruct

        public IEmitVal EmitGlobalStruct(
            string name,
            IEmitVal[] members )
        {
            var span = new Span();

            name = string.Format(
                "_spark_global_{0}{1}",
                name ?? "",
                _globalCounter++ );

            span.WriteLine( "struct {" );
            var typeSpan = span.IndentSpan();
            for( int ii = 0; ii < members.Length; ++ii )
            {
                var memberType = (EmitTypeCPP) members[ii].Type;
                typeSpan.WriteLine( "{0};", memberType.Declare( string.Format( "_m{0}", ii ) ) );
            }
            span.WriteLine( "}} {0} = {{", name);
            for( int ii = 0; ii < members.Length; ++ii )
            {
                if( ii != 0 )
                    span.WriteLine( "," );
                span.Write( members[ ii ].ToString() );
            }
            span.WriteLine( " };" );

            _sourceSpan.Add( span );

            return new EmitValCPP(
                Target,
                name,
                Target.GetOpaqueType( "void" ) );
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:34,代码来源:EmitTargetCPP.cs

示例9: WriteParameter

        public void WriteParameter(
            IEmitType type,
            string name,
            bool first,
            Span span)
        {
            if (!first)
                span.Write(",");
            span.WriteLine();

            span.Write(((IEmitTypeCPP) type).Declare(name));
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:12,代码来源:EmitTargetCPP.cs

示例10: EmitMethodCPP

        public EmitMethodCPP(
            EmitClassCPP clazz,
            string prefix,
            string name,
            string cconv,
            IEmitType resultType,
            Span headerSpan,
            Span sourceSpan)
        {
            _class = clazz;
            _name = name;
            _cconv = cconv;
            _resultType = resultType;
            _headerSpan = headerSpan;
            _sourceSpan = sourceSpan;

            _headerSpan.Write( "static " );
            _headerParamsSpan = CreateSignatureSpan(
                _name,
                _headerSpan);
            _headerSpan.WriteLine(";");

            _fullName = prefix + _name;

            _sourceParamsSpan = CreateSignatureSpan(
                prefix + _name,
                _sourceSpan);
            _sourceSpan.WriteLine();
            _sourceSpan.WriteLine("{");
            _bodySpan = _sourceSpan.IndentSpan();
            _sourceSpan.WriteLine("}");

            _thisParameter = (EmitValCPP) AddParameter(
                Target.Pointer( clazz ),
                "self" );
            _entryBlock = new EmitBlockCPP(this, _bodySpan.InsertSpan());
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:37,代码来源:EmitTargetCPP.cs

示例11: Struct

        public IEmitVal Struct(
            string structTypeName,
            params IEmitVal[] fields)
        {
            var structType = Target.GetBuiltinType(structTypeName);

            var span = new Span();
            span.WriteLine("{");
            foreach (var f in fields)
            {
                span.WriteLine("\t{0},", f);
            }
            span.Write("}");

            return new EmitValCPP(
                Target,
                span.ToString(),
                structType);
        }
开发者ID:spark-shading-language,项目名称:spark,代码行数:19,代码来源:EmitTargetCPP.cs

示例12: ConvertSpanToBytes

 private byte[] ConvertSpanToBytes(Span span)
 {
     var buf = new MemoryStream();
     TProtocol protocol = protocolFactory.GetProtocol(new TStreamTransport(buf, buf));
     span.Write(protocol);
     return buf.ToArray();
 }
开发者ID:theburningmonk,项目名称:Medidata.ZipkinTracerModule,代码行数:7,代码来源:SpanProcessor.cs


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