// legend:
        //  [something physical to be stored in buffer]  (something to be translated to/from the byte array)
        //  <<description of item>> (no physical storaged.. just to make reading the structure easier!)
        // 
        // overall layout of byte buffer:
        //
        //  [unsigned int number_of_elements ]
        //  [element]
        //  [element]
        //  ...
        //
        // element = 
        //  <<ItemIdentity>>
        //      [ushort typeField]
        //      [ushort referenceTypeField]
        //      <<embedded ary>>
        //          [unsigned int namefield_length]
        //          [bytes nameField_strdata 0..n]
        //      <<embedded ary>>
        //          [unsigned int contextNameField_length]
        //          [bytes contextNameField_strdata 0..n]
        //      [ulong idField]
        //      [bool idFieldSpecified]
        //  <<RuntimeValue>>
        //      [DateTime timestampField] (??)
        //      [bool timestampFieldSpecified]
        //      <<Variant>>
        //          [ushort typeField]
        //          [int lengthField]
        //          <embedded ary>
        //              [unsigned int payloadField_length]
        //              [bytes payloadField_bytes 0..n]
        //
        //      <<ASBStatus>>
        //          [sbyte countField]
        //          <<embedded ary>>
        //              [unsigned int payloadfield_length]
        //              [bytes payloadField_bytes 0..n]
        //
        //  <<Variant>>
        //      [ushort typeField]
        //      [int lengthField]
        //      <<embedded ary>>
        //          [unsigned int payloadField_length]
        //          [bytes payloadField_bytes 0..n]


        private void ConvertItemIdentityToBytes(ref ItemIdentity p_itemIdentity, BinaryWriter bw)
        {
            //      [ushort typeField]
            bw.Write(p_itemIdentity.Type);
            //      [ushort referenceTypeField]
            bw.Write(p_itemIdentity.ReferenceType);
            //      <<embedded ary>>
            //          [unsigned int namefield_length]
            //          [bytes nameField_strdata 0..n]
            if (p_itemIdentity.Name != null)
            {
                byte[] tmpArray = enc.GetBytes(p_itemIdentity.Name);
                bw.Write((uint)tmpArray.Length);
                bw.Write(tmpArray);
            }
            else
            {
                bw.Write((uint)0);
            }
            //      <<embedded ary>>
            //          [unsigned int contextNameField_length]
            //          [bytes contextNameField_strdata 0..n]
            if (p_itemIdentity.ContextName != null)
            {
                byte[] tmpArray = enc.GetBytes(p_itemIdentity.ContextName);
                bw.Write((uint)tmpArray.Length);
                bw.Write(tmpArray);
            }
            else
            {
                bw.Write((uint)0);
            }
            //      [ulong idField]
            bw.Write(p_itemIdentity.Id);
            //      [bool idFieldSpecified]
            bw.Write(p_itemIdentity.IdSpecified);

        }
        private void ConvertBytesToItemIdentity(ref ItemIdentity Item, BinaryReader br)
        {
            //      [ushort typeField]
            Item.Type = br.ReadUInt16();
            //      [ushort referenceTypeField]
            Item.ReferenceType = br.ReadUInt16();
            //      <<embedded ary>>
            //          [unsigned int namefield_length]
            //          [bytes nameField_strdata 0..n]
            int strLen = br.ReadInt32();
            if (strLen > 0)
            {
                byte[] tmpBytes = br.ReadBytes(strLen);
                Item.Name = enc.GetString(tmpBytes);
            }
            else
            {
                Item.Name = "";
            }
            //      <<embedded ary>>
            //          [unsigned int contextNameField_length]
            //          [bytes contextNameField_strdata 0..n]
            strLen = br.ReadInt32();
            if (strLen > 0)
            {
                byte[] tmpBytes = br.ReadBytes(strLen);
                Item.ContextName = enc.GetString(tmpBytes);
            }
            else
            {
                Item.ContextName = "";
            }
            //      [ulong idField]
            Item.Id = br.ReadUInt64();
            //      [bool idFieldSpecified]
            Item.IdSpecified = br.ReadBoolean();

        }