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); } }
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); }
string ISerializer <string> .Read(ref ProtoReader.State state, string value) => state.ReadString();
IPAddress ISerializer <IPAddress> .Read(ref ProtoReader.State state, IPAddress value) => IPAddressParse(state.ReadString());
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; } } }
public object Read(ref ProtoReader.State state, object value) { Debug.Assert(value == null); // since replaces return(state.ReadString()); }
public object Read(ref ProtoReader.State state, object value) { Debug.Assert(value == null); // since replaces return(parse.Invoke(null, new object[] { state.ReadString() })); }