public static bool StreamProtoEnum <TDoc, TCursor>(this IO.TagElementStream <TDoc, TCursor, string> s , string xmlName, ref int dbid , Collections.IProtoEnum protoEnum , bool isOptional = true, IO.TagElementNodeType xmlSource = XML.XmlUtil.kSourceElement , int isOptionalDefaultValue = TypeExtensions.kNone) where TDoc : class where TCursor : class { Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName)); Contract.Requires(protoEnum != null); string id_name = null; bool was_streamed = true; bool to_lower = false; if (s.IsReading) { if (isOptional) { was_streamed = s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true); } else { s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true); } if (was_streamed) { dbid = protoEnum.TryGetMemberId(id_name); Contract.Assert(dbid.IsNotNone(), id_name); } //else // dbid = isOptionalDefaultValue; } else if (s.IsWriting) { if (isOptional && isOptionalDefaultValue.IsNotNone() && isOptionalDefaultValue == dbid) { was_streamed = false; return(was_streamed); } id_name = protoEnum.TryGetMemberName(dbid); if (id_name.IsNullOrEmpty()) { Contract.Assert(!id_name.IsNullOrEmpty(), dbid.ToString()); } if (isOptional) { s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true); } else { s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true); } } return(was_streamed); }
public static int TryGetId(this Collections.IProtoEnum dbi, string name) { if (dbi == null) { return(TypeExtensions.kNone); } return(dbi.TryGetMemberId(name)); }
void ReadNodes <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var xs = s.GetSerializerInterface(); Collections.IProtoEnum penum = Bits.InitializeFromEnum(xs.Database); if (Params.ElementItselfMeansTrue) { var getDefault = Bits.Params.kGetMemberDefaultValue; foreach (var e in s.Elements) { var element_name = s.GetElementName(e); int id = penum.TryGetMemberId(element_name); if (id.IsNone()) { continue; } bool flag = true; s.StreamElementOpt(element_name, ref flag); if (getDefault != null && flag != getDefault(id)) { // do nothing, allow the Set call below } else if (!flag) { continue; } Bits.Set(id, flag); } } else { foreach (var n in s.ElementsByName(Params.ElementName)) { using (s.EnterCursorBookmark(n)) { string name = null; Params.StreamDataName(s, ref name); int id = penum.GetMemberId(name); Bits.Set(id); } } } Bits.OptimizeStorage(); }