Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/rbor/string.rb
Instance Method Summary collapse
-
#cbor_deserialize ⇒ Object
Treat the object as CBOR ‘BINARY` data and deserialize it into a Ruby object.
-
#cbor_serialize(options = {}) ⇒ String
Serialize a String into a CBOR string.
Instance Method Details
#cbor_deserialize ⇒ Object
Treat the object as CBOR ‘BINARY` data and deserialize it into a Ruby object.
Depending on the major type of the CBOR data, this method will return a object of one of the following types:
-
major type 0: Integer
-
major type 1: Integer
-
major type 2: String
-
major type 3: String
-
major type 4: Array
-
major type 5: Hash
-
major type 7: FalseClass, TrueClass, NilClass
16 17 18 |
# File 'lib/rbor/string.rb', line 16 def cbor_deserialize return self.bytes.cbor_deserialize end |
#cbor_serialize(options = {}) ⇒ String
Serialize a String into a CBOR string.
If the ‘encoding` is of type `UTF-8`, the object will be serialized to a text string (major type 3). Otherwise, the obejct will be serialized to a byte string (major type 2).
29 30 31 32 33 34 35 36 37 |
# File 'lib/rbor/string.rb', line 29 def cbor_serialize( = {}) len = self.bytesize.cbor_serialize.bytes mt = 2 if self.encoding.to_s == "UTF-8" mt = 3 end len[0] = mt << 5 | len[0] return len.pack('C*') + String.new(self, encoding: "BINARY") end |