Module: Erlang::ETF::Term

Overview

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

BINARY_ENCODING =
Encoding.find('binary')
ERLANG_MAGIC_BYTE =
131.chr.force_encoding(BINARY_ENCODING).freeze
SMALL_INTEGER_EXT =
97.freeze
INTEGER_EXT =
98.freeze
FLOAT_EXT =
99.freeze
ATOM_EXT =
100.freeze
REFERENCE_EXT =
101.freeze
PORT_EXT =
102.freeze
PID_EXT =
103.freeze
SMALL_TUPLE_EXT =
104.freeze
LARGE_TUPLE_EXT =
105.freeze
NIL_EXT =
106.freeze
STRING_EXT =
107.freeze
LIST_EXT =
108.freeze
BINARY_EXT =
109.freeze
SMALL_BIG_EXT =
110.freeze
LARGE_BIG_EXT =
111.freeze
NEW_REFERENCE_EXT =
114.freeze
SMALL_ATOM_EXT =
115.freeze
FUN_EXT =
117.freeze
NEW_FUN_EXT =
112.freeze
EXPORT_EXT =
113.freeze
BIT_BINARY_EXT =
77.freeze
NEW_FLOAT_EXT =
70.freeze
ATOM_UTF8_EXT =
118.freeze
SMALL_ATOM_UTF8_EXT =
119.freeze
MAP_EXT =
116.freeze
DIST_HEADER =

not implemented

68.freeze
ATOM_CACHE_REF =

not implemented

82.freeze
ATOM_INTERNAL_REF2 =

not implemented

73.freeze
ATOM_INTERNAL_REF3 =

not implemented

75.freeze
BINARY_INTERNAL_REF =

not implemented

74.freeze
BIT_BINARY_INTERNAL_REF =

not implemented

76.freeze
COMPRESSED =
80.freeze
INT8 =

8-bit signed (signed char)

'c'.freeze
INT16 =

16-bit signed, native endian (int16_t)

's'.freeze
INT32 =

32-bit signed, native endian (int32_t)

'l'.freeze
INT64 =

64-bit signed, native endian (int64_t)

'q'.freeze
INT128 =

128-bit signed, native endian (int128_t)

'qq'.freeze
INT16BE =

16-bit signed, big-endian

's>'.freeze
INT32BE =

32-bit signed, big-endian

'l>'.freeze
INT64BE =

64-bit signed, big-endian

'q>'.freeze
INT128BE =

128-bit signed, big-endian

'q>q>'.freeze
INT16LE =

16-bit signed, little-endian

's<'.freeze
INT32LE =

32-bit signed, little-endian

'l<'.freeze
INT64LE =

64-bit signed, little-endian

'q<'.freeze
INT128LE =

128-bit signed, little-endian

'q<q<'.freeze
UINT8 =

8-bit unsigned (unsigned char)

'C'.freeze
UINT16 =

16-bit unsigned, native endian (uint16_t)

'S'.freeze
UINT32 =

32-bit unsigned, native endian (uint32_t)

'L'.freeze
UINT64 =

64-bit unsigned, native endian (uint64_t)

'Q'.freeze
UINT128 =

128-bit unsigned, native endian (uint128_t)

'QQ'.freeze
UINT16BE =

16-bit unsigned, network (big-endian) byte order

'n'.freeze
UINT32BE =

32-bit unsigned, network (big-endian) byte order

'N'.freeze
UINT64BE =

64-bit unsigned, network (big-endian) byte order

'Q>'.freeze
UINT128BE =

128-bit unsigned, network (big-endian) byte order

'Q>Q>'.freeze
UINT16LE =

16-bit unsigned, VAX (little-endian) byte order

'v'.freeze
UINT32LE =

32-bit unsigned, VAX (little-endian) byte order

'V'.freeze
UINT64LE =

64-bit unsigned, VAX (little-endian) byte order

'Q<'.freeze
UINT128LE =

128-bit unsigned, VAX (little-endian) byte order

'Q<Q<'.freeze
SINGLE =

32-bit single-precision, native format

'F'.freeze
DOUBLE =

64-bit double-precision, native format

'D'.freeze
SINGLEBE =

32-bit sinlge-precision, network (big-endian) byte order

'g'.freeze
DOUBLEBE =

64-bit double-precision, network (big-endian) byte order

'G'.freeze
SINGLELE =

32-bit sinlge-precision, little-endian byte order

'e'.freeze
DOUBLELE =

64-bit double-precision, little-endian byte order

'E'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.binary_encoding(string) ⇒ Object



102
103
104
105
106
# File 'lib/erlang/etf/term.rb', line 102

def self.binary_encoding(string)
  string = string.dup if string.frozen?
  string = string.force_encoding(BINARY_ENCODING)
  return string
end

.included(base) ⇒ Object

Extends the including class with +ClassMethods+.

Parameters:

  • subclass (Class)

    the inheriting class



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/erlang/etf/term.rb', line 84

def included(base)
  super
  # base.send(:include, ::Binary::Protocol)
  base.send(:include, Erlang::Immutable)
  base.extend ClassMethods
  base.send(:include, ::Comparable)
  base.class_eval do
    attr_reader :term
    alias :to_erlang :term
    memoize :erlang_external_type
  end
end

Instance Method Details

#<=>(other) ⇒ Object



131
132
133
# File 'lib/erlang/etf/term.rb', line 131

def <=>(other)
  return Erlang.compare(self, other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/erlang/etf/term.rb', line 127

def eql?(other)
  return @term.eql?(other)
end

#erlang_external_typeObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/erlang/etf/term.rb', line 108

def erlang_external_type
  type = self.class.name.split('::').last.dup
  type.gsub!('::', '/')
  type.gsub!(/(?:([A-Za-z\d])|^)(UTF8)(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
  type.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  type.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  type.tr!("-", "_")
  type.downcase!
  return type.intern
end

#hashObject



123
124
125
# File 'lib/erlang/etf/term.rb', line 123

def hash
  return @term.hash
end

#inspectObject



119
120
121
# File 'lib/erlang/etf/term.rb', line 119

def inspect
  return "#{self.class.name}[#{term.inspect}]"
end

#to_erlang_etfObject



135
136
137
# File 'lib/erlang/etf/term.rb', line 135

def to_erlang_etf
  return self
end