Module: Sidetree::Util::AnchoredDataSerializer
- Defined in:
- lib/sidetree/util/anchored_data_serializer.rb
Constant Summary collapse
- DELIMITER =
"."
Class Method Summary collapse
-
.deserialize(anchor_str) ⇒ Array[Integer, String]
Deserializes the given string that is read from the blockchain into data.
-
.serialize(op_count, uri) ⇒ String
Serialize given data as Anchor String.
Class Method Details
.deserialize(anchor_str) ⇒ Array[Integer, String]
Deserializes the given string that is read from the blockchain into data.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sidetree/util/anchored_data_serializer.rb', line 24 def deserialize(anchor_str) data = anchor_str.split(DELIMITER) raise Sidetree::Error, "Invalid anchor string" unless data.length == 2 unless data[0] =~ /^[1-9]\d*$/ raise Sidetree::Error, "Number of operations in anchor string is not positive number" end count = data[0].to_i if count > Sidetree::Params::MAX_OPERATION_COUNT raise Sidetree::Error, "Number of operations in anchor string greater than max" end [count, data[1]] end |
.serialize(op_count, uri) ⇒ String
Serialize given data as Anchor String.
13 14 15 16 17 18 |
# File 'lib/sidetree/util/anchored_data_serializer.rb', line 13 def serialize(op_count, uri) if op_count > Sidetree::Params::MAX_OPERATION_COUNT raise Sidetree::Error, "Number of operations greater than max" end "#{op_count}#{DELIMITER}#{uri}" end |