ruby-proto 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 288e832ce33fa46a784c2f04fcb3576ac4592cef
4
- data.tar.gz: 16a953f60bc9e7be6e17ca8cbeacdc9140ac9ff9
3
+ metadata.gz: e87020c7b71fdd90d663ba80ce739b01ffa8f52c
4
+ data.tar.gz: 88fb1c6324714210b25a58973a70e4c0b8f6e71e
5
5
  SHA512:
6
- metadata.gz: fe4aac18c236212f5005f3aad8207e23d35c5ae5c8e8e5fc5dba0c3195b0490eab1f5c5a9a3863674d385b55ba28b1025249ed1f522651ed1b4c6fc52364dd3b
7
- data.tar.gz: a6422f0492ab86e7bc7bb48028717ff2d3e24fbf11d62a8adcb7266abda6956c1014d2d09e02828a3bdb92d72742b610046f69f683147e505405bf6baac90f78
6
+ metadata.gz: 9429b8189fc3928ebed4ed4e4d4477aafc10565e0bb56054b073db4733b428709772bd214436e11f076e4c5d965cde375026b7e99ddc5cb384caaac7ab6280a6
7
+ data.tar.gz: 5ff1373821a00a9771f34aa1be5a80aba82cbb417fd030efe247d0bfeb76b14531d9572a172c3757ede428d202ee55a51b4a745cde1e433c4cd356e77537f106
data/lib/ruby/proto.rb CHANGED
@@ -63,4 +63,98 @@ module Ruby
63
63
  end
64
64
  end
65
65
  end
66
+
67
+ module SerialData
68
+ class << self
69
+ def intToByteArray(_value, _length = 4)
70
+ arr = []
71
+ _length.times do |_index|
72
+ val = _value & 0xff;
73
+ _value = _value >> 8;
74
+ arr.push(val)
75
+ end
76
+ arr
77
+ end
78
+
79
+ def byteArrayToInt(_arr)
80
+ value = 0
81
+ _arr.reverse_each do |_byte|
82
+ # puts "#{__callee__} byte:[#{_byte}]"
83
+ value = value << 8
84
+ value = value | _byte
85
+ end
86
+ value
87
+ end
88
+ end
89
+
90
+ def storeInt32(_value)
91
+ doStoreInt_(_value, 4)
92
+ end
93
+
94
+ def storeInt16(_value)
95
+ doStoreInt_(_value, 2)
96
+ end
97
+
98
+ def storeInt8(_value)
99
+ doStoreInt_(_value, 1)
100
+ end
101
+
102
+ def loadInt8
103
+ doLoadInt_(1)
104
+ end
105
+
106
+ def loadInt16
107
+ doLoadInt_(2)
108
+ end
109
+
110
+ def loadInt32
111
+ doLoadInt_(4)
112
+ end
113
+
114
+ private
115
+ def doStoreInt_(_value, _length)
116
+ arr = SerialData.intToByteArray(_value, _length)
117
+ str = arr.pack("C#{_length}")
118
+ writeDataImp(str)
119
+ end
120
+
121
+ def doLoadInt_(_length)
122
+ str = readDataImp(_length)
123
+ return 0 if str.nil? || str.empty?
124
+ _length = str.length
125
+ arr = str.unpack("C#{_length}")
126
+ SerialData.byteArrayToInt(arr)
127
+ end
128
+ end
129
+
130
+ class SerialString
131
+ include SerialData
132
+ attr_reader :str, :read_index
133
+
134
+ def initialize(_value = "")
135
+ resetString(_value)
136
+ end
137
+
138
+ def resetString(_value = "")
139
+ @str = ""
140
+ @str.encode!("binary")
141
+ _value = _value || ""
142
+ @str <<_value
143
+ @read_index = 0
144
+ end
145
+
146
+ private
147
+ def writeDataImp(_str)
148
+ @str << _str
149
+ end
150
+
151
+ def readDataImp(_length)
152
+ str = @str.slice(@read_index, _length)
153
+ return str if str.nil? || str.empty?
154
+ _length = str.length
155
+ @read_index += _length
156
+ str
157
+ end
158
+ end
159
+
66
160
  end
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module Proto
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-proto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rubyer