Пример #1
0
        private static void Write <T>(BinaryWriter writer, object value)
        {
            T proto = (T)value;

            byte[] bytes = ProtoUtils.GetBytes <T>(proto.ToEnumerable());
            writer.Write(bytes);
        }
Пример #2
0
 public static void Write <T>(this Stream stream, T proto)
 {
     byte[] payload = ProtoUtils.GetBytes(proto);
     stream.Write(payload, 0, payload.Length);
 }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="stream"></param>
 /// <param name="tuple"></param>
 /// <returns></returns>
 public static async Task WriteAsync <T>(this Stream stream, T proto, CancellationToken token)
 {
     byte[] payload = ProtoUtils.GetBytes(proto);
     await stream.WriteAsync(payload, 0, payload.Length, token);
 }
Пример #4
0
        // /// <summary>
        // /// Creates a data table for tuples
        // /// </summary>
        // /// <typeparam name="T">tuple type</typeparam>
        // /// <param name="tuples">tuple objects</param>
        // /// <returns>data table for the tuples</returns>
        // public static DataTable CreateDataTable<T>(this IEnumerable<T> protoes) where T : new()
        // {
        //     DataTable table = new DataTable();

        //     Proto<T>.Validate();
        //     foreach (IProtoColumn protoColumn in Proto<T>.Columns)
        //     {
        //         table.Columns.Add(protoColumn.Name, protoColumn.ColumnType);
        //     }

        //     foreach (T proto in protoes)
        //     {
        //         table.Rows.Add(Proto<T>.Columns.Select(col => proto.GetValue(col)).ToArray());
        //     }

        //     return table;
        // }

        /// <summary>
        /// Display tuple objects in grid
        /// </summary>
        /// <typeparam name="T">tuple type</typeparam>
        /// <param name="dataSource"></param>
        /// <param name="msgLoop"></param>
        // public static void ShowGrid<T>(this IEnumerable<T> protoes, bool msgLoop) where T : new()
        // {
        //     DataGridView gridView = ProtoGrid<T>.CreateDataGrid();
        //     gridView.DataSource = protoes.CreateDataTable();
        //     ProtoGrid<T>.ShowGrid(gridView, msgLoop);
        // }

        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tuples"></param>
        /// <returns></returns>
        public static byte[] GetBytes <T>(params T[] protoes)
        {
            return(ProtoUtils.GetBytes <T>((IEnumerable <T>)protoes));
        }