public override Item encode() { byte[] buff = rule.buff; int i = rule.i; int flag = rule.flag; Item item = new Item(); ushort gtag = (ushort)(buff[i] * 256 + buff[i + 1]); ushort etag = (ushort)(buff[i + 2] * 256 + buff[i + 3]); string tag = "(" + gtag.ToString("X4") + "," + etag.ToString("X4") + ")"; i += 4; //为显式VR是解得VR的类型 String vrstring = Encoding.Default.GetString(buff, i, 2); i += 2; int len; //为如下值时,len为2+4,先跳过前两的00 00 在按照LE取出剩下的四个值,解码的len if (vrstring == "OB" || vrstring == "OW" || vrstring == "UT" || vrstring == "OW" || vrstring == "UN" || vrstring == "SQ") { i += 2; len = (int)(buff[i + 0] << 24 + (buff[i + 1] << 16) + (buff[i + 2] << 8) + (buff[i + 3] << 0)); i += 4; } //不是上边的类型是,len为两个字节,按照LE接触len else { len = (int)((buff[i + 0] << 8) + buff[i + 1]); i += 2; } rule.i = i; VRFactory vrf; if (vrstring != "SQ") { vrf = new no_sqVRFactory(); } else { vrf = new sqVRFactory(); } try { VR vr = vrf.CreateVR(vrstring, rule, len); string value = vr.ValueEncoding(); item.Tag = tag; item.len = len; item.Value = value; return(item); } catch { throw new Exception(); } }
public override Item encode() { int i = rule.i; Item item = new Item(); ushort gtag = (ushort)(rule.buff[i] + rule.buff[i + 1] * 256); ushort etag = (ushort)(rule.buff[rule.i + 2] + rule.buff[i + 3] * 256); string tag = "(" + gtag.ToString("X4") + "," + etag.ToString("X4") + ")"; i += 4; int len = (int)(rule.buff[i + 0] + (rule.buff[i + 1] << 8) + (rule.buff[i + 2] << 16) + (rule.buff[i + 3] << 24)); i += 4; string vrstring = encodeVR(tag);//找出对应的VR VRFactory vrf; if (vrstring != "SQ") { vrf = new no_sqVRFactory(); } else { vrf = new sqVRFactory(); } rule.i = i; VR vr = vrf.CreateVR(vrstring, rule, len); string value = vr.ValueEncoding(); item.Tag = tag; item.len = len; item.Value = value; return(item); }