Skip to content

Commit

Permalink
Small clean-ups for message ID code
Browse files Browse the repository at this point in the history
  • Loading branch information
hdima committed Feb 28, 2016
1 parent c8cfacb commit 246b772
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions priv/python2/erlport/erlang.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
from erlport import Atom


def new_message_id():
return uuid.uuid4().int

class Error(Exception):
"""ErlPort Error."""

Expand Down Expand Up @@ -109,6 +106,9 @@ def __init__(self, port):
self._self = None
self.responses = Responses()

def new_message_id(self):
return uuid.uuid4().int

def set_default_encoder(self):
self.encoder = lambda o: o

Expand Down Expand Up @@ -203,7 +203,7 @@ def make_ref(self):
return self._call(Atom('erlang'), Atom('make_ref'), [], Atom('L'))

def _call(self, module, function, args, context):
mid = new_message_id()
mid = self.new_message_id()
self.port.write((Atom('C'), mid, module, function,
map(self.encoder, args), context))

Expand Down
10 changes: 4 additions & 6 deletions priv/python3/erlport/erlang.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
from erlport import Atom


def new_message_id():
return uuid.uuid4().int

class Error(Exception):
"""ErlPort Error."""

Expand Down Expand Up @@ -105,6 +102,9 @@ def __init__(self, port):
self._self = None
self.responses = Responses()

def new_message_id(self):
return uuid.uuid4().int

def set_default_encoder(self):
self.encoder = lambda o: o

Expand Down Expand Up @@ -200,8 +200,7 @@ def make_ref(self):
return self._call(Atom(b'erlang'), Atom(b'make_ref'), [], Atom(b'L'))

def _call(self, module, function, args, context):
mid = new_message_id()

mid = self.new_message_id()
self.port.write((Atom(b'C'), mid, module, function,
# TODO: Optimize list(map())
list(map(self.encoder, args)), context))
Expand All @@ -216,7 +215,6 @@ def _call(self, module, function, args, context):
if mtype == b"e":
raise CallError(value)
raise UnknownMessage(response)

return self.decoder(value)

def _incoming_call(self, mid, module, function, args):
Expand Down
2 changes: 1 addition & 1 deletion priv/ruby1.8/erlport/erlang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def put response_id, message, default=nil

class MessageId
def generate &code
code.call SecureRandom.random_number(2 << 128)
code.call SecureRandom.random_number(1 << 128)
end
end
end
Expand Down

0 comments on commit 246b772

Please sign in to comment.