@@ -79,6 +79,9 @@ def b_ord(character):
7979_TAG_NEW_FLOAT_EXT = 70
8080_TAG_BIT_BINARY_EXT = 77
8181_TAG_ATOM_CACHE_REF = 78
82+ _TAG_NEW_PID_EXT = 88
83+ _TAG_NEW_PORT_EXT = 89
84+ _TAG_NEWER_REFERENCE_EXT = 90
8285_TAG_SMALL_INTEGER_EXT = 97
8386_TAG_INTEGER_EXT = 98
8487_TAG_FLOAT_EXT = 99
@@ -274,10 +277,19 @@ def binary(self):
274277 """
275278 return encoded representation
276279 """
277- return (
278- b_chr (_TAG_PID_EXT ) +
279- self .node .binary () + self .id + self .serial + self .creation
280- )
280+ creation_size = len (self .creation )
281+ if creation_size == 1 :
282+ return (
283+ b_chr (_TAG_PID_EXT ) +
284+ self .node .binary () + self .id + self .serial + self .creation
285+ )
286+ elif creation_size == 4 :
287+ return (
288+ b_chr (_TAG_NEW_PID_EXT ) +
289+ self .node .binary () + self .id + self .serial + self .creation
290+ )
291+ else :
292+ raise OutputException ('unknown pid type' )
281293 def __repr__ (self ):
282294 return '%s(%s,%s,%s,%s)' % (
283295 self .__class__ .__name__ ,
@@ -303,10 +315,19 @@ def binary(self):
303315 """
304316 return encoded representation
305317 """
306- return (
307- b_chr (_TAG_PORT_EXT ) +
308- self .node .binary () + self .id + self .creation
309- )
318+ creation_size = len (self .creation )
319+ if creation_size == 1 :
320+ return (
321+ b_chr (_TAG_PORT_EXT ) +
322+ self .node .binary () + self .id + self .creation
323+ )
324+ elif creation_size == 4 :
325+ return (
326+ b_chr (_TAG_NEW_PORT_EXT ) +
327+ self .node .binary () + self .id + self .creation
328+ )
329+ else :
330+ raise OutputException ('unknown port type' )
310331 def __repr__ (self ):
311332 return '%s(%s,%s,%s)' % (
312333 self .__class__ .__name__ ,
@@ -338,11 +359,21 @@ def binary(self):
338359 self .node .binary () + self .id + self .creation
339360 )
340361 elif length <= 65535 :
341- return (
342- b_chr (_TAG_NEW_REFERENCE_EXT ) +
343- struct .pack (b'>H' , length ) +
344- self .node .binary () + self .creation + self .id
345- )
362+ creation_size = len (self .creation )
363+ if creation_size == 1 :
364+ return (
365+ b_chr (_TAG_NEW_REFERENCE_EXT ) +
366+ struct .pack (b'>H' , length ) +
367+ self .node .binary () + self .creation + self .id
368+ )
369+ elif creation_size == 4 :
370+ return (
371+ b_chr (_TAG_NEWER_REFERENCE_EXT ) +
372+ struct .pack (b'>H' , length ) +
373+ self .node .binary () + self .creation + self .id
374+ )
375+ else :
376+ raise OutputException ('unknown reference type' )
346377 else :
347378 raise OutputException ('uint16 overflow' )
348379 def __repr__ (self ):
@@ -478,24 +509,33 @@ def _binary_to_term(i, data):
478509 j = struct .unpack (b'>H' , data [i :i + 2 ])[0 ]
479510 i += 2
480511 return (i + j , OtpErlangAtom (data [i :i + j ]))
481- elif tag == _TAG_REFERENCE_EXT or tag == _TAG_PORT_EXT :
512+ elif (tag == _TAG_NEW_PORT_EXT or
513+ tag == _TAG_REFERENCE_EXT or tag == _TAG_PORT_EXT ):
482514 i , node = _binary_to_atom (i , data )
483515 id_value = data [i :i + 4 ]
484516 i += 4
485- creation = data [i :i + 1 ]
486- i += 1
487- if tag == _TAG_REFERENCE_EXT :
488- return (i , OtpErlangReference (node , id_value , creation ))
489- # tag == _TAG_PORT_EXT
517+ if tag == _TAG_NEW_PORT_EXT :
518+ creation = data [i :i + 4 ]
519+ i += 4
520+ else :
521+ creation = data [i :i + 1 ]
522+ i += 1
523+ if tag == _TAG_REFERENCE_EXT :
524+ return (i , OtpErlangReference (node , id_value , creation ))
525+ # tag == _TAG_NEW_PORT_EXT or tag == _TAG_PORT_EXT
490526 return (i , OtpErlangPort (node , id_value , creation ))
491- elif tag == _TAG_PID_EXT :
527+ elif tag == _TAG_NEW_PID_EXT or tag == _TAG_PID_EXT :
492528 i , node = _binary_to_atom (i , data )
493529 id_value = data [i :i + 4 ]
494530 i += 4
495531 serial = data [i :i + 4 ]
496532 i += 4
497- creation = data [i :i + 1 ]
498- i += 1
533+ if tag == _TAG_NEW_PID_EXT :
534+ creation = data [i :i + 4 ]
535+ i += 4
536+ elif tag == _TAG_PID_EXT :
537+ creation = data [i :i + 1 ]
538+ i += 1
499539 return (i , OtpErlangPid (node , id_value , serial , creation ))
500540 elif tag == _TAG_SMALL_TUPLE_EXT or tag == _TAG_LARGE_TUPLE_EXT :
501541 if tag == _TAG_SMALL_TUPLE_EXT :
@@ -554,12 +594,16 @@ def _binary_to_term(i, data):
554594 _ = b_ord (data [i ])
555595 i += 1
556596 return (i , OtpErlangFunction (tag , data [old_i :i ]))
557- elif tag == _TAG_NEW_REFERENCE_EXT :
597+ elif tag == _TAG_NEWER_REFERENCE_EXT or tag == _TAG_NEW_REFERENCE_EXT :
558598 j = struct .unpack (b'>H' , data [i :i + 2 ])[0 ] * 4
559599 i += 2
560600 i , node = _binary_to_atom (i , data )
561- creation = data [i :i + 1 ]
562- i += 1
601+ if tag == _TAG_NEWER_REFERENCE_EXT :
602+ creation = data [i :i + 4 ]
603+ i += 4
604+ elif tag == _TAG_NEW_REFERENCE_EXT :
605+ creation = data [i :i + 1 ]
606+ i += 1
563607 return (i + j , OtpErlangReference (node , data [i : i + j ], creation ))
564608 elif tag == _TAG_SMALL_ATOM_EXT :
565609 j = b_ord (data [i ])
@@ -648,7 +692,16 @@ def _binary_to_integer(i, data):
648692def _binary_to_pid (i , data ):
649693 tag = b_ord (data [i ])
650694 i += 1
651- if tag == _TAG_PID_EXT :
695+ if tag == _TAG_NEW_PID_EXT :
696+ i , node = _binary_to_atom (i , data )
697+ id_value = data [i :i + 4 ]
698+ i += 4
699+ serial = data [i :i + 4 ]
700+ i += 4
701+ creation = data [i :i + 4 ]
702+ i += 4
703+ return (i , OtpErlangPid (node , id_value , serial , creation ))
704+ elif tag == _TAG_PID_EXT :
652705 i , node = _binary_to_atom (i , data )
653706 id_value = data [i :i + 4 ]
654707 i += 4
0 commit comments