-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use SWIG, the project is easy enough. Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Showing
9 changed files
with
99 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "ruby.h" | ||
|
||
#include "smile.h" | ||
|
||
static VALUE rb_mSmile; | ||
static VALUE rb_cParser; | ||
|
||
static VALUE libsmile_init() | ||
{ | ||
smile_decode_block_init(); | ||
return Qnil; | ||
} | ||
|
||
#define BUFFER_SIZE 65536 | ||
|
||
static VALUE libsmile_decode(VALUE self, VALUE input) | ||
{ | ||
char result[BUFFER_SIZE] = {'\0'}; | ||
|
||
Check_Type(input, T_STRING); | ||
|
||
// Reset for successive calls | ||
smile_decode_block_reset(); | ||
|
||
smile_decode_block(result, BUFFER_SIZE, RSTRING_PTR(input), RSTRING_LEN(input)); | ||
|
||
return rb_str_new2(result); | ||
} | ||
|
||
void Init_libsmile() | ||
{ | ||
rb_mSmile = rb_define_module("Smile"); | ||
rb_cParser = rb_define_class_under(rb_mSmile, "Parser", rb_cObject); | ||
|
||
rb_define_method(rb_cParser, "initialize", libsmile_init, 0); | ||
rb_define_method(rb_cParser, "decode", libsmile_decode, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,33 @@ | ||
require '../ruby/build/libsmile' | ||
require_relative '../ruby/libsmile' | ||
|
||
smile_file = '../data/smile/test1.smile' | ||
@parser = Smile::Parser.new() | ||
|
||
smile = open(smile_file, "rb") { |io| io.read } | ||
def read_file(path) | ||
return open(path, "rb") { |io| io.read } | ||
end | ||
|
||
puts Libsmile.smile_decode_block_init | ||
puts Libsmile.smile_decode_block_exit | ||
def test_one_file(json_filename, smile_filename) | ||
puts "*** Ruby *** Testing #{smile_filename}\n"; | ||
|
||
data_dir = "#{File.dirname(__FILE__)}/../data" | ||
|
||
smile_file = "#{data_dir}/smile/#{smile_filename}" | ||
smile = read_file(smile_file) | ||
actual = @parser.decode(smile) | ||
|
||
json_file = "#{data_dir}/json/#{json_filename}" | ||
expected = read_file(json_file) | ||
|
||
unless expected.eql? actual | ||
puts("Expected: #{expected}"); | ||
puts("Actual: #{actual}"); | ||
exit(1); | ||
end | ||
end | ||
|
||
files = ['json-org-sample1', 'json-org-sample2', 'json-org-sample3', 'json-org-sample4', 'json-org-sample5', | ||
'numbers-int-4k', 'numbers-int-64k', 'test1', 'test2']; | ||
|
||
files.each do |file| | ||
test_one_file "#{file}.jsn", "#{file}.smile" | ||
end |