Permalink
Browse files

Add methods to read/write matrix to base64

  • Loading branch information...
1 parent b7d925c commit 5f7793be8ec89813966b2e1499b831a18efc8aa7 @bradleybuda committed Nov 1, 2011
Showing with 13 additions and 0 deletions.
  1. +13 −0 params_matrix.rb
View
@@ -1,4 +1,5 @@
require 'matrix'
+require 'stringio'
class ParamsMatrix
ROWS = 8
@@ -21,6 +22,18 @@ def self.write(io, matrix)
end
end
+ def self.to_base64(matrix)
+ io = StringIO.new
+ write(io, matrix)
+ [io.string].pack("m0")
+ end
+
+ def self.from_base64(str)
+ bytes = str.unpack("m0").first
+ io = StringIO.new(bytes)
+ read(io)
+ end
+
def self.with_binary_io(io)
io.binmode
return yield

0 comments on commit 5f7793b

Please sign in to comment.