本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例6: AddArgsImpl
private void AddArgsImpl(
SimpleValHLSL val,
ref bool first,
Span span)
{
if (!first)
span.Write(", ");
first = false;
span.Write("{0}", val);
}
示例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);
}
示例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" ) );
}
示例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));
}
示例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());
}
示例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);
}
示例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();
}