Beispiel #1
0
        public static void WriteField <TBufferWriter>(ref Buffers.Writer <TBufferWriter> writer, uint fieldIdDelta, Type expectedType, IPAddress value) where TBufferWriter : IBufferWriter <byte>
        {
            if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, value))
            {
                return;
            }

            writer.WriteFieldHeader(fieldIdDelta, expectedType, CodecFieldType, WireType.LengthPrefixed);
#if NET5_0_OR_GREATER
            Span <byte> buffer = stackalloc byte[64];
            if (value.TryWriteBytes(buffer, out var length))
            {
                var writable = writer.WritableSpan;
                if (writable.Length > length)
                {
                    writer.WriteVarUInt32((uint)length);
                    buffer.Slice(0, length).CopyTo(writable.Slice(1));
                    writer.AdvanceSpan(length);
                    return;
                }
            }
#endif
            var bytes = value.GetAddressBytes();
            writer.WriteVarUInt32((uint)bytes.Length);
            writer.Write(bytes);
        }
Beispiel #2
0
        public static void WriteField <TBufferWriter>(ref Buffers.Writer <TBufferWriter> writer, uint fieldIdDelta, Type expectedType, IPEndPoint value) where TBufferWriter : IBufferWriter <byte>
        {
            if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, value))
            {
                return;
            }

            writer.WriteFieldHeader(fieldIdDelta, expectedType, CodecFieldType, WireType.TagDelimited);
            IPAddressCodec.WriteField(ref writer, 1, IPAddressCodec.CodecFieldType, value.Address);
            UInt16Codec.WriteField(ref writer, 1, UInt16Codec.CodecFieldType, (ushort)value.Port);
            writer.WriteEndObject();
        }
Beispiel #3
0
 public void Serialize <TBufferWriter>(ref Buffers.Writer <TBufferWriter> writer, PooledResponse <TResult> instance)
     where TBufferWriter : System.Buffers.IBufferWriter <byte>
 {
     if (instance.Exception is null)
     {
         _resultCodec.WriteField(ref writer, 0U, ResultType, instance.TypedResult);
     }
     else
     {
         _exceptionCodec.WriteField(ref writer, 1U, ExceptionType, instance.Exception);
     }
 }
Beispiel #4
0
 void IFieldCodec <IPAddress> .WriteField <TBufferWriter>(ref Buffers.Writer <TBufferWriter> writer, uint fieldIdDelta, Type expectedType, IPAddress value)
 {
     WriteField(ref writer, fieldIdDelta, expectedType, value);
 }
Beispiel #5
0
 void IFieldCodec <IPEndPoint> .WriteField <TBufferWriter>(ref Buffers.Writer <TBufferWriter> writer, uint fieldIdDelta, Type expectedType, IPEndPoint value) => WriteField(ref writer, fieldIdDelta, expectedType, value);