internal static byte[] ContainerToBytes(IIonValue container) { List <byte> bytes = new List <byte>(); bytes.AddRange(new byte[] { 0xE0, 0x01, 0x00, 0xEA }); var bytesEnumerator = container.GetEnumerator(); while (bytesEnumerator.MoveNext()) { bytes.Add((byte)bytesEnumerator.Current.IntValue); } return(bytes.ToArray()); }
public object ConvertTo(IIonValue value, Type type) { var listGenericArg = type.GetGenericArguments()[0]; var handler = FieldHandlers.GetHandler(listGenericArg); var list = (IList)Activator.CreateInstance(type); var enumerator = value.GetEnumerator(); while (enumerator.MoveNext()) { list.Add(handler.ConvertTo(enumerator.Current, listGenericArg)); } return(list); }
private static string HashLogToString(IIonValue hashLog) { bool multipleEntries = hashLog.Count > 1; StringBuilder sb = new StringBuilder(); sb.Append("("); IEnumerator <IIonValue> enumerator = hashLog.GetEnumerator(); while (enumerator.MoveNext()) { IIonValue hashCall = enumerator.Current; if (multipleEntries) { sb.Append("\n "); } foreach (SymbolToken annotation in hashCall.GetTypeAnnotationSymbols()) { sb.Append(annotation.Text).Append("::"); } sb.Append("("); int cnt = 0; IEnumerator <IIonValue> bytesEnum = hashCall.GetEnumerator(); while (bytesEnum.MoveNext()) { IIonValue i = bytesEnum.Current; if (cnt++ > 0) { sb.Append(" "); } sb.Append(i.IntValue.ToString("x2")); } sb.Append(")"); } if (multipleEntries) { sb.Append("\n"); } sb.Append(")"); return(sb.ToString()); }
protected SystemTreeReader(IIonValue value) { this.systemSymbols = SharedSymbolTable.GetSystem(1); this.current = null; this.eof = false; this.top = 0; if (value.Type() == IonType.Datagram) { this.parent = value; this.next = null; this.iter = value.GetEnumerator(); } else { this.parent = null; this.next = value; } }
protected SystemTreeReader(IIonValue value) { _systemSymbols = SharedSymbolTable.GetSystem(1); _current = null; _eof = false; _top = 0; if (value.Type() == IonType.Datagram) { _parent = value; _next = null; _iter = value.GetEnumerator(); } else { _parent = null; _next = value; } }
public IEnumerable <object[]> GetData(MethodInfo methodInfo) { var dataList = new List <object[]>(); var loader = IonLoader.Default; var file = DirStructure.IonHashDotnetTestFile("ion_hash_tests.ion"); var ionHashTests = loader.Load(file); var testsEnumerator = ionHashTests.GetEnumerator(); while (testsEnumerator.MoveNext()) { IIonValue testCase = testsEnumerator.Current; string testName = "unknown"; if (testCase.ContainsField("ion")) { testName = testCase.GetField("ion").ToPrettyString(); } IReadOnlyCollection <SymbolToken> annotations = testCase.GetTypeAnnotationSymbols(); if (annotations.Count > 0) { testName = annotations.ElementAt(0).Text; } IIonValue expect = testCase.GetField("expect"); var expectEnumerator = expect.GetEnumerator(); while (expectEnumerator.MoveNext()) { IIonValue expectedHashLog = expectEnumerator.Current; String hasherName = expectedHashLog.FieldNameSymbol.Text; object[] data = new object[] { hasherName.Equals("identity") ? testName : testName + "." + hasherName, testCase, expectedHashLog, TestIonHasherProvider.GetInstance(hasherName) }; dataList.Add(data); } } return(dataList); }
public object ConvertTo(IIonValue value, Type type) { var genericArgs = type.GetGenericArguments(); var keyGenericArg = genericArgs[0]; var valueGenericArg = genericArgs[1]; var valueHandler = FieldHandlers.GetHandler(valueGenericArg); var dict = (IDictionary)Activator.CreateInstance(type); var enumerator = value.GetEnumerator(); while (enumerator.MoveNext()) { var itemField = enumerator.Current; var key = System.Convert.ChangeType(itemField.FieldNameSymbol.Text, keyGenericArg); var itemValue = valueHandler.ConvertTo(enumerator.Current, valueGenericArg); dict.Add(key, itemValue); } return(dict); }
private static IIonValue FilterHashLog(IIonValue actualHashLog, IIonValue expectedHashLog) { HashSet <string> methodCalls = new HashSet <string>(); IEnumerator <IIonValue> enumerator = expectedHashLog.GetEnumerator(); while (enumerator.MoveNext()) { IIonValue v = enumerator.Current; foreach (SymbolToken annotation in v.GetTypeAnnotationSymbols()) { methodCalls.Add(annotation.Text); } } IValueFactory valueFactory = new ValueFactory(); IIonValue result = valueFactory.NewEmptySexp(); if (methodCalls.Count == 1 && methodCalls.Contains("final_digest")) { IIonValue finalDigest = actualHashLog.GetElementAt(actualHashLog.Count - 1); finalDigest.ClearAnnotations(); finalDigest.AddTypeAnnotation("final_digest"); result.Add(finalDigest); } else { enumerator = actualHashLog.GetEnumerator(); while (enumerator.MoveNext()) { IIonValue v = enumerator.Current; String methodCall = v.GetTypeAnnotationSymbols().ElementAt(0).Text; if (methodCalls.Contains(methodCall)) { result.Add(v); } } } return(result); }