WriteBinHex() public method

public WriteBinHex ( byte buffer, int index, int count ) : void
buffer byte
index int
count int
return void
Exemplo n.º 1
0
 public virtual void WriteXml(System.Xml.XmlWriter writer)
 {
     byte[] bits = System.Text.Encoding.UTF8.GetBytes("hello world");
     writer.WriteStartElement("WriteBinHex");
     writer.WriteBinHex(bits, 0, bits.Length); //writes hello world again
     writer.WriteEndElement();                 // WriteBinHex
 }
Exemplo n.º 2
0
        /// <summary>
        /// Serialize the object to a XML writer
        /// </summary>
        /// <param name="writer">   XML writer</param>
        void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
        {
            MemoryStream memStream;
            BinaryWriter binWriter;

            byte[] bytes;


            memStream = new MemoryStream(32768);
            binWriter = new BinaryWriter(memStream);
            SaveToStream(binWriter);
            bytes = memStream.GetBuffer();
            writer.WriteStartElement("MoveHistory");
            writer.WriteBinHex(bytes, 0, (int)memStream.Length);
            writer.WriteEndElement();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Replay all cached events to an XmlWriter.
        /// </summary>
        public void EventsToWriter(XmlWriter writer) {
            XmlEvent[] page;
            int idxPage, idxEvent;
            byte[] bytes;
            char[] chars;
            XmlRawWriter rawWriter;

            // Special-case single text node at the top-level
            if (this.singleText.Count != 0) {
                writer.WriteString(this.singleText.GetResult());
                return;
            }

            rawWriter = writer as XmlRawWriter;

            // Loop over set of pages
            for (idxPage = 0; idxPage < this.pages.Count; idxPage++) {
                page = this.pages[idxPage];

                // Loop over events in each page
                for (idxEvent = 0; idxEvent < page.Length; idxEvent++) {
                    switch (page[idxEvent].EventType) {
                        case XmlEventType.Unknown:
                            // No more events
                            Debug.Assert(idxPage + 1 == this.pages.Count);
                            return;

                        case XmlEventType.DocType:
                            writer.WriteDocType(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3, (string) page[idxEvent].Object);
                            break;

                        case XmlEventType.StartElem:
                            writer.WriteStartElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                            break;

                        case XmlEventType.StartAttr:
                            writer.WriteStartAttribute(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                            break;

                        case XmlEventType.EndAttr:
                            writer.WriteEndAttribute();
                            break;

                        case XmlEventType.CData:
                            writer.WriteCData(page[idxEvent].String1);
                            break;

                        case XmlEventType.Comment:
                            writer.WriteComment(page[idxEvent].String1);
                            break;

                        case XmlEventType.PI:
                            writer.WriteProcessingInstruction(page[idxEvent].String1, page[idxEvent].String2);
                            break;

                        case XmlEventType.Whitespace:
                            writer.WriteWhitespace(page[idxEvent].String1);
                            break;

                        case XmlEventType.String:
                            writer.WriteString(page[idxEvent].String1);
                            break;

                        case XmlEventType.Raw:
                            writer.WriteRaw(page[idxEvent].String1);
                            break;

                        case XmlEventType.EntRef:
                            writer.WriteEntityRef(page[idxEvent].String1);
                            break;

                        case XmlEventType.CharEnt:
                            writer.WriteCharEntity((char) page[idxEvent].Object);
                            break;

                        case XmlEventType.SurrCharEnt:
                            chars = (char[]) page[idxEvent].Object;
                            writer.WriteSurrogateCharEntity(chars[0], chars[1]);
                            break;

                        case XmlEventType.Base64:
                            bytes = (byte[]) page[idxEvent].Object;
                            writer.WriteBase64(bytes, 0, bytes.Length);
                            break;

                        case XmlEventType.BinHex:
                            bytes = (byte[]) page[idxEvent].Object;
                            writer.WriteBinHex(bytes, 0, bytes.Length);
                            break;

                        case XmlEventType.XmlDecl1:
                            if (rawWriter != null)
                                rawWriter.WriteXmlDeclaration((XmlStandalone) page[idxEvent].Object);
                            break;

                        case XmlEventType.XmlDecl2:
                            if (rawWriter != null)
                                rawWriter.WriteXmlDeclaration(page[idxEvent].String1);
                            break;

                        case XmlEventType.StartContent:
                            if (rawWriter != null)
                                rawWriter.StartElementContent();
                            break;

                        case XmlEventType.EndElem:
                            if (rawWriter != null)
                                rawWriter.WriteEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                            else
                                writer.WriteEndElement();
                            break;

                        case XmlEventType.FullEndElem:
                            if (rawWriter != null)
                                rawWriter.WriteFullEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                            else
                                writer.WriteFullEndElement();
                            break;

                        case XmlEventType.Nmsp:
                            if (rawWriter != null)
                                rawWriter.WriteNamespaceDeclaration(page[idxEvent].String1, page[idxEvent].String2);
                            else
                                writer.WriteAttributeString("xmlns", page[idxEvent].String1, XmlReservedNs.NsXmlNs, page[idxEvent].String2);
                            break;

                        case XmlEventType.EndBase64:
                            if (rawWriter != null)
                                rawWriter.WriteEndBase64();
                            break;

                        case XmlEventType.Close:
                            writer.Close();
                            break;

                        case XmlEventType.Flush:
                            writer.Flush();
                            break;

                        case XmlEventType.Dispose:
                            ((IDisposable)writer).Dispose();
                            break;

                        default:
                            Debug.Assert(false, "Unknown event: " + page[idxEvent].EventType);
                            break;
                    }
                }
            }

            Debug.Assert(false, "Unknown event should be added to end of event sequence.");
        }
 public override void WriteBinHex(byte [] buffer, int index, int count)
 {
     writer.WriteBinHex(buffer, index, count);
 }
Exemplo n.º 5
0
 private static void WriteSerializable( XmlWriter w, object o )
 {
     w.WriteAttributeString( "type", "Object" );
     using( MemoryStream mem = new MemoryStream() )
     {
         BinaryFormatter f = new BinaryFormatter();
         f.Serialize( mem, o );
         byte[] buffer = mem.ToArray();
         w.WriteAttributeString( "size", buffer.Length.ToString() );
         w.WriteBinHex( buffer, 0, buffer.Length );
     }
 }
Exemplo n.º 6
0
 public override void WriteBinHex(byte[] buffer, int index, int count)
 {
     CheckAsync();
     _coreWriter.WriteBinHex(buffer, index, count);
 }
Exemplo n.º 7
0
 private void InvokeMethod(XmlWriter w, string methodName)
 {
     byte[] buffer = new byte[10];
     switch (methodName)
     {
         case "WriteStartDocument":
             w.WriteStartDocument();
             break;
         case "WriteStartElement":
             w.WriteStartElement("root");
             break;
         case "WriteEndElement":
             w.WriteEndElement();
             break;
         case "WriteStartAttribute":
             w.WriteStartAttribute("attr");
             break;
         case "WriteEndAttribute":
             w.WriteEndAttribute();
             break;
         case "WriteCData":
             w.WriteCData("test");
             break;
         case "WriteComment":
             w.WriteComment("test");
             break;
         case "WritePI":
             w.WriteProcessingInstruction("name", "test");
             break;
         case "WriteEntityRef":
             w.WriteEntityRef("e");
             break;
         case "WriteCharEntity":
             w.WriteCharEntity('c');
             break;
         case "WriteSurrogateCharEntity":
             w.WriteSurrogateCharEntity('\uDC00', '\uDBFF');
             break;
         case "WriteWhitespace":
             w.WriteWhitespace(" ");
             break;
         case "WriteString":
             w.WriteString("foo");
             break;
         case "WriteChars":
             char[] charArray = new char[] { 'a', 'b', 'c', 'd' };
             w.WriteChars(charArray, 0, 3);
             break;
         case "WriteRaw":
             w.WriteRaw("<foo>bar</foo>");
             break;
         case "WriteBase64":
             w.WriteBase64(buffer, 0, 9);
             break;
         case "WriteBinHex":
             w.WriteBinHex(buffer, 0, 9);
             break;
         case "LookupPrefix":
             string str = w.LookupPrefix("foo");
             break;
         case "WriteNmToken":
             w.WriteNmToken("foo");
             break;
         case "WriteName":
             w.WriteName("foo");
             break;
         case "WriteQualifiedName":
             w.WriteQualifiedName("foo", "bar");
             break;
         case "WriteValue":
             w.WriteValue(Int32.MaxValue);
             break;
         case "WriteAttributes":
             XmlReader xr1 = ReaderHelper.Create(new StringReader("<root attr='test'/>"));
             xr1.Read();
             w.WriteAttributes(xr1, false);
             break;
         case "WriteNodeReader":
             XmlReader xr2 = ReaderHelper.Create(new StringReader("<root/>"));
             xr2.Read();
             w.WriteNode(xr2, false);
             break;
         case "Flush":
             w.Flush();
             break;
         default:
             CError.Equals(false, "Unexpected param in testcase: {0}", methodName);
             break;
     }
 }
Exemplo n.º 8
0
 public override void WriteBinHex(byte [] buffer, int index, int count)
 {
     writer.WriteBinHex(buffer, index, count);
     state = WriteState.Content;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Replay all cached events to an XmlWriter.
        /// </summary>
        public void EventsToWriter(XmlWriter writer)
        {
            XmlEvent[] page;
            int        idxPage, idxEvent;

            byte[]       bytes;
            char[]       chars;
            XmlRawWriter rawWriter;

            // Special-case single text node at the top-level
            if (this.singleText.Count != 0)
            {
                writer.WriteString(this.singleText.GetResult());
                return;
            }

            rawWriter = writer as XmlRawWriter;

            // Loop over set of pages
            for (idxPage = 0; idxPage < this.pages.Count; idxPage++)
            {
                page = this.pages[idxPage];

                // Loop over events in each page
                for (idxEvent = 0; idxEvent < page.Length; idxEvent++)
                {
                    switch (page[idxEvent].EventType)
                    {
                    case XmlEventType.Unknown:
                        // No more events
                        Debug.Assert(idxPage + 1 == this.pages.Count);
                        return;

                    case XmlEventType.DocType:
                        writer.WriteDocType(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3, (string)page[idxEvent].Object);
                        break;

                    case XmlEventType.StartElem:
                        writer.WriteStartElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                        break;

                    case XmlEventType.StartAttr:
                        writer.WriteStartAttribute(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                        break;

                    case XmlEventType.EndAttr:
                        writer.WriteEndAttribute();
                        break;

                    case XmlEventType.CData:
                        writer.WriteCData(page[idxEvent].String1);
                        break;

                    case XmlEventType.Comment:
                        writer.WriteComment(page[idxEvent].String1);
                        break;

                    case XmlEventType.PI:
                        writer.WriteProcessingInstruction(page[idxEvent].String1, page[idxEvent].String2);
                        break;

                    case XmlEventType.Whitespace:
                        writer.WriteWhitespace(page[idxEvent].String1);
                        break;

                    case XmlEventType.String:
                        writer.WriteString(page[idxEvent].String1);
                        break;

                    case XmlEventType.Raw:
                        writer.WriteRaw(page[idxEvent].String1);
                        break;

                    case XmlEventType.EntRef:
                        writer.WriteEntityRef(page[idxEvent].String1);
                        break;

                    case XmlEventType.CharEnt:
                        writer.WriteCharEntity((char)page[idxEvent].Object);
                        break;

                    case XmlEventType.SurrCharEnt:
                        chars = (char[])page[idxEvent].Object;
                        writer.WriteSurrogateCharEntity(chars[0], chars[1]);
                        break;

                    case XmlEventType.Base64:
                        bytes = (byte[])page[idxEvent].Object;
                        writer.WriteBase64(bytes, 0, bytes.Length);
                        break;

                    case XmlEventType.BinHex:
                        bytes = (byte[])page[idxEvent].Object;
                        writer.WriteBinHex(bytes, 0, bytes.Length);
                        break;

                    case XmlEventType.XmlDecl1:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteXmlDeclaration((XmlStandalone)page[idxEvent].Object);
                        }
                        break;

                    case XmlEventType.XmlDecl2:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteXmlDeclaration(page[idxEvent].String1);
                        }
                        break;

                    case XmlEventType.StartContent:
                        if (rawWriter != null)
                        {
                            rawWriter.StartElementContent();
                        }
                        break;

                    case XmlEventType.EndElem:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                        }
                        else
                        {
                            writer.WriteEndElement();
                        }
                        break;

                    case XmlEventType.FullEndElem:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteFullEndElement(page[idxEvent].String1, page[idxEvent].String2, page[idxEvent].String3);
                        }
                        else
                        {
                            writer.WriteFullEndElement();
                        }
                        break;

                    case XmlEventType.Nmsp:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteNamespaceDeclaration(page[idxEvent].String1, page[idxEvent].String2);
                        }
                        else
                        {
                            writer.WriteAttributeString("xmlns", page[idxEvent].String1, XmlReservedNs.NsXmlNs, page[idxEvent].String2);
                        }
                        break;

                    case XmlEventType.EndBase64:
                        if (rawWriter != null)
                        {
                            rawWriter.WriteEndBase64();
                        }
                        break;

                    case XmlEventType.Close:
                        writer.Close();
                        break;

                    case XmlEventType.Flush:
                        writer.Flush();
                        break;

                    case XmlEventType.Dispose:
                        ((IDisposable)writer).Dispose();
                        break;

                    default:
                        Debug.Assert(false, "Unknown event: " + page[idxEvent].EventType);
                        break;
                    }
                }
            }

            Debug.Assert(false, "Unknown event should be added to end of event sequence.");
        }
Exemplo n.º 10
0
 public void WriteXml(XmlWriter writer)
 {
     writer.WriteStartElement("ID");
     writer.WriteValue(id);
     writer.WriteEndElement();
     writer.WriteStartElement("nodeType");
     writer.WriteValue((int)_cachedType.enumeratedType);
     writer.WriteEndElement();
     writer.WriteStartElement("parentNodeID");
     writer.WriteValue(_parentNode.id);
     writer.WriteEndElement();
     writer.WriteStartElement("driverPort");
     writer.WriteValue(_parentNode.Mydriver.getPort());
     writer.WriteEndElement();
     writer.WriteStartElement("driverEncrypt");
     writer.WriteValue(_parentNode.Mydriver.usesEncryption());
     writer.WriteEndElement();
     if (_parentNode.Mydriver.usesEncryption())
     {
         writer.WriteStartElement("key");
         writer.WriteBinHex(_parentNode.Mydriver.getKey(), 0, 16);
         writer.WriteEndElement();
     }
     _parentNode.Mydriver.Dispose();
 }
Exemplo n.º 11
0
        /// <summary>
        /// Write binary chunk data according to encoding type to xml script.
        /// </summary>
        /// <param name="writer">Xml writer.</param>
        /// <param name="chunkEncoding">Encoding of the chunk.</param>
        /// <param name="chunkData">Chunk data.</param>
        private static void WriteBinaryData(XmlWriter writer, ScriptAcousticChunkEncoding chunkEncoding,
            Collection<float> chunkData)
        {
            Debug.Assert(writer != null);
            Debug.Assert(chunkEncoding == ScriptAcousticChunkEncoding.Base64Binary ||
                chunkEncoding == ScriptAcousticChunkEncoding.HexBinary);

            int bufSize = chunkData.Count * sizeof(float);
            byte[] bytes = new byte[bufSize];
            int bytesIndex = 0;
            for (int i = 0; i < chunkData.Count; i++)
            {
                byte[] floatBytes = BitConverter.GetBytes(chunkData[i]);
                for (int j = 0; j < sizeof(float); j++)
                {
                    bytes[bytesIndex] = floatBytes[j];
                    bytesIndex ++;
                }
            }

            switch (chunkEncoding)
            {
                case ScriptAcousticChunkEncoding.Base64Binary:
                    writer.WriteBase64(bytes, 0, bufSize);
                    break;
                case ScriptAcousticChunkEncoding.HexBinary:
                    writer.WriteBinHex(bytes, 0, bufSize);
                    break;
            }
        }
Exemplo n.º 12
0
        public void EventsToWriter(XmlWriter writer)
        {
            if (this.singleText.Count != 0)
            {
                writer.WriteString(this.singleText.GetResult());
            }
            else
            {
                XmlRawWriter writer2 = writer as XmlRawWriter;
                for (int i = 0; i < this.pages.Count; i++)
                {
                    XmlEvent[] eventArray = this.pages[i];
                    for (int j = 0; j < eventArray.Length; j++)
                    {
                        byte[] buffer;
                        switch (eventArray[j].EventType)
                        {
                        case XmlEventType.Unknown:
                            return;

                        case XmlEventType.DocType:
                        {
                            writer.WriteDocType(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3, (string)eventArray[j].Object);
                            continue;
                        }

                        case XmlEventType.StartElem:
                        {
                            writer.WriteStartElement(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.StartAttr:
                        {
                            writer.WriteStartAttribute(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.EndAttr:
                        {
                            writer.WriteEndAttribute();
                            continue;
                        }

                        case XmlEventType.CData:
                        {
                            writer.WriteCData(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.Comment:
                        {
                            writer.WriteComment(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.PI:
                        {
                            writer.WriteProcessingInstruction(eventArray[j].String1, eventArray[j].String2);
                            continue;
                        }

                        case XmlEventType.Whitespace:
                        {
                            writer.WriteWhitespace(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.String:
                        {
                            writer.WriteString(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.Raw:
                        {
                            writer.WriteRaw(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.EntRef:
                        {
                            writer.WriteEntityRef(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.CharEnt:
                        {
                            writer.WriteCharEntity((char)eventArray[j].Object);
                            continue;
                        }

                        case XmlEventType.SurrCharEnt:
                        {
                            char[] chArray = (char[])eventArray[j].Object;
                            writer.WriteSurrogateCharEntity(chArray[0], chArray[1]);
                            continue;
                        }

                        case XmlEventType.Base64:
                        {
                            buffer = (byte[])eventArray[j].Object;
                            writer.WriteBase64(buffer, 0, buffer.Length);
                            continue;
                        }

                        case XmlEventType.BinHex:
                        {
                            buffer = (byte[])eventArray[j].Object;
                            writer.WriteBinHex(buffer, 0, buffer.Length);
                            continue;
                        }

                        case XmlEventType.XmlDecl1:
                        {
                            if (writer2 != null)
                            {
                                writer2.WriteXmlDeclaration((XmlStandalone)eventArray[j].Object);
                            }
                            continue;
                        }

                        case XmlEventType.XmlDecl2:
                        {
                            if (writer2 != null)
                            {
                                writer2.WriteXmlDeclaration(eventArray[j].String1);
                            }
                            continue;
                        }

                        case XmlEventType.StartContent:
                        {
                            if (writer2 != null)
                            {
                                writer2.StartElementContent();
                            }
                            continue;
                        }

                        case XmlEventType.EndElem:
                        {
                            if (writer2 == null)
                            {
                                break;
                            }
                            writer2.WriteEndElement(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.FullEndElem:
                        {
                            if (writer2 == null)
                            {
                                goto Label_0367;
                            }
                            writer2.WriteFullEndElement(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.Nmsp:
                        {
                            if (writer2 == null)
                            {
                                goto Label_0394;
                            }
                            writer2.WriteNamespaceDeclaration(eventArray[j].String1, eventArray[j].String2);
                            continue;
                        }

                        case XmlEventType.EndBase64:
                        {
                            if (writer2 != null)
                            {
                                writer2.WriteEndBase64();
                            }
                            continue;
                        }

                        case XmlEventType.Close:
                        {
                            writer.Close();
                            continue;
                        }

                        case XmlEventType.Flush:
                        {
                            writer.Flush();
                            continue;
                        }

                        case XmlEventType.Dispose:
                        {
                            writer.Dispose();
                            continue;
                        }

                        default:
                        {
                            continue;
                        }
                        }
                        writer.WriteEndElement();
                        continue;
Label_0367:
                        writer.WriteFullEndElement();
                        continue;
Label_0394:
                        writer.WriteAttributeString("xmlns", eventArray[j].String1, "http://www.w3.org/2000/xmlns/", eventArray[j].String2);
                    }
                }
            }
        }