public static List <int> ListIntFromBytes(byte[] data, int wt, ref int offset, ref int ncount, List <int> lst) { List <int> result; if (data == null) { result = lst; } else { if (wt != 2) { throw new ArgumentException("list member from bytes error, type error!!!"); } int count = ProtoUtil.IntFromBytes(data, ref offset, ref ncount); if (count <= 0) { result = lst; } else { if (lst == null) { lst = new List <int>(count); } for (int i = 0; i < count; i++) { int val = ProtoUtil.IntFromBytes(data, ref offset, ref ncount); lst.Add(val); } result = lst; } } return(result); }
public static void ListMemberFromBytes <T>(List <T> lst, byte[] data, int wt, ref int offset, ref int ncount) where T : class, IProtoBuffData, new() { if (lst != null && data != null) { if (wt != 2) { throw new ArgumentException("list member from bytes error, type error!!!"); } int count = ProtoUtil.IntFromBytes(data, ref offset, ref ncount); for (int i = 0; i < count; i++) { int size = ProtoUtil.IntFromBytes(data, ref offset, ref ncount); T obj = Activator.CreateInstance <T>(); if (size <= 0) { lst.Add(obj); } else { int newPos = obj.fromBytes(data, offset, size); ncount += newPos - offset; offset = newPos; lst.Add(obj); } } } }
public static void GetTag(byte[] data, ref int offset, ref int fieldnumber, ref int wt, ref int ncount) { int tag = ProtoUtil.IntFromBytes(data, ref offset, ref ncount); fieldnumber = tag >> 3; wt = (tag & 7); }
public static int IntMemberFromBytes(byte[] data, int wt, ref int offset, ref int ncount) { if (wt != 0) { throw new ArgumentException("int member from bytes error, type error!!!"); } return(ProtoUtil.IntFromBytes(data, ref offset, ref ncount)); }
public static string StringMemberFromBytes(byte[] data, int wt, ref int offset, ref int ncount) { if (wt != 2) { throw new ArgumentException("string from bytes error, type error!!!"); } int bytes = ProtoUtil.IntFromBytes(data, ref offset, ref ncount); string result; if (bytes == 0) { result = ""; } else { string s = new UTF8Encoding().GetString(data, offset, bytes); offset += bytes; ncount += bytes; result = s; } return(result); }