public Node(byte[] bytes) { byte[] editedBytes; Id = GetId(bytes, out editedBytes); Labels = GetLabels(editedBytes, out editedBytes); Data = PackStream.Unpack <T>(editedBytes); }
private static IDictionary UnpackDictionary <TKey, TValue>(byte[] content) { int numberOfPairs; var markerLess = RemoveMarker(content, out numberOfPairs); var output = new Dictionary <TKey, TValue>(); if (numberOfPairs == 0) { return(output); } var packed = PackStream.GetPackedEntities(markerLess); for (var i = 0; i < packed.Length; i += 2) { var key = PackStream.Unpack(packed[i]); var value = PackStream.Unpack(packed[i + 1]); Type genericType; if (Packers.List.IsEnumerable(typeof(TValue), out genericType)) { var method = typeof(Packers.List).GetTypeInfo().GetDeclaredMethod("Unpack"); var genericMethod = method.MakeGenericMethod(genericType); var list = genericMethod.Invoke(null, new object[] { packed[i + 1].Original }) as IEnumerable; value = (TValue)list; } output.Add(key, value); } return(output); }
private static IDictionary <string, IEnumerable <string> > GetMetaData(Struct s) { if (s.NumberOfFields == 0) { return(null); } //Get actual data var response = PackStream.Unpack <Dictionary <string, IEnumerable <string> > >(s.ContentWithoutStructAndSignature); return(response); }
public static IEnumerable <T> Unpack <T>(byte[] content) { if (!IsUnpackable(content)) { throw new ArgumentException("Not a list.", nameof(content)); } var numberOfElements = GetNumberOfElements(content); var bytesToSkip = GetSizeOfMarkerInBytes(numberOfElements); var unpacked = PackStream.Unpack(content.Skip(bytesToSkip).ToArray()); return(unpacked.Cast <T>()); }