public void Parse(byte[] packagebodybyte, IPackage package) { try { byte[] header = packagebodybyte.Take(min_body_header_length).ToArray(); byte[] body = packagebodybyte.Skip(min_body_header_length).Take(packagebodybyte.Length - min_body_header_length).ToArray(); ipp_Header ippheader = new ipp_Header(header); ipp_Body ippbody = new ipp_Body(body, _defEncoding); Indexes indexes = new Indexes(0, 6); package.PCC = ippbody.GetString(indexes); package.UID = ippbody.GetUid(indexes.Next(24));//ci + ippheader.PT + ippheader.PCT, ippheader.PCT); package.PD = ippbody.GetDatetime(indexes.Next(14));//ci + ippheader.PT + ippheader.PCT, ippheader.PCT); package.IPPV = ippbody.GetString(indexes.Next(ippheader.IPPV));//ci, ippheader.PT); package.PT = ippbody.GetInt(indexes.Next(ippheader.PT));//ci, ippheader.PT); package.PCT = ippbody.GetInt(indexes.Next(ippheader.PCT));//ci + ippheader.PT, ippheader.PCT); package.PCL = ippbody.GetInt(indexes.Next(ippheader.PCL));//ci + ippheader.PT + ippheader.PCT, ippheader.PCT); package.PS = ippbody.GetString(indexes.Next(ippheader.PS));//ci + ippheader.PT + ippheader.PCT + ippheader.PCL, ippheader.PS); package.PR = ippbody.GetString(indexes.Next(ippheader.PR));//ci + ippheader.PT + ippheader.PCT + ippheader.PCL + ippheader.PS, ippheader.PR); package.PCN = ippbody.GetString(indexes.Next(ippheader.PCN));//ci + ippheader.PT + ippheader.PCT + ippheader.PCL + ippheader.PS + ippheader.PR, ippheader.PS); package.PC = body.Skip(indexes.Index + indexes.Count).Take(body.Length - indexes.Index + indexes.Count).ToArray();//ci + ippheader.PT + ippheader.PCT + ippheader.PCL, ippheader.PCT); } catch (Exception e) { } }
public DateTime GetDatetime(Indexes indexes) { return _defEncoding.GetString(_body, indexes.Index, indexes.Count).ToDateTime("yyyyMMddHHmmss"); }
public string GetString(Indexes indexes) { return _defEncoding.GetString(_body, indexes.Index, indexes.Count); }
public Guid GetUid(Indexes indexes) { return _body.Skip(indexes.Index).Take(indexes.Count).ToArray().FromiTripByteArray(_defEncoding); //return new Guid(Convert.FromBase64String(Encoding.Default.GetString(_body.Skip(indexes.Index).Take(indexes.Count).ToArray()))); //return new Guid(_body.Skip(indexes.Index).Take(indexes.Count).ToArray()); //Guid guid = Guid.Empty; //Guid.TryParse(Encoding.UTF8.GetString(_body, indexes.Index, indexes.Count), out guid); //return guid; }
public int GetInt(Indexes indexes) { return BitConverter.ToInt32(_body.Skip(indexes.Index).Take(indexes.Count).ToArray(), 0); //return Encoding.Default.GetString(_body, indexes.Index, indexes.Count).ToInt(); }