Otp.OtpOutputStream.write_string C# (CSharp) Метод

write_string() публичный Метод

public write_string ( System s ) : void
s System
Результат void
        public virtual void  write_string(System.String s)
        {
            int len = s.Length;
            
            switch (len)
            {
                case 0: 
                    this.write_nil();
                    break;
                
                default:
                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    Byte[] bytebuf = encoding.GetBytes(s);
                    if (bytebuf.Length < 0xffff)
                    {
                        this.write1(OtpExternal.stringTag);
                        this.write2BE(len);
                        this.writeN(bytebuf);
                    }
                    else
                    {
                        this.write_list_head(len);
                        for (int i2 = 0; i2 < len; i2++)
                            this.write_byte(bytebuf[i2]);
                        this.write_nil();
                    }

                    /*
                    //UPGRADE_NOTE: This code will be optimized in the future;
                    byte[] tmpBytes;
                    int i;
                    string tmpStr;
                    tmpStr = s;
                    tmpBytes = new byte[tmpStr.Length];
                    i = 0;
                    while (i < tmpStr.Length)
                    {
                        tmpBytes[i] = (byte) tmpStr[i];
                        i++;
                    }
                    byte[] bytebuf = tmpBytes;

                    if (bytebuf.Length == len)
                    {
                        // Usual
                        this.write1(OtpExternal.stringTag);
                        this.write2BE(len);
                        this.writeN(bytebuf);
                    }
                    else
                    {
                        // Unicode
                        char[] charbuf = s.ToCharArray();
                        
                        this.write_list_head(len);
                        
                         for (int i2 = 0; i2 < len; i2++)
                            this.write_char(charbuf[i2]);
                        
                        this.write_nil();
                    }
                    */
                    break;
                
            }
        }
        

Usage Example

Пример #1
0
 private void  sendExit(int tag, Erlang.Pid from, Erlang.Pid dest, System.String reason)
 {
     if (!connected)
     {
         throw new System.IO.IOException("Not connected");
     }
     OtpOutputStream header = new OtpOutputStream(headerLen);
     
     // preamble: 4 byte length + "passthrough" tag
     header.write4BE(0); // reserve space for length
     header.write1(passThrough);
     header.write1(version);
     
     // header
     header.write_tuple_head(4);
     header.write_long(tag);
     header.write_any(from);
     header.write_any(dest);
     header.write_string(reason);
     
     // fix up length in preamble
     header.poke4BE(0, header.count() - 4);
     
     do_send(header);
 }