Example #1
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();
        }
Example #2
0
        public static IPEndPoint ReadValue <TInput>(ref Buffers.Reader <TInput> reader, Field field)
        {
            if (field.WireType == WireType.Reference)
            {
                return((IPEndPoint)ReferenceCodec.ReadReference(ref reader, field, CodecFieldType));
            }

            var       referencePlaceholder = ReferenceCodec.CreateRecordPlaceholder(reader.Session);
            IPAddress address = default;
            ushort    port    = 0;
            int       id      = 0;
            Field     header  = default;

            while (true)
            {
                id = OrleansGeneratedCodeHelper.ReadHeader(ref reader, ref header, id);
                if (id == 1)
                {
                    address = IPAddressCodec.ReadValue(ref reader, header);
                    id      = OrleansGeneratedCodeHelper.ReadHeader(ref reader, ref header, id);
                }

                if (id == 2)
                {
                    port = UInt16Codec.ReadValue(ref reader, header);
                    id   = OrleansGeneratedCodeHelper.ReadHeaderExpectingEndBaseOrEndObject(ref reader, ref header, id);
                }

                if (id != -1)
                {
                    reader.ConsumeUnknownField(header);
                }
                else
                {
                    break;
                }
            }

            var result = new IPEndPoint(address, port);

            ReferenceCodec.RecordObject(reader.Session, result, referencePlaceholder);
            return(result);
        }