bytes 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -2
- data/Rakefile +1 -1
- data/lib/bytes/version.rb +2 -2
- data/lib/bytes.rb +15 -11
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d93d96204652bc075816b6b9a32220b7f1f72fa3765379012ecea3dfc4485c3
|
4
|
+
data.tar.gz: ba15bcb1f6939fd5ddb4d42da815a9ecb7edfc42e785c81bc8845101dc819b9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3f41e967326e54022df7c16257fab59dc8bfe3d0402ba74670b16532d086162b74156937e3b4f40f2a09aee5a73521e1399b0329232da418a18599a48cfcfe1
|
7
|
+
data.tar.gz: 71726839412c32893a6f1a243cf4d00d84ba1558379f39e2e355940b645a5970a72c07a249481f11046486853926d8afd44aa28b4ef7ebc90afc9674534eaeb0
|
data/README.md
CHANGED
@@ -246,12 +246,72 @@ To be continued ...
|
|
246
246
|
|
247
247
|
|
248
248
|
|
249
|
+
## Usage
|
249
250
|
|
251
|
+
### BytesHelper - From Bytes (Binary String) to Hex(adecimal) String and Back
|
252
|
+
|
253
|
+
``` ruby
|
254
|
+
require 'bytes
|
255
|
+
|
256
|
+
Bytes.bin_to_hex( "\x61\x62".b )
|
257
|
+
#=> '6162'
|
258
|
+
|
259
|
+
Bytes.hex_to_bin( '6162' ) # or
|
260
|
+
Bytes.hex_to_bin( '0x6162' ) # or
|
261
|
+
#=> "\x61\x62".b
|
262
|
+
|
263
|
+
Bytes.is_hex?( '6162' )
|
264
|
+
Bytes.is_hex?( '0x6162' )
|
265
|
+
Bytes.is_hex?( '' ) # empty string or
|
266
|
+
Bytes.is_hex?( '0x' ) # empty hex string
|
267
|
+
#=> true
|
268
|
+
|
269
|
+
Bytes.is_hex?( 'xyz' )
|
270
|
+
Bytes.is_hex?( '0xyz' )
|
271
|
+
#=> false
|
272
|
+
|
273
|
+
Bytes.hex_to_bin( 'xzy' ) # or
|
274
|
+
Bytes.hex_to_bin( '0xxzy' )
|
275
|
+
#=> raises TypeError - non-hexadecimal digit found
|
276
|
+
```
|
277
|
+
|
278
|
+
Note: You can use the shorter alternate alias
|
279
|
+
names `btoh` or `htob`
|
280
|
+
for `bin_to_hex` and `hex_to_bin`.
|
281
|
+
|
282
|
+
|
283
|
+
Or use the mixed-in String class variants. Example:
|
284
|
+
|
285
|
+
``` ruby
|
286
|
+
"\x61\x62".b.bin_to_hex # or
|
287
|
+
"\x61\x62".b.btoh
|
288
|
+
#=> '6162'
|
289
|
+
|
290
|
+
'6162'.hex_to_bin # or
|
291
|
+
'6162'.htob # or
|
292
|
+
'0x6162'.hex_to_bin # or
|
293
|
+
'0x6162'.htob # or
|
294
|
+
#=> "\x61\x62".b
|
295
|
+
|
296
|
+
'6162'.is_hex?
|
297
|
+
'0x6162'is_hex?
|
298
|
+
''.is_hex? # empty string or
|
299
|
+
'0x'.is_hex? # empty hex string
|
300
|
+
#=> true
|
301
|
+
|
302
|
+
'xyz'is_hex?
|
303
|
+
'0xyz'.is_hex?
|
304
|
+
#=> false
|
305
|
+
|
306
|
+
'xzy'.htob # or
|
307
|
+
'0xxzy'.htob
|
308
|
+
#=> raises TypeError - non-hexadecimal digit found
|
309
|
+
```
|
310
|
+
|
311
|
+
and so on.
|
250
312
|
|
251
313
|
|
252
|
-
## Usage
|
253
314
|
|
254
|
-
To be done
|
255
315
|
|
256
316
|
|
257
317
|
## License
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ Hoe.spec 'bytes' do
|
|
6
6
|
|
7
7
|
self.version = Cocos::Module::Bytes::VERSION
|
8
8
|
|
9
|
-
self.summary = "bytes"
|
9
|
+
self.summary = "bytes - bits 'n' bytes made easy/easier incl. new buffer helper / wrapper class to help with the string byte vs character dichotomy"
|
10
10
|
self.description = summary
|
11
11
|
|
12
12
|
|
data/lib/bytes/version.rb
CHANGED
data/lib/bytes.rb
CHANGED
@@ -6,6 +6,7 @@ require 'forwardable'
|
|
6
6
|
require_relative 'bytes/version' # note: let version always go first
|
7
7
|
|
8
8
|
|
9
|
+
|
9
10
|
module BytesHelper
|
10
11
|
def hex_to_bin( hex )
|
11
12
|
## todo/fix: do an argument regex hex check!!!!
|
@@ -18,8 +19,8 @@ module BytesHelper
|
|
18
19
|
[hex].pack('H*')
|
19
20
|
end
|
20
21
|
end
|
21
|
-
alias_method :hex_to_bytes, :hex_to_bin
|
22
|
-
alias_method :h_to_b, :hex_to_bin
|
22
|
+
## alias_method :hex_to_bytes, :hex_to_bin
|
23
|
+
## alias_method :h_to_b, :hex_to_bin
|
23
24
|
alias_method :htob, :hex_to_bin
|
24
25
|
|
25
26
|
|
@@ -32,8 +33,8 @@ module BytesHelper
|
|
32
33
|
hex.encode!( Encoding::UTF_8 )
|
33
34
|
hex
|
34
35
|
end
|
35
|
-
alias_method :bytes_to_hex, :bin_to_hex
|
36
|
-
alias_method :b_to_h, :bin_to_hex
|
36
|
+
## alias_method :bytes_to_hex, :bin_to_hex
|
37
|
+
## alias_method :b_to_h, :bin_to_hex
|
37
38
|
alias_method :btoh, :bin_to_hex
|
38
39
|
|
39
40
|
|
@@ -81,8 +82,8 @@ class Bytes
|
|
81
82
|
:size, :length
|
82
83
|
|
83
84
|
|
84
|
-
def
|
85
|
-
alias_method :
|
85
|
+
def to_hex() Bytes.bin_to_hex( @bin ); end
|
86
|
+
alias_method :to_s, :to_hex
|
86
87
|
|
87
88
|
def b() @bin; end
|
88
89
|
|
@@ -119,12 +120,15 @@ end
|
|
119
120
|
|
120
121
|
|
121
122
|
class String
|
122
|
-
def
|
123
|
-
|
124
|
-
|
123
|
+
def bin_to_hex() Bytes.bin_to_hex( self ); end
|
124
|
+
alias_method :btoh, :bin_to_hex
|
125
|
+
alias_method :to_hex, :bin_to_hex
|
125
126
|
## note: built-in String#hex returns string converted
|
126
|
-
## to Integer -same as String.to_i(16) !!!!
|
127
|
-
|
127
|
+
## to Integer - same as String.to_i(16) !!!!
|
128
|
+
|
129
|
+
def hex_to_bin() Bytes.hex_to_bin( self ); end
|
130
|
+
alias_method :htob, :hex_to_bin
|
131
|
+
end # class String
|
128
132
|
|
129
133
|
|
130
134
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bytes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -44,7 +44,8 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3.23'
|
47
|
-
description: bytes
|
47
|
+
description: bytes - bits 'n' bytes made easy/easier incl. new buffer helper / wrapper
|
48
|
+
class to help with the string byte vs character dichotomy
|
48
49
|
email: wwwmake@googlegroups.com
|
49
50
|
executables: []
|
50
51
|
extensions: []
|
@@ -83,5 +84,6 @@ requirements: []
|
|
83
84
|
rubygems_version: 3.3.7
|
84
85
|
signing_key:
|
85
86
|
specification_version: 4
|
86
|
-
summary: bytes
|
87
|
+
summary: bytes - bits 'n' bytes made easy/easier incl. new buffer helper / wrapper
|
88
|
+
class to help with the string byte vs character dichotomy
|
87
89
|
test_files: []
|