nmspec 1.5.1.pre → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90d3113e482e5bdc15f3a5043de7db0acacb0ee669600214b7dd4f450fad5b69
4
- data.tar.gz: 63824be872579cff6a615eb68898a9799c1d7849b0b624f46a968c199d671a15
3
+ metadata.gz: 128d25a1fb4afa4687bfe7e3808fac4f0be06587be012781272cc94f13d61743
4
+ data.tar.gz: '0086e7f406eed250a55bea6c58829b09800aafd8b3d2c1a144e773156c06de03'
5
5
  SHA512:
6
- metadata.gz: 1d6643f500fa0e5a057d1b3cc2cc0b2d601fcbed9ad3a0efbc1f2e6c85335b23d54894857778a9e2bcbcf80b4493d14ac05e5678c9bb5e9b6504920acf3b2547
7
- data.tar.gz: 7c9a03a9d47d1625fbc34341086c50f5ac0f4c15a8228c69101b569b49e8daeda8af2ae27187c9611c2b726c7355bcebed7fcb1da50d21d8ccea9281d74b2052
6
+ metadata.gz: 62752a73c1dea7cc4766ea0c46f747574aec876ab176190699ef9f2ab551b43129a615ae0d9211fd34a5f0a721047df305567a8003154a4a1166728db8fb39bd
7
+ data.tar.gz: 004d417ad7440f191fcc99d480a891e419380ad21ef21aa3b19e442d2187a04bb2f3ea08fbd7139890319d8b484cb0aa0a3d24bd30aafde7dffa961a03d6d796
data/README.md CHANGED
@@ -12,6 +12,12 @@ described in `nmspec` are used to create both the reading and writing sides
12
12
  of the connection, so that a single source code file contains everything you
13
13
  need for a network peer, regardless of if it's the client or server.
14
14
 
15
+ ## Demo video explaining how to use this gem
16
+
17
+ <a href="https://youtu.be/Ib6c6BEl82c">
18
+ <img src="https://s3.us-east-2.amazonaws.com/vim4evar.com/nmspec-imgs/link-to-demo-video.png" />
19
+ </a>
20
+
15
21
  ## Motivation
16
22
 
17
23
  `nmspec` was specifically created to help with with a problem I was facing,
@@ -48,8 +54,8 @@ As a starting point this gem supports network messengers in these two languages:
48
54
  * [Ruby 3.0.x][ruby-lang]
49
55
  * [GDScript 3.4.stable][gdscript]
50
56
 
51
- `nmspec` came out of a online game project where the backend was written in
52
- Ruby, and the frontend build with the Godot game engine, which includes the
57
+ `nmspec` came out of a online game project where the backend is written in
58
+ Ruby, and the frontend is built with the Godot game engine, which includes the
53
59
  embedded scripting language, GDSCript.
54
60
 
55
61
  # Sample usage
@@ -283,7 +289,7 @@ description languages/tools in the past, beginning with [Prolac][prolac]. This
283
289
  lead me to other network messaging tools, binary serialization in general,
284
290
  finally [Google's protocol buffers][protobuffs]. Protocol buffers were probably
285
291
  the closest thing to what I wanted, and took care of binary
286
- serialization/deserialization, but weren't packaaged with the networking layer,
292
+ serialization/deserialization, but weren't packaged with the networking layer,
287
293
  which introduces additional considerations such as byte ordering, efficient
288
294
  packet construction, TCP stack options, and communication retries and graceful
289
295
  failover. While protocol buffers are a good design, and I think do a good job of
@@ -14,7 +14,7 @@ module Nmspec
14
14
 
15
15
  if spec.dig(:msgr, :desc)
16
16
  code << '#'
17
- code << "# #{spec.dig(:msgr, :desc)}"
17
+ spec.dig(:msgr, :desc).lines.each{|l| code << "# #{l.strip}" }
18
18
  end
19
19
 
20
20
  code << 'extends Reference'
@@ -52,8 +52,6 @@ module Nmspec
52
52
 
53
53
  subtypes = spec[:types].select{|t| !t[:base_type].nil? }
54
54
  code << _protos_methods(spec[:protos], subtypes)
55
-
56
- code.join("\n")
57
55
  rescue => e
58
56
  "Code generation failed due to unknown error: check spec validity\n cause: #{e.inspect}"
59
57
  puts e.backtrace.join("\n ")
@@ -288,6 +286,7 @@ module Nmspec
288
286
  ##
289
287
  # send
290
288
  code << _proto_method('send', proto_code, proto, send_local_vars, send_passed_params, subtypes)
289
+ code << "\n"
291
290
  code << _proto_method('recv', proto_code, proto, recv_local_vars, recv_passed_params, subtypes)
292
291
  end
293
292
 
@@ -323,7 +322,7 @@ module Nmspec
323
322
  def _proto_method(kind, proto_code, proto, local_vars, passed_params, subtypes)
324
323
  code = []
325
324
 
326
- code << "# #{proto[:desc]}" if proto[:desc]
325
+ proto[:desc].lines.each{|l| code << "# #{l.strip}" } if proto[:desc]
327
326
  unless local_vars.empty?
328
327
  code << '#'
329
328
  code << '# returns: (type | local var name)'
data/lib/nmspec/ruby.rb CHANGED
@@ -14,8 +14,8 @@ module Nmspec
14
14
  code << '# NOTE: this code is auto-generated from an nmspec file'
15
15
 
16
16
  if spec.dig(:msgr, :desc)
17
- code << '#'
18
- code << "# #{spec.dig(:msgr, :desc)}"
17
+ code << '##'
18
+ spec.dig(:msgr, :desc).lines.each{|l| code << "# #{l.strip}" }
19
19
  end
20
20
 
21
21
  code << "class #{_class_name_from_msgr_name(spec.dig(:msgr, :name))}"
@@ -27,6 +27,8 @@ module Nmspec
27
27
 
28
28
  code << _initialize
29
29
  code << ''
30
+ code << _open?
31
+ code << ''
30
32
  code << _close
31
33
  code << ''
32
34
  code << _bool_type
@@ -77,18 +79,32 @@ module Nmspec
77
79
 
78
80
  code << ' def initialize(socket, no_delay=false)'
79
81
  code << ' @socket = socket'
82
+ code << ' @open = true'
80
83
  code << ' @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if no_delay'
81
84
  code << ' end'
82
85
 
83
86
  code
84
87
  end
85
88
 
89
+ def _open?
90
+ code = []
91
+
92
+ code << ' ##'
93
+ code << ' # closes the socket inside this object'
94
+ code << ' def open?'
95
+ code << ' !!(@socket && @open)'
96
+ code << ' end'
97
+
98
+ code
99
+ end
100
+
86
101
  def _close
87
102
  code = []
88
103
 
89
104
  code << ' ##'
90
105
  code << ' # closes the socket inside this object'
91
106
  code << ' def close'
107
+ code << ' @open = false'
92
108
  code << ' @socket&.close'
93
109
  code << ' end'
94
110
 
@@ -356,7 +372,8 @@ module Nmspec
356
372
  def _proto_method(kind, proto_code, proto, local_vars, passed_params)
357
373
  code = []
358
374
 
359
- code << " # #{proto[:desc]}" if proto[:desc]
375
+ proto[:desc].lines.each{|l| code << " # #{l.strip}" } if proto[:desc]
376
+
360
377
  unless local_vars.empty?
361
378
  code << ' #'
362
379
  code << ' # returns: (type | local var name)'
@@ -1 +1 @@
1
- NMSPEC_GEM_VERSION = '1.5.1.pre'
1
+ NMSPEC_GEM_VERSION = '1.6.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nmspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1.pre
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-30 00:00:00.000000000 Z
11
+ date: 2022-06-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: nmspec makes it easier to describe binary messages between two network
14
14
  peers via a config file, generate their network code in a number of languages, and
@@ -43,9 +43,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
43
  version: '0'
44
44
  required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 1.3.1
48
+ version: '0'
49
49
  requirements: []
50
50
  rubygems_version: 3.2.32
51
51
  signing_key: