Module: XDR::Concerns::ConvertsToXDR
- Includes:
- ReadsBytes
- Included in:
- Array, Bool, Double, Enum, Float, Hyper, Int, Opaque, Option, Quadruple, String, Struct, Union, UnsignedHyper, UnsignedInt, VarArray, VarOpaque, Void
- Defined in:
- lib/xdr/concerns/converts_to_xdr.rb
Instance Method Summary collapse
-
#from_xdr(string) ⇒ Object
Deserializes an object from the provided string of bytes.
-
#read(io) ⇒ Object
Reads from the provided IO an instance of the implementing class.
-
#to_xdr(val) ⇒ String
Serialized the provided val to xdr, returning a string of the serialized data.
-
#valid?(value) ⇒ Boolean
Returns true if the value provided is compatible with this serializer class.
-
#write(val, io) ⇒ Object
Serialized the provided ‘val` to xdr and writes it to `io`.
Instance Method Details
#from_xdr(string) ⇒ Object
Deserializes an object from the provided string of bytes
53 54 55 56 |
# File 'lib/xdr/concerns/converts_to_xdr.rb', line 53 def from_xdr(string) io = StringIO.new(string) read(io) end |
#read(io) ⇒ Object
Reads from the provided IO an instance of the implementing class
19 20 21 |
# File 'lib/xdr/concerns/converts_to_xdr.rb', line 19 def read(io) raise NotImplementedError, "implement in including class" end |
#to_xdr(val) ⇒ String
Serialized the provided val to xdr, returning a string of the serialized data
40 41 42 43 44 45 |
# File 'lib/xdr/concerns/converts_to_xdr.rb', line 40 def to_xdr(val) StringIO. new. tap{|io| write(val, io)}. string.force_encoding("ASCII-8BIT") end |
#valid?(value) ⇒ Boolean
Returns true if the value provided is compatible with this serializer class
29 30 31 |
# File 'lib/xdr/concerns/converts_to_xdr.rb', line 29 def valid?(value) raise NotImplementedError, "implement in including class" end |
#write(val, io) ⇒ Object
Serialized the provided ‘val` to xdr and writes it to `io`
10 11 12 |
# File 'lib/xdr/concerns/converts_to_xdr.rb', line 10 def write(val, io) raise NotImplementedError, "implement in including class" end |