public static StObject FromParser(BinaryParser parser, int?hint = null) { var so = new StObject(); // hint, is how many bytes to parse if (hint != null) { // end hint hint = parser.Pos() + hint; } while (!parser.End(hint)) { var field = parser.ReadField(); if (field == Field.ObjectEndMarker) { break; } var sizeHint = field.IsVlEncoded ? parser.ReadVlLength() : (int?)null; var st = field.FromParser(parser, sizeHint); if (st == null) { throw new InvalidOperationException("Parsed " + field + " as null"); } so.Fields[field] = st; } return(so); }
public override StObject FromParser(BinaryParser parser, int?hint) { var so = new StObject(); IOutTypeTranslator <ISerializedType> tr; ISerializedType st; Field field; int? sizeHint; while (!parser.End) { field = parser.ReadField(); if (field == Field.ObjectEndMarker) { break; } tr = OutTranslators.ForField(field); sizeHint = field.IsVlEncoded() ? parser.ReadVlLength() : (int?)null; st = tr.FromParser(parser, sizeHint); if (st == null) { throw new InvalidOperationException(string.Format("Parsed {0} as null", field)); } so.Add(field, st); } return(Formatted(so)); }
public void testBinaryParsing() { /* * TransactionType * Sequence * Amount * Fee * SigningPubKey * Account * Destination * */ string expectedSerialization = "120000240000000561D4C44364C5BB000000000000000000000000000055534" + "40000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8684000000000" + "00000F73210330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A" + "313222F7FD0208114B5F762798A53D543A014CAF8B297CFF8F2F937E88314FD" + "94A75318DE40B1D513E6764ECBCB6F1E7056ED"; BinaryParser binaryParser = new BinaryParser(expectedSerialization); Field field; field = binaryParser.ReadField(); Assert.AreEqual(Field.TransactionType, field); Assert.AreEqual(Field.TransactionType, UInt16.TransactionType.GetField()); UInt16 uInt16 = UInt16.OutTranslate.FromParser(binaryParser); Assert.AreEqual(0, uInt16.IntValue()); field = binaryParser.ReadField(); Assert.AreEqual(Field.Sequence, field); UInt32 sequence = UInt32.OutTranslate.FromParser(binaryParser); Assert.AreEqual(5, sequence.IntValue()); field = binaryParser.ReadField(); Assert.AreEqual(Field.Amount, field); binaryParser = new BinaryParser(expectedSerialization); StObject so = StObject.OutTranslate.FromParser(binaryParser); Assert.AreEqual(expectedSerialization, so.ToHex()); }
public static StArray FromParser(BinaryParser parser, int?hint = null) { var stArray = new StArray(); while (!parser.End()) { var field = parser.ReadField(); if (field == Field.ArrayEndMarker) { break; } var outer = new StObject { [(StObjectField)field] = StObject.FromParser(parser) }; stArray.Add(outer); } return(stArray); }
public override StArray FromParser(BinaryParser parser, int?hint) { var stArray = new StArray(); while (!parser.End) { Field field = parser.ReadField(); if (field == Field.ArrayEndMarker) { break; } var outer = new StObject { { field, StObject.OutTranslate.FromParser(parser) } }; stArray.Add(outer); } return(stArray); }