Lines Matching refs:buffer

56         public static void WriteDouble(ref Span<byte> buffer, ref WriterInternalState state, double value)
58 WriteRawLittleEndian64(ref buffer, ref state, (ulong)BitConverter.DoubleToInt64Bits(value));
64 public static unsafe void WriteFloat(ref Span<byte> buffer, ref WriterInternalState state, float value)
67 if (buffer.Length - state.position >= length)
69 // if there's enough space in the buffer, write the float directly into the buffer
70 var floatSpan = buffer.Slice(state.position, length);
81 WriteFloatSlowPath(ref buffer, ref state, value);
86 private static unsafe void WriteFloatSlowPath(ref Span<byte> buffer, ref WriterInternalState state, float value)
98 WriteRawByte(ref buffer, ref state, floatSpan[0]);
99 WriteRawByte(ref buffer, ref state, floatSpan[1]);
100 WriteRawByte(ref buffer, ref state, floatSpan[2]);
101 WriteRawByte(ref buffer, ref state, floatSpan[3]);
107 public static void WriteUInt64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
109 WriteRawVarint64(ref buffer, ref state, value);
115 public static void WriteInt64(ref Span<byte> buffer, ref WriterInternalState state, long value)
117 WriteRawVarint64(ref buffer, ref state, (ulong)value);
123 public static void WriteInt32(ref Span<byte> buffer, ref WriterInternalState state, int value)
127 WriteRawVarint32(ref buffer, ref state, (uint)value);
132 WriteRawVarint64(ref buffer, ref state, (ulong)value);
139 public static void WriteFixed64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
141 WriteRawLittleEndian64(ref buffer, ref state, value);
147 public static void WriteFixed32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
149 WriteRawLittleEndian32(ref buffer, ref state, value);
155 public static void WriteBool(ref Span<byte> buffer, ref WriterInternalState state, bool value)
157 WriteRawByte(ref buffer, ref state, value ? (byte)1 : (byte)0);
164 public static void WriteString(ref Span<byte> buffer, ref WriterInternalState state, string value)
167 // the string directly to the buffer, which should be common.
169 WriteLength(ref buffer, ref state, length);
170 if (buffer.Length - state.position >= length)
176 buffer[state.position + i] = (byte)value[i];
185 WriteRawBytes(ref buffer, ref state, bytes);
192 fixed (byte* destinationBytes = &MemoryMarshal.GetReference(buffer.Slice(state.position)))
194 bytesUsed = Utf8Encoding.GetBytes(sourceChars, source.Length, destinationBytes, buffer.Length);
204 // Large strings that don't fit into the current buffer segment
208 WriteRawBytes(ref buffer, ref state, bytes);
216 public static void WriteBytes(ref Span<byte> buffer, ref WriterInternalState state, ByteString value)
218 WriteLength(ref buffer, ref state, value.Length);
219 WriteRawBytes(ref buffer, ref state, value.Span);
225 public static void WriteUInt32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
227 WriteRawVarint32(ref buffer, ref state, value);
233 public static void WriteEnum(ref Span<byte> buffer, ref WriterInternalState state, int value)
235 WriteInt32(ref buffer, ref state, value);
241 public static void WriteSFixed32(ref Span<byte> buffer, ref WriterInternalState state, int value)
243 WriteRawLittleEndian32(ref buffer, ref state, (uint)value);
249 public static void WriteSFixed64(ref Span<byte> buffer, ref WriterInternalState state, long value)
251 WriteRawLittleEndian64(ref buffer, ref state, (ulong)value);
257 public static void WriteSInt32(ref Span<byte> buffer, ref WriterInternalState state, int value)
259 WriteRawVarint32(ref buffer, ref state, EncodeZigZag32(value));
265 public static void WriteSInt64(ref Span<byte> buffer, ref WriterInternalState state, long value)
267 WriteRawVarint64(ref buffer, ref state, EncodeZigZag64(value));
276 public static void WriteLength(ref Span<byte> buffer, ref WriterInternalState state, int length)
278 WriteRawVarint32(ref buffer, ref state, (uint)length);
286 /// there's enough buffer space left to whizz through without checking
289 public static void WriteRawVarint32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
292 if (value < 128 && state.position < buffer.Length)
294 buffer[state.position++] = (byte)value;
299 while (state.position < buffer.Length)
303 buffer[state.position++] = (byte)((value & 0x7F) | 0x80);
308 buffer[state.position++] = (byte)value;
315 WriteRawByte(ref buffer, ref state, (byte)((value & 0x7F) | 0x80));
319 WriteRawByte(ref buffer, ref state, (byte)value);
322 public static void WriteRawVarint64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
325 if (value < 128 && state.position < buffer.Length)
327 buffer[state.position++] = (byte)value;
332 while (state.position < buffer.Length)
336 buffer[state.position++] = (byte)((value & 0x7F) | 0x80);
341 buffer[state.position++] = (byte)value;
348 WriteRawByte(ref buffer, ref state, (byte)((value & 0x7F) | 0x80));
352 WriteRawByte(ref buffer, ref state, (byte)value);
355 public static void WriteRawLittleEndian32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
358 if (state.position + length > buffer.Length)
360 WriteRawLittleEndian32SlowPath(ref buffer, ref state, value);
364 BinaryPrimitives.WriteUInt32LittleEndian(buffer.Slice(state.position), value);
370 private static void WriteRawLittleEndian32SlowPath(ref Span<byte> buffer, ref WriterInternalState state, uint value)
372 WriteRawByte(ref buffer, ref state, (byte)value);
373 WriteRawByte(ref buffer, ref state, (byte)(value >> 8));
374 WriteRawByte(ref buffer, ref state, (byte)(value >> 16));
375 WriteRawByte(ref buffer, ref state, (byte)(value >> 24));
378 public static void WriteRawLittleEndian64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
381 if (state.position + length > buffer.Length)
383 WriteRawLittleEndian64SlowPath(ref buffer, ref state, value);
387 BinaryPrimitives.WriteUInt64LittleEndian(buffer.Slice(state.position), value);
393 public static void WriteRawLittleEndian64SlowPath(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
395 WriteRawByte(ref buffer, ref state, (byte)value);
396 WriteRawByte(ref buffer, ref state, (byte)(value >> 8));
397 WriteRawByte(ref buffer, ref state, (byte)(value >> 16));
398 WriteRawByte(ref buffer, ref state, (byte)(value >> 24));
399 WriteRawByte(ref buffer, ref state, (byte)(value >> 32));
400 WriteRawByte(ref buffer, ref state, (byte)(value >> 40));
401 WriteRawByte(ref buffer, ref state, (byte)(value >> 48));
402 WriteRawByte(ref buffer, ref state, (byte)(value >> 56));
405 private static void WriteRawByte(ref Span<byte> buffer, ref WriterInternalState state, byte value)
407 if (state.position == buffer.Length)
409 WriteBufferHelper.RefreshBuffer(ref buffer, ref state);
412 buffer[state.position++] = value;
418 public static void WriteRawBytes(ref Span<byte> buffer, ref WriterInternalState state, byte[] value)
420 WriteRawBytes(ref buffer, ref state, new ReadOnlySpan<byte>(value));
426 public static void WriteRawBytes(ref Span<byte> buffer, ref WriterInternalState state, byte[] value, int offset, int length)
428 WriteRawBytes(ref buffer, ref state, new ReadOnlySpan<byte>(value, offset, length));
434 public static void WriteRawBytes(ref Span<byte> buffer, ref WriterInternalState state, ReadOnlySpan<byte> value)
436 if (buffer.Length - state.position >= value.Length)
438 // We have room in the current buffer.
439 value.CopyTo(buffer.Slice(state.position, value.Length));
445 // copying the data twice (first copying to the current buffer and
446 // and later writing from the current buffer to the underlying Stream)
451 while (buffer.Length - state.position < value.Length - bytesWritten)
453 int length = buffer.Length - state.position;
454 value.Slice(bytesWritten, length).CopyTo(buffer.Slice(state.position, length));
457 WriteBufferHelper.RefreshBuffer(ref buffer, ref state);
462 value.Slice(bytesWritten, remainderLength).CopyTo(buffer.Slice(state.position, remainderLength));
472 public static void WriteTag(ref Span<byte> buffer, ref WriterInternalState state, int fieldNumber, WireFormat.WireType type)
474 WriteRawVarint32(ref buffer, ref state, WireFormat.MakeTag(fieldNumber, type));
480 public static void WriteTag(ref Span<byte> buffer, ref WriterInternalState state, uint tag)
482 WriteRawVarint32(ref buffer, ref state, tag);
488 public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1)
490 WriteRawByte(ref buffer, ref state, b1);
496 public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2)
498 if (state.position + 2 > buffer.Length)
500 WriteRawTagSlowPath(ref buffer, ref state, b1, b2);
504 buffer[state.position++] = b1;
505 buffer[state.position++] = b2;
510 private static void WriteRawTagSlowPath(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2)
512 WriteRawByte(ref buffer, ref state, b1);
513 WriteRawByte(ref buffer, ref state, b2);
519 public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2, byte b3)
521 if (state.position + 3 > buffer.Length)
523 WriteRawTagSlowPath(ref buffer, ref state, b1, b2, b3);
527 buffer[state.position++] = b1;
528 buffer[state.position++] = b2;
529 buffer[state.position++] = b3;
534 private static void WriteRawTagSlowPath(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2, byte b3)
536 WriteRawByte(ref buffer, ref state, b1);
537 WriteRawByte(ref buffer, ref state, b2);
538 WriteRawByte(ref buffer, ref state, b3);
544 public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4)
546 if (state.position + 4 > buffer.Length)
548 WriteRawTagSlowPath(ref buffer, ref state, b1, b2, b3, b4);
552 buffer[state.position++] = b1;
553 buffer[state.position++] = b2;
554 buffer[state.position++] = b3;
555 buffer[state.position++] = b4;
561 private static void WriteRawTagSlowPath(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4)
563 WriteRawByte(ref buffer, ref state, b1);
564 WriteRawByte(ref buffer, ref state, b2);
565 WriteRawByte(ref buffer, ref state, b3);
566 WriteRawByte(ref buffer, ref state, b4);
572 public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4, byte b5)
574 if (state.position + 5 > buffer.Length)
576 WriteRawTagSlowPath(ref buffer, ref state, b1, b2, b3, b4, b5);
580 buffer[state.position++] = b1;
581 buffer[state.position++] = b2;
582 buffer[state.position++] = b3;
583 buffer[state.position++] = b4;
584 buffer[state.position++] = b5;
589 private static void WriteRawTagSlowPath(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4, byte b5)
591 WriteRawByte(ref buffer, ref state, b1);
592 WriteRawByte(ref buffer, ref state, b2);
593 WriteRawByte(ref buffer, ref state, b3);
594 WriteRawByte(ref buffer, ref state, b4);
595 WriteRawByte(ref buffer, ref state, b5);