gogyou 0.1.240911.prototype → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,160 @@
1
+ #vim: set fileencoding:utf-8
2
+
3
+ require "gogyou"
4
+
5
+ describe Gogyou do
6
+ it "basic struct-1" do
7
+ x = Gogyou.struct {
8
+ uint32_t :a
9
+ }
10
+
11
+ expect(x.ancestors).to include Gogyou::Accessor::Struct
12
+ expect(x::BYTESIZE).to eq 4
13
+ expect(x::BYTEALIGN).to eq 4
14
+ end
15
+
16
+ it "basic struct-2" do
17
+ x = Gogyou.struct {
18
+ uint32_t :a, :b
19
+ }
20
+
21
+ expect(x.ancestors).to include Gogyou::Accessor::Struct
22
+ expect(x::BYTESIZE).to eq 8
23
+ expect(x::BYTEALIGN).to eq 4
24
+ end
25
+ end
26
+
27
+ describe Gogyou::Model do
28
+ it "struct in union" do
29
+ x = Gogyou.union {
30
+ struct {
31
+ int32_t :a
32
+ }
33
+ uint32_t :b
34
+ }
35
+
36
+ reference = Gogyou::Model::Union[
37
+ 4, 4,
38
+ Gogyou::Model::Field[0, :a, nil, Gogyou::Primitives::INT32_T, 0x00],
39
+ Gogyou::Model::Field[0, :b, nil, Gogyou::Primitives::UINT32_T, 0x00]
40
+ ]
41
+
42
+ expect(x::MODEL).to eq reference
43
+ end
44
+
45
+ it "nested struct with anonymous fields" do
46
+ x = Gogyou.struct {
47
+ char :a
48
+ union {
49
+ int :b
50
+ struct {
51
+ int64_t :c
52
+ int32_t :d
53
+ }
54
+ }
55
+ char :e
56
+ }
57
+
58
+ ref = Gogyou::Model::Struct[
59
+ 32, 8,
60
+ Gogyou::Model::Field[0, :a, nil, Gogyou::Primitives::CHAR, 0],
61
+ Gogyou::Model::Field[8, :b, nil, Gogyou::Primitives::INT, 0],
62
+ Gogyou::Model::Field[8, :c, nil, Gogyou::Primitives::INT64_T, 0],
63
+ Gogyou::Model::Field[16, :d, nil, Gogyou::Primitives::INT32_T, 0],
64
+ Gogyou::Model::Field[24, :e, nil, Gogyou::Primitives::CHAR, 0]
65
+ ]
66
+
67
+ expect(x::MODEL).to eq ref
68
+ end
69
+
70
+ it "nested struct with array" do
71
+ x = Gogyou.struct {
72
+ char :a
73
+ union {
74
+ int :b
75
+ struct -> {
76
+ int64_t :c
77
+ int32_t :d
78
+ }, :e, 4
79
+ }
80
+ }
81
+
82
+ ref = Gogyou::Model::Struct[
83
+ 72, 8,
84
+ Gogyou::Model::Field[0, :a, nil, Gogyou::Primitives::CHAR, 0x00],
85
+ Gogyou::Model::Field[8, :b, nil, Gogyou::Primitives::INT, 0x00],
86
+ Gogyou::Model::Field[8, :e, [4], Gogyou::Model::Struct[
87
+ 16, 8,
88
+ Gogyou::Model::Field[0, :c, nil, Gogyou::Primitives::INT64_T, 0x00],
89
+ Gogyou::Model::Field[8, :d, nil, Gogyou::Primitives::INT32_T, 0x00]], 0x00]]
90
+ expect(x::MODEL).to eq ref
91
+ end
92
+
93
+ it "nested struct in union" do
94
+ x = Gogyou.struct {
95
+ char :a
96
+ union {
97
+ int :b
98
+ struct {
99
+ int64_t :c
100
+ int32_t :d
101
+ }
102
+ }
103
+ }
104
+
105
+ y = Gogyou.union {
106
+ struct x, :a, :b
107
+ }
108
+
109
+ ref = Gogyou::Model::Union[
110
+ 24, 8,
111
+ Gogyou::Model::Field[0, :a, nil, x, 0x00],
112
+ Gogyou::Model::Field[0, :b, nil, x, 0x00]]
113
+ expect(y::MODEL).to eq ref
114
+ end
115
+ end
116
+
117
+ describe Gogyou::Accessor do
118
+ it "fixed bytesize struct" do
119
+ type = Gogyou.struct {
120
+ int32_t :a, :b, 2, 2
121
+ }
122
+
123
+ expect(type.bytesize).to eq 20
124
+ expect(type.bytealign).to eq 4
125
+ expect(type.extensible?).to eq false
126
+
127
+ obj = type.new
128
+ expect(obj.bytesize).to eq 20
129
+ end
130
+
131
+ it "extensibity struct" do
132
+ type = Gogyou.struct {
133
+ int32_t :a, :b, 2, 2
134
+ int32_t :c, 4, 0
135
+ }
136
+
137
+ expect(type.bytesize).to eq 20
138
+ expect(type.bytealign).to eq 4
139
+ expect(type.extensible?).to eq true
140
+
141
+ obj = type.new
142
+ expect(obj.bytesize).to eq 20
143
+ end
144
+
145
+ it "extensibity struct in struct" do
146
+ type = Gogyou.struct {
147
+ struct -> {
148
+ int32_t :a, :b, 2, 2
149
+ int32_t :c, 4, 0
150
+ }, :x
151
+ }
152
+
153
+ expect(type.bytesize).to eq 20
154
+ expect(type.bytealign).to eq 4
155
+ expect(type.extensible?).to eq true
156
+
157
+ obj = type.new
158
+ expect(obj.bytesize).to eq 20
159
+ end
160
+ end
metadata CHANGED
@@ -1,69 +1,100 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gogyou
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.240911.prototype
5
- prerelease: 11
4
+ version: '0.2'
6
5
  platform: ruby
7
6
  authors:
8
7
  - dearblue
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-11 00:00:00.000000000 Z
13
- dependencies: []
14
- description: ! 'gogyou is a library for define the data struct for packing and unpacking
15
- to binary strings.
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: |
42
+ The gogyou is a library that provides auxiliary features of binary data operation for ruby.
16
43
 
17
- The C style types are usable.
44
+ The C-liked struct, union and multidimensional array definition are posible in ruby syntax.
18
45
 
19
- Also:
20
-
21
- - Define struct in struct is possible.
22
-
23
- - By using the typedef, you can define any class.
24
-
25
- - Definition of a one-dimensional array is possible.
26
-
27
- '
46
+ * Usable nested struct.
47
+ * Usable nested union.
48
+ * Usable multidimensional array.
49
+ * Usable user definition types.
28
50
  email: dearblue@users.sourceforge.jp
29
51
  executables: []
30
52
  extensions: []
31
53
  extra_rdoc_files:
32
- - README.txt
33
- - LICENSE.txt
54
+ - LICENSE.markdown
55
+ - README.markdown
34
56
  - lib/gogyou.rb
57
+ - lib/gogyou/accessor.rb
58
+ - lib/gogyou/mixin.rb
59
+ - lib/gogyou/model.rb
60
+ - lib/gogyou/typespec.rb
61
+ - lib/gogyou/primitives.rb
35
62
  files:
36
- - README.txt
37
- - LICENSE.txt
63
+ - LICENSE.markdown
64
+ - README.markdown
65
+ - Rakefile
66
+ - gemstub.rb
38
67
  - lib/gogyou.rb
68
+ - lib/gogyou/accessor.rb
69
+ - lib/gogyou/mixin.rb
70
+ - lib/gogyou/model.rb
71
+ - lib/gogyou/primitives.rb
72
+ - lib/gogyou/typespec.rb
73
+ - mkprims.rb
74
+ - spec/gogyou_spec.rb
39
75
  homepage: http://sourceforge.jp/projects/rutsubo/
40
76
  licenses:
41
77
  - 2-clause BSD License
78
+ metadata: {}
42
79
  post_install_message:
43
- rdoc_options:
44
- - -e
45
- - UTF-8
46
- - -m
47
- - README.txt
80
+ rdoc_options: []
48
81
  require_paths:
49
82
  - lib
50
83
  required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
84
  requirements:
53
- - - ! '>='
85
+ - - ">="
54
86
  - !ruby/object:Gem::Version
55
- version: 1.9.3
87
+ version: '2.0'
56
88
  required_rubygems_version: !ruby/object:Gem::Requirement
57
- none: false
58
89
  requirements:
59
- - - ! '>'
90
+ - - ">="
60
91
  - !ruby/object:Gem::Version
61
- version: 1.3.1
92
+ version: '0'
62
93
  requirements: []
63
94
  rubyforge_project:
64
- rubygems_version: 1.8.24
95
+ rubygems_version: 2.4.1
65
96
  signing_key:
66
97
  specification_version: 3
67
- summary: define the data struct for packing and unpacking to binary strings
98
+ summary: binary data operation library with the C liked struct and union
68
99
  test_files: []
69
- has_rdoc: false
100
+ has_rdoc:
data/README.txt DELETED
@@ -1,3 +0,0 @@
1
- = About gogyou
2
-
3
- ゴギョウ (御形) は、バイナリ文字列にパックまたはアンパックする構造体クラスを定義するライブラリです。