LocalTime ISerializer <LocalTime> .Read(ref ProtoReader.State state, LocalTime value) { int field; int hours = value.Hour, minutes = value.Minute, seconds = value.Second, nanos = value.NanosecondOfSecond; while ((field = state.ReadFieldHeader()) > 0) { switch (field) { case 1: hours = state.ReadInt32(); break; case 2: minutes = state.ReadInt32(); break; case 3: seconds = state.ReadInt32(); break; case 4: nanos = state.ReadInt32(); break; default: state.SkipField(); break; } } return(new LocalTime(hours, minutes, seconds).PlusNanoseconds(nanos)); }
LocalDate ISerializer <LocalDate> .Read(ref ProtoReader.State state, LocalDate value) { int field; int year = value.Year, month = value.Month, day = value.Day; while ((field = state.ReadFieldHeader()) > 0) { switch (field) { case 1: year = state.ReadInt32(); break; case 2: month = state.ReadInt32(); break; case 3: day = state.ReadInt32(); break; default: state.SkipField(); break; } } return(new LocalDate(year, month, day)); // ISO calendar is implicit }
public static List <Student> CreateProtoReaderBuffer(byte[] encoded) { using (MemoryStream rs = new MemoryStream(encoded)) { ProtoReader.State pr = ProtoReader.State.Create(rs, null, null); List <Student> students = new List <Student>(); Student student = new Student(); while (pr.GetPosition() < rs.Length) { var fieldHeader = pr.ReadFieldHeader(); if (fieldHeader == 1) { student = new Student(); students.Add(student); } if (fieldHeader == 1) { student.Id = BclHelpers.ReadGuid(ref pr); } else if (fieldHeader == 2) { student.Name = pr.ReadString(); } else if (fieldHeader == 3) { student.AdmissionDate = BclHelpers.ReadDateTime(ref pr); } else if (fieldHeader == 4) { student.Age = pr.ReadInt32(); } } return(students); } }
private static Duration ReadDurationFallback(ref ProtoReader.State state, Duration value) { var seconds = value.Seconds; var nanos = value.Nanoseconds; int fieldNumber; while ((fieldNumber = state.ReadFieldHeader()) > 0) { switch (fieldNumber) { case 1: seconds = state.ReadInt64(); break; case 2: nanos = state.ReadInt32(); break; default: state.SkipField(); break; } } return(new Duration(seconds, nanos)); }
ScaledTicks ISerializer <ScaledTicks> .Read(ref ProtoReader.State state, ScaledTicks _) { int fieldNumber; TimeSpanScale scale = TimeSpanScale.Days; long value = 0; var kind = DateTimeKind.Unspecified; while ((fieldNumber = state.ReadFieldHeader()) > 0) { switch (fieldNumber) { case ScaledTicks.FieldTimeSpanScale: scale = (TimeSpanScale)state.ReadInt32(); break; case ScaledTicks.FieldTimeSpanValue: state.Assert(WireType.SignedVarint); value = state.ReadInt64(); break; case ScaledTicks.FieldTimeSpanKind: kind = (DateTimeKind)state.ReadInt32(); switch (kind) { case DateTimeKind.Unspecified: case DateTimeKind.Utc: case DateTimeKind.Local: break; // fine default: ThrowHelper.ThrowProtoException("Invalid date/time kind: " + kind.ToString()); break; } break; default: state.SkipField(); break; } } return(new ScaledTicks(value, scale, kind)); }
private static void Merge(ref ProtoReader.State state, ref protogen.OrderLine obj) { int field; if (obj == null) { obj = new protogen.OrderLine(); } while ((field = state.ReadFieldHeader()) != 0) { switch (field) { case 1: obj.OrderID = state.ReadInt32(); break; case 2: obj.ProductID = state.ReadInt32(); break; case 3: obj.UnitPrice = state.ReadDouble(); break; case 4: state.Hint(WireType.SignedVarint); obj.Quantity = state.ReadInt32(); break; case 5: obj.Discount = state.ReadSingle(); break; default: state.AppendExtensionData(obj); break; } } }
public MyMessage Read(ref ProtoReader.State state, MyMessage value) { value ??= new MyMessage(); int field; while ((field = state.ReadFieldHeader()) > 0) { switch (field) { case 12: value.Y = state.ReadString(); break; case 42: value.X = state.ReadInt32(); break; default: state.SkipField(); break; } } return(value); }
public object Read(ref ProtoReader.State state, object value) { Debug.Assert(value is null); // since replaces return(state.ReadInt32()); }
private static void Merge(ref ProtoReader.State state, ref protogen.Order obj) { SubItemToken tok; int field; if (obj == null) { obj = new protogen.Order(); } while ((field = state.ReadFieldHeader()) != 0) { switch (field) { case 1: obj.OrderID = state.ReadInt32(); break; case 2: obj.CustomerID = state.ReadString(); break; case 3: obj.EmployeeID = state.ReadInt32(); break; case 4: obj.OrderDate = BclHelpers.ReadTimestamp(ref state); break; case 5: obj.RequiredDate = BclHelpers.ReadTimestamp(ref state); break; case 6: obj.ShippedDate = BclHelpers.ReadTimestamp(ref state); break; case 7: obj.ShipVia = state.ReadInt32(); break; case 8: obj.Freight = state.ReadDouble(); break; case 9: obj.ShipName = state.ReadString(); break; case 10: obj.ShipAddress = state.ReadString(); break; case 11: obj.ShipCity = state.ReadString(); break; case 12: obj.ShipRegion = state.ReadString(); break; case 13: obj.ShipPostalCode = state.ReadString(); break; case 14: obj.ShipCountry = state.ReadString(); break; case 15: do { protogen.OrderLine _15 = default; tok = state.StartSubItem(); Merge(ref state, ref _15); state.EndSubItem(tok); obj.Lines.Add(_15); } while (state.TryReadFieldHeader(1)); break; default: state.AppendExtensionData(obj); break; } } }