/// <inheritdoc/> public TField ReadValue <TInput>(ref Reader <TInput> reader, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <TField, TInput>(ref reader, field)); } var placeholderReferenceId = ReferenceCodec.CreateRecordPlaceholder(reader.Session); var fieldType = field.FieldType; if (fieldType is null || fieldType == _fieldType) { TSurrogate surrogate = default; _surrogateSerializer.Deserialize(ref reader, ref surrogate); var result = _converter.ConvertFromSurrogate(in surrogate); ReferenceCodec.RecordObject(reader.Session, result, placeholderReferenceId); return(result); } // The type is a descendant, not an exact match, so get the specific serializer for it. var specificSerializer = reader.Session.CodecProvider.GetCodec(fieldType); if (specificSerializer != null) { return((TField)specificSerializer.ReadValue(ref reader, field)); } ThrowSerializerNotFoundException(fieldType); return(default);
TField IFieldCodec <TField> .ReadValue(ref Reader reader, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <TField>(ref reader, field)); } var fieldType = field.FieldType; if (fieldType == null || fieldType == CodecFieldType) { var result = this.activator.Create(); ReferenceCodec.RecordObject(reader.Session, result); this.serializer.Deserialize(ref reader, result); return(result); } // The type is a descendant, not an exact match, so get the specific serializer for it. var specificSerializer = reader.Session.CodecProvider.GetCodec(fieldType); if (specificSerializer != null) { return((TField)specificSerializer.ReadValue(ref reader, field)); } ThrowSerializerNotFoundException(fieldType); return(null); }
object IFieldCodec <object> .ReadValue <TInput>(ref Reader <TInput> reader, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <object, TInput>(ref reader, field)); } if (field.WireType != WireType.TagDelimited) { ThrowUnsupportedWireTypeException(field); } var placeholderReferenceId = ReferenceCodec.CreateRecordPlaceholder(reader.Session); object result = null; Type type = null; uint fieldId = 0; while (true) { var header = reader.ReadFieldHeader(); if (header.IsEndBaseOrEndObject) { break; } fieldId += header.FieldIdDelta; switch (fieldId) { case 0: ReferenceCodec.MarkValueField(reader.Session); type = reader.Session.TypeCodec.ReadLengthPrefixed(ref reader); break; case 1: if (type is null) { ThrowTypeFieldMissing(); } // To possibly improve efficiency, this could be converted to read a ReadOnlySequence<byte> instead of a byte array. var serializedValue = StringCodec.ReadValue(ref reader, header); result = JsonConvert.DeserializeObject(serializedValue, type, _options.SerializerSettings); ReferenceCodec.RecordObject(reader.Session, result, placeholderReferenceId); break; default: reader.ConsumeUnknownField(header); break; } } return(result); }
public object ReadValue(ref Reader reader, SerializerSession session, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference(ref reader, session, field, null)); } var placeholderReferenceId = ReferenceCodec.CreateRecordPlaceholder(session); var header = reader.ReadFieldHeader(session); var type = this.typeCodec.ReadValue(ref reader, session, header); if (type.IsValueType) { var serializer = this.valueTypeSerializerFactory.GetSerializer(type); return(serializer.ReadValue(ref reader, session, type, placeholderReferenceId)); } return(this.objectSerializer.ReadValue(ref reader, session, type, placeholderReferenceId)); }
public object ReadValue <TInput>(ref Reader <TInput> reader, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <object, TInput>(ref reader, field)); } var placeholderReferenceId = ReferenceCodec.CreateRecordPlaceholder(reader.Session); var header = reader.ReadFieldHeader(); var type = _typeCodec.ReadValue(ref reader, header); if (type.IsValueType) { var serializer = _valueTypeSerializerFactory.GetSerializer(type); return(serializer.ReadValue(ref reader, type, placeholderReferenceId)); } return(_objectSerializer.ReadValue(ref reader, type, placeholderReferenceId)); }
public object ReadValue(Reader reader, SerializerSession session, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <object>(reader, session, field, this.codecProvider)); } if (field.WireType != WireType.LengthPrefixed) { ThrowUnsupportedWireTypeException(field); } var length = reader.ReadVarUInt32(); var bytes = reader.ReadBytes((int)length); // TODO: NoAlloc var resultString = Encoding.UTF8.GetString(bytes); var result = JsonConvert.DeserializeObject(resultString, this.settings); ReferenceCodec.RecordObject(session, result); return(result); }
public TField ReadValue(Reader reader, SerializerSession session, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <TField>(reader, session, field, this.codecProvider)); } var fieldType = field.FieldType; if (fieldType == null) { ThrowMissingFieldType(); } var specificSerializer = this.codecProvider.GetCodec(fieldType); if (specificSerializer != null) { return((TField)specificSerializer.ReadValue(reader, session, field)); } return(ThrowSerializerNotFound(fieldType)); }
object IFieldCodec <object> .ReadValue <TInput>(ref Reader <TInput> reader, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <object, TInput>(ref reader, field)); } if (field.WireType != WireType.LengthPrefixed) { ThrowUnsupportedWireTypeException(field); } var length = reader.ReadVarUInt32(); var bytes = reader.ReadBytes(length); // TODO: NoAlloc var resultString = Encoding.UTF8.GetString(bytes); var result = JsonConvert.DeserializeObject(resultString, _settings); ReferenceCodec.RecordObject(reader.Session, result); return(result); }
public SiloAddress ReadValue <TReaderInput>(ref Reader <TReaderInput> reader, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <SiloAddress, TReaderInput>(ref reader, field)); } ReferenceCodec.MarkValueField(reader.Session); int id = 0; Field header = default; IPEndPoint endpoint = default; int generation = default; while (true) { id = OrleansGeneratedCodeHelper.ReadHeader(ref reader, ref header, id); if (id == 0) { endpoint = IPEndPointCodec.ReadValue(ref reader, header); id = OrleansGeneratedCodeHelper.ReadHeader(ref reader, ref header, id); } if (id == 1) { generation = Int32Codec.ReadValue(ref reader, header); id = OrleansGeneratedCodeHelper.ReadHeaderExpectingEndBaseOrEndObject(ref reader, ref header, id); } if (id == -1) { break; } reader.ConsumeUnknownField(header); } return(SiloAddress.New(endpoint, generation)); }
public TField ReadValue <TInput>(ref Reader <TInput> reader, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <TField, TInput>(ref reader, field)); } var fieldType = field.FieldType; if (fieldType is null) { ThrowMissingFieldType(); } var specificSerializer = reader.Session.CodecProvider.GetCodec(fieldType); if (specificSerializer != null) { return((TField)specificSerializer.ReadValue(ref reader, field)); } return(ThrowSerializerNotFound(fieldType)); }
/// <inheritdoc/> object IFieldCodec <object> .ReadValue <TInput>(ref Reader <TInput> reader, Field field) { if (field.WireType == WireType.Reference) { return(ReferenceCodec.ReadReference <object, TInput>(ref reader, field)); } if (field.WireType != WireType.TagDelimited) { ThrowUnsupportedWireTypeException(field); } var placeholderReferenceId = ReferenceCodec.CreateRecordPlaceholder(reader.Session); object result = null; Type type = null; uint fieldId = 0; while (true) { var header = reader.ReadFieldHeader(); if (header.IsEndBaseOrEndObject) { break; } fieldId += header.FieldIdDelta; switch (fieldId) { case 0: ReferenceCodec.MarkValueField(reader.Session); type = reader.Session.TypeCodec.ReadLengthPrefixed(ref reader); break; case 1: if (type is null) { ThrowTypeFieldMissing(); } ReferenceCodec.MarkValueField(reader.Session); var length = reader.ReadVarUInt32(); // To possibly improve efficiency, this could be converted to read a ReadOnlySequence<byte> instead of a byte array. ReadOnlySequence <byte> sequence = default; var tempBuffer = new PooledArrayBufferWriter(); try { reader.ReadBytes(ref tempBuffer, (int)length); sequence = tempBuffer.RentReadOnlySequence(); var jsonReader = new Utf8JsonReader(sequence, _options.ReaderOptions); result = JsonSerializer.Deserialize(ref jsonReader, type, _options.SerializerOptions); } finally { tempBuffer.ReturnReadOnlySequence(sequence); tempBuffer.Reset(); } break; default: reader.ConsumeUnknownField(header); break; } } ReferenceCodec.RecordObject(reader.Session, result, placeholderReferenceId); return(result); }