Lines Matching defs:value

54         /// Writes a double field value, without a tag, to the stream.
56 public static void WriteDouble(ref Span<byte> buffer, ref WriterInternalState state, double value)
58 WriteRawLittleEndian64(ref buffer, ref state, (ulong)BitConverter.DoubleToInt64Bits(value));
62 /// Writes a float field value, without a tag, to the stream.
64 public static unsafe void WriteFloat(ref Span<byte> buffer, ref WriterInternalState state, float value)
71 Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(floatSpan), value);
81 WriteFloatSlowPath(ref buffer, ref state, value);
86 private static unsafe void WriteFloatSlowPath(ref Span<byte> buffer, ref WriterInternalState state, float value)
92 Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(floatSpan), value);
105 /// Writes a uint64 field value, without a tag, to the stream.
107 public static void WriteUInt64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
109 WriteRawVarint64(ref buffer, ref state, value);
113 /// Writes an int64 field value, without a tag, to the stream.
115 public static void WriteInt64(ref Span<byte> buffer, ref WriterInternalState state, long value)
117 WriteRawVarint64(ref buffer, ref state, (ulong)value);
121 /// Writes an int32 field value, without a tag, to the stream.
123 public static void WriteInt32(ref Span<byte> buffer, ref WriterInternalState state, int value)
125 if (value >= 0)
127 WriteRawVarint32(ref buffer, ref state, (uint)value);
132 WriteRawVarint64(ref buffer, ref state, (ulong)value);
137 /// Writes a fixed64 field value, without a tag, to the stream.
139 public static void WriteFixed64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
141 WriteRawLittleEndian64(ref buffer, ref state, value);
145 /// Writes a fixed32 field value, without a tag, to the stream.
147 public static void WriteFixed32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
149 WriteRawLittleEndian32(ref buffer, ref state, value);
153 /// Writes a bool field value, without a tag, to the stream.
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);
161 /// Writes a string field value, without a tag, to the stream.
164 public static void WriteString(ref Span<byte> buffer, ref WriterInternalState state, string value)
168 int length = Utf8Encoding.GetByteCount(value);
172 if (length == value.Length) // Must be all ASCII...
176 buffer[state.position + i] = (byte)value[i];
184 byte[] bytes = Utf8Encoding.GetBytes(value);
187 ReadOnlySpan<char> source = value.AsSpan();
207 byte[] bytes = Utf8Encoding.GetBytes(value);
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);
223 /// Writes a uint32 value, without a tag, to the stream.
225 public static void WriteUInt32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
227 WriteRawVarint32(ref buffer, ref state, value);
231 /// Writes an enum value, without a tag, to the stream.
233 public static void WriteEnum(ref Span<byte> buffer, ref WriterInternalState state, int value)
235 WriteInt32(ref buffer, ref state, value);
239 /// Writes an sfixed32 value, without a tag, to the stream.
241 public static void WriteSFixed32(ref Span<byte> buffer, ref WriterInternalState state, int value)
243 WriteRawLittleEndian32(ref buffer, ref state, (uint)value);
247 /// Writes an sfixed64 value, without a tag, to the stream.
249 public static void WriteSFixed64(ref Span<byte> buffer, ref WriterInternalState state, long value)
251 WriteRawLittleEndian64(ref buffer, ref state, (ulong)value);
255 /// Writes an sint32 value, without a tag, to the stream.
257 public static void WriteSInt32(ref Span<byte> buffer, ref WriterInternalState state, int value)
259 WriteRawVarint32(ref buffer, ref state, EncodeZigZag32(value));
263 /// Writes an sint64 value, without a tag, to the stream.
265 public static void WriteSInt64(ref Span<byte> buffer, ref WriterInternalState state, long value)
267 WriteRawVarint64(ref buffer, ref state, EncodeZigZag64(value));
285 /// Writes a 32 bit value as a varint. The fast route is taken when
289 public static void WriteRawVarint32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
291 // Optimize for the common case of a single byte value
292 if (value < 128 && state.position < buffer.Length)
294 buffer[state.position++] = (byte)value;
301 if (value > 127)
303 buffer[state.position++] = (byte)((value & 0x7F) | 0x80);
304 value >>= 7;
308 buffer[state.position++] = (byte)value;
313 while (value > 127)
315 WriteRawByte(ref buffer, ref state, (byte)((value & 0x7F) | 0x80));
316 value >>= 7;
319 WriteRawByte(ref buffer, ref state, (byte)value);
322 public static void WriteRawVarint64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
324 // Optimize for the common case of a single byte value
325 if (value < 128 && state.position < buffer.Length)
327 buffer[state.position++] = (byte)value;
334 if (value > 127)
336 buffer[state.position++] = (byte)((value & 0x7F) | 0x80);
337 value >>= 7;
341 buffer[state.position++] = (byte)value;
346 while (value > 127)
348 WriteRawByte(ref buffer, ref state, (byte)((value & 0x7F) | 0x80));
349 value >>= 7;
352 WriteRawByte(ref buffer, ref state, (byte)value);
355 public static void WriteRawLittleEndian32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
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)
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)
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)
439 value.CopyTo(buffer.Slice(state.position, value.Length));
440 state.position += value.Length;
451 while (buffer.Length - state.position < value.Length - bytesWritten)
454 value.Slice(bytesWritten, length).CopyTo(buffer.Slice(state.position, length));
461 int remainderLength = value.Length - bytesWritten;
462 value.Slice(bytesWritten, remainderLength).CopyTo(buffer.Slice(state.position, remainderLength));
600 /// Encode a 32-bit value with ZigZag encoding.
615 /// Encode a 64-bit value with ZigZag encoding.