本文整理汇总了C#中System.ByteBuffer.WriteBytes方法的典型用法代码示例。如果您正苦于以下问题:C# ByteBuffer.WriteBytes方法的具体用法?C# ByteBuffer.WriteBytes怎么用?C# ByteBuffer.WriteBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.WriteBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncodeObject
public override void EncodeObject(object value, bool arrayEncoding, ByteBuffer buffer)
{
if (arrayEncoding)
{
ArraySegment<byte> binaryValue = (ArraySegment<byte>)value;
AmqpBitConverter.WriteUInt(buffer, (uint)binaryValue.Count);
buffer.WriteBytes(binaryValue.Array, binaryValue.Offset, binaryValue.Count);
}
else
{
BinaryEncoding.Encode((ArraySegment<byte>)value, buffer);
}
}
示例2: Encode
public static void Encode(ArraySegment<byte> value, ByteBuffer buffer)
{
if (value.Array == null)
{
AmqpEncoding.EncodeNull(buffer);
}
else
{
int width = AmqpEncoding.GetEncodeWidthBySize(value.Count);
if (width == FixedWidth.UByte)
{
AmqpBitConverter.WriteUByte(buffer, (byte)FormatCode.Binary8);
AmqpBitConverter.WriteUByte(buffer, (byte)value.Count);
}
else
{
AmqpBitConverter.WriteUByte(buffer, (byte)FormatCode.Binary32);
AmqpBitConverter.WriteUInt(buffer, (uint)value.Count);
}
buffer.WriteBytes(value.Array, value.Offset, value.Count);
}
}
示例3: EncodeValue
unsafe static void EncodeValue(decimal value, ByteBuffer buffer)
{
int[] bits = Decimal.GetBits(value);
int lowSignificant = bits[0];
int middleSignificant = bits[1];
int highSignificant = bits[2];
int signAndExponent = bits[3];
byte[] bytes = new byte[FixedWidth.Decimal128];
byte *p = (byte*)&signAndExponent;
int exponent = Decimal128Bias - p[2];
bytes[0] = p[3]; // sign
bytes[0] |= (byte)(exponent >> 9); // 7 bits in msb
bytes[1] = (byte)((exponent & 0x7F) << 1); // 7 bits in 2nd msb
bytes[2] = 0;
bytes[3] = 0;
p = (byte*)&highSignificant;
bytes[4] = p[3];
bytes[5] = p[2];
bytes[6] = p[1];
bytes[7] = p[0];
p = (byte*)&middleSignificant;
bytes[8] = p[3];
bytes[9] = p[2];
bytes[10] = p[1];
bytes[11] = p[0];
p = (byte*)&lowSignificant;
bytes[12] = p[3];
bytes[13] = p[2];
bytes[14] = p[1];
bytes[15] = p[0];
buffer.WriteBytes(bytes, 0, bytes.Length);
}
示例4: PatchRawSection
void PatchRawSection(ByteBuffer buffer, MetadataBuilder metadata)
{
var position = base.position;
Align(4);
buffer.WriteBytes(base.position - position);
const byte fat_format = 0x40;
const byte more_sects = 0x80;
var flags = ReadByte();
if ((flags & fat_format) == 0)
{
buffer.WriteByte(flags);
PatchRawSmallSection(buffer, metadata);
}
else
PatchRawFatSection(buffer, metadata);
if ((flags & more_sects) != 0)
PatchRawSection(buffer, metadata);
}
示例5: PatchRawExceptionHandlers
void PatchRawExceptionHandlers(ByteBuffer buffer, MetadataBuilder metadata, int count, bool fat_entry)
{
const int fat_entry_size = 16;
const int small_entry_size = 6;
for (int i = 0; i < count; i++)
{
ExceptionHandlerType handler_type;
if (fat_entry)
{
var type = ReadUInt32();
handler_type = (ExceptionHandlerType)(type & 0x7);
buffer.WriteUInt32(type);
}
else
{
var type = ReadUInt16();
handler_type = (ExceptionHandlerType)(type & 0x7);
buffer.WriteUInt16(type);
}
buffer.WriteBytes(ReadBytes(fat_entry ? fat_entry_size : small_entry_size));
switch (handler_type)
{
case ExceptionHandlerType.Catch:
var exception = reader.LookupToken(ReadToken());
buffer.WriteUInt32(metadata.LookupToken(exception).ToUInt32());
break;
default:
buffer.WriteUInt32(ReadUInt32());
break;
}
}
}
示例6: PatchRawCode
void PatchRawCode(ByteBuffer buffer, int code_size, CodeWriter writer)
{
var metadata = writer.metadata;
buffer.WriteBytes(ReadBytes(code_size));
var end = buffer.position;
buffer.position -= code_size;
while (buffer.position < end)
{
OpCode opcode;
var il_opcode = buffer.ReadByte();
if (il_opcode != 0xfe)
{
opcode = OpCodes.OneByteOpCode[il_opcode];
}
else
{
var il_opcode2 = buffer.ReadByte();
opcode = OpCodes.TwoBytesOpCode[il_opcode2];
}
switch (opcode.OperandType)
{
case OperandType.ShortInlineI:
case OperandType.ShortInlineBrTarget:
case OperandType.ShortInlineVar:
case OperandType.ShortInlineArg:
buffer.position += 1;
break;
case OperandType.InlineVar:
case OperandType.InlineArg:
buffer.position += 2;
break;
case OperandType.InlineBrTarget:
case OperandType.ShortInlineR:
case OperandType.InlineI:
buffer.position += 4;
break;
case OperandType.InlineI8:
case OperandType.InlineR:
buffer.position += 8;
break;
case OperandType.InlineSwitch:
var length = buffer.ReadInt32();
buffer.position += length * 4;
break;
case OperandType.InlineString:
var @string = GetString(new MetadataToken(buffer.ReadUInt32()));
buffer.position -= 4;
buffer.WriteUInt32(
new MetadataToken(
TokenType.String,
metadata.user_string_heap.GetStringIndex(@string)).ToUInt32());
break;
case OperandType.InlineSig:
var call_site = GetCallSite(new MetadataToken(buffer.ReadUInt32()));
buffer.position -= 4;
buffer.WriteUInt32(writer.GetStandAloneSignature(call_site).ToUInt32());
break;
case OperandType.InlineTok:
case OperandType.InlineType:
case OperandType.InlineMethod:
case OperandType.InlineField:
var provider = reader.LookupToken(new MetadataToken(buffer.ReadUInt32()));
buffer.position -= 4;
buffer.WriteUInt32(metadata.LookupToken(provider).ToUInt32());
break;
}
}
}