/// <summary> /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TStream"></typeparam> /// <param name="stream"></param> /// <param name="structs"></param> /// <param name="count"></param> /// <returns></returns> public static TStream WriteStructVector <T, TStream>(this TStream stream, T[] structs, int count = -1) where T : struct where TStream : Stream { stream.WriteBytes(StructUtils.StructArrayToBytes(structs, count)); return(stream); }
private byte[] HandlePacket_ListElements(byte[] RequestContent) { List <ListElements_ResponseEntryStruct> ResponseEntries = new List <ListElements_ResponseEntryStruct>(); var Request = StructUtils.BytesToStruct <ListElements_RequestStruct>(RequestContent); // http://stackoverflow.com/questions/7032290/what-happens-to-an-awaiting-thread-in-c-sharp-async-ctp { var RankingIndex = ServerManager.ServerIndices[Request.RankingIndexId]; int CurrentEntryOffset = Request.Offset; if (Request.Offset >= 0) { foreach (var UserScore in RankingIndex.GetRange(Request.Offset, Request.Count)) { ResponseEntries.Add(new ListElements_ResponseEntryStruct() { Position = CurrentEntryOffset, UserId = UserScore.UserId, ScoreValue = UserScore.ScoreValue, ScoreTimeStamp = UserScore.ScoreTimeStamp, }); CurrentEntryOffset++; } } } return(StructUtils.StructArrayToBytes(ResponseEntries.ToArray())); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Stream"></param> /// <param name="Structs"></param> /// <returns></returns> public static Stream WriteStructVector <T>(this Stream Stream, T[] Structs) where T : struct { Stream.WriteBytes(StructUtils.StructArrayToBytes(Structs)); return(Stream); }