ToBinary() public method

public ToBinary ( ) : Binary
return Otp.Erlang.Binary
Ejemplo n.º 1
0
        // used by  send and send_reg (message types with payload)
        protected internal virtual void  do_send(OtpOutputStream header, OtpOutputStream payload)
        {
            lock(this)
            {
                try
                {
                    if (traceLevel >= OtpTrace.Type.sendThreshold)
                    {
                        // Need to decode header and output buffer to show trace message!
                        // First make OtpInputStream, then decode.
                        try
                        {
                            if (traceLevel >= OtpTrace.Type.wireThreshold)
                            {
                                Erlang.Object h = (header.getOtpInputStream(5)).read_any();
                                Erlang.Binary hb = header.ToBinary();
                                Erlang.Binary ob = payload.ToBinary();
                                System.Text.StringBuilder s = new System.Text.StringBuilder();
                                s.AppendFormat("-> {0} {1} (header_sz={2}, msg_sz={3})\n" +
                                               "   Header: {4}\n" +
                                               "   Msg:    {5}", headerType(h), h.ToString(), hb.size(), ob.size(),
                                                                 hb.ToBinaryString(), ob.ToBinaryString());
                                OtpTrace.TraceEvent(s.ToString());
                                h  = null;
                                hb = null;
                                ob = null;
                            }
                            else
                            {
                                Erlang.Object h = (header.getOtpInputStream(5)).read_any();
                                OtpTrace.TraceEvent("-> " + headerType(h) + " " + h.ToString());
                                Erlang.Object o = (payload.getOtpInputStream(0)).read_any();
                                OtpTrace.TraceEvent("   " + o.ToString());
                                h = null;
                                o = null;
                            }
                        }
                        catch (Erlang.Exception e)
                        {
                            OtpTrace.TraceEvent("   " + "can't decode output buffer:" + e);
                        }
                    }
                    
                    header.writeTo((System.IO.Stream) socket.GetStream());
                    payload.writeTo((System.IO.Stream) socket.GetStream());

                    long written = header.count() + payload.count();
                    sentBytes += written;
                    sentMsgs++;
                    if (onReadWrite != null)
                        onReadWrite(this, Operation.Write, written, sentBytes, sentMsgs);
                }
                catch (System.Exception e)
                {
                    close();
                    throw e;
                }
            }
        }