[erlang-questions] Otp.NET: It would be nice to have seamless string support

Roessner, Silvester silvester.roessner@REDACTED
Wed Apr 29 08:11:57 CEST 2009


Hi,

(sorry for the former incomplete e-mail - I hit enter by accident)

I think it would be usefull to have a real Otp.Erlang.List object
that combines Otp.Erlang.List and Otp.Erlang.String.

This object should have a constructor String(string S)
and a methode stringValue().


The reason why I think this is sensible:

I run into a problem while I tried to send Otp.Erlang.String 
with length > 64k from a OTP.Net node to a native Erlang node.
The Erlang node only received a cut string, not the full one.

The cause of this trouble is the strong adherence of OTP.Net 
to the external term format.

The Erlang node sends a list in an external term "STRING_EXT"
when the list length < 64k and all list entries are integers 
in the range 0..255

But it sends a list as an external term "LIST_EXT" otherwise.

OTP.Net has implemented Otp.Erlang.String but this is not a 
real Erlang type only an external term.

When I use OTP.Net to receive from or send strings to another 
node I have to manually distinguish between these two cases.


Receiver:
                    ....
                    try
                    {
                        Otp.Erlang.String S =
(Otp.Erlang.String)Tuple.elementAt(1);
                        Payload = S.stringValue();
                    }
                    catch (InvalidCastException)
                    {
                        Otp.Erlang.List List =
(Otp.Erlang.List)Tuple.elementAt(1);
                        Payload = stringValue(List);
                    }
                    ....


        private string stringValue(Otp.Erlang.List L)
        {
            System.Text.StringBuilder s = new
System.Text.StringBuilder();
            int _arity = L.Length;
            Otp.Erlang.Long E_Char;
						
			for (int i = 0; i < _arity; i++)
			{
                                E_Char =
(Otp.Erlang.Long)L.elementAt(i);
				s.Append(E_Char.charValue());
			}
						
			return s.ToString();
        }



Sender:

                    ....
                    Otp.Erlang.Object[] Message = new
Otp.Erlang.Object[2];
                    Message[0] = new Otp.Erlang.Int(L);

                    if (L < 65000) 
                    {
                        Message[1] = new Otp.Erlang.String(Payload);
                    }
                    else
                    {
                        Otp.Erlang.String Test = new
Otp.Erlang.String(Payload);
                        int LL = Test.stringValue().Length;
                        new Otp.Erlang.List(
                        Message[1] = toList(Payload);
                    }
                    
                    Box.send(Other, new Tuple(Message));
                    ....


        private Otp.Erlang.List toList(string S)
        {
            int _arity = S.Length;
            Otp.Erlang.Object[] Longs = new Otp.Erlang.Object[_arity];

            for (int i = 0; i < _arity; i++)
            {
                Longs[i] = new Otp.Erlang.Long(S[i]);
            }

            return new Otp.Erlang.List(Longs);
        }
This message is intended for a particular addressee only and
may contain business or company secrets. If you have received
this email in error, please contact the sender and delete the
message immediately. Any use of this email, including saving,
publishing, copying, replication or forwarding of the message
or the contents is not permitted.




More information about the erlang-questions mailing list