lib/gogyou/primitives.rb in gogyou-0.2.2 vs lib/gogyou/primitives.rb in gogyou-0.2.3
- old
+ new
@@ -20,30 +20,27 @@
def extensible?
false
end
def to_s
- "#{self.class}[name=#{name.inspect}, bytesize=#{bytesize.inspect}, bytealign=#{bytealign.inspect}]"
+ "\#<#{self.class}:#{name} bytesize=#{bytesize.inspect}, bytealign=#{bytealign.inspect}>"
end
alias inspect to_s
def pretty_print(q)
#name, bytesize, bytealign
- q.group(1, "#{self.class}[") do
- q.text "name="
- q.pp name
- q.text ", "
- #q.breakable
+ q.group(1, "\#<#{self.class}:#{name}") do
+ q.breakable " "
q.text "bytesize="
q.pp bytesize
- q.text ", "
- #q.breakable
+ q.text ","
+ q.breakable " "
q.text "bytealign="
q.pp bytealign
end
- q.text "]"
+ q.text ">"
end
end
SIZE_T = Primitive[:size_t, TypeSpec::SIZEOF_SIZE_T, TypeSpec::SIZEOF_SIZE_T,
->(buf, offset, num) { buf.store_sizet(offset, num) },
@@ -67,28 +64,16 @@
->(buf, offset, num) { buf.store16(offset, num) },
->(buf, offset) { buf.loadi16(offset) }].freeze
UINT16_T = Primitive[:uint16_t, 2, 2,
->(buf, offset, num) { buf.store16(offset, num) },
->(buf, offset) { buf.loadu16(offset) }].freeze
- INT24_T = Primitive[:int24_t, 3, 1,
- ->(buf, offset, num) { buf.store24(offset, num) },
- ->(buf, offset) { buf.loadi24(offset) }].freeze
- UINT24_T = Primitive[:uint24_t, 3, 1,
- ->(buf, offset, num) { buf.store24(offset, num) },
- ->(buf, offset) { buf.loadu24(offset) }].freeze
INT32_T = Primitive[:int32_t, 4, 4,
->(buf, offset, num) { buf.store32(offset, num) },
->(buf, offset) { buf.loadi32(offset) }].freeze
UINT32_T = Primitive[:uint32_t, 4, 4,
->(buf, offset, num) { buf.store32(offset, num) },
->(buf, offset) { buf.loadu32(offset) }].freeze
- INT48_T = Primitive[:int48_t, 6, 2,
- ->(buf, offset, num) { buf.store48(offset, num) },
- ->(buf, offset) { buf.loadi48(offset) }].freeze
- UINT48_T = Primitive[:uint48_t, 6, 2,
- ->(buf, offset, num) { buf.store48(offset, num) },
- ->(buf, offset) { buf.loadu48(offset) }].freeze
INT64_T = Primitive[:int64_t, 8, 8,
->(buf, offset, num) { buf.store64(offset, num) },
->(buf, offset) { buf.loadi64(offset) }].freeze
UINT64_T = Primitive[:uint64_t, 8, 8,
->(buf, offset, num) { buf.store64(offset, num) },
@@ -157,28 +142,16 @@
->(buf, offset, num) { buf.store16swap(offset, num) },
->(buf, offset) { buf.loadi16swap(offset) }].freeze
UINT16_SWAP = Primitive[:uint16_swap, 2, 2,
->(buf, offset, num) { buf.store16swap(offset, num) },
->(buf, offset) { buf.loadu16swap(offset) }].freeze
- INT24_SWAP = Primitive[:int24_swap, 3, 1,
- ->(buf, offset, num) { buf.store24swap(offset, num) },
- ->(buf, offset) { buf.loadi24swap(offset) }].freeze
- UINT24_SWAP = Primitive[:uint24_swap, 3, 1,
- ->(buf, offset, num) { buf.store24swap(offset, num) },
- ->(buf, offset) { buf.loadu24swap(offset) }].freeze
INT32_SWAP = Primitive[:int32_swap, 4, 4,
->(buf, offset, num) { buf.store32swap(offset, num) },
->(buf, offset) { buf.loadi32swap(offset) }].freeze
UINT32_SWAP = Primitive[:uint32_swap, 4, 4,
->(buf, offset, num) { buf.store32swap(offset, num) },
->(buf, offset) { buf.loadu32swap(offset) }].freeze
- INT48_SWAP = Primitive[:int48_swap, 6, 2,
- ->(buf, offset, num) { buf.store48swap(offset, num) },
- ->(buf, offset) { buf.loadi48swap(offset) }].freeze
- UINT48_SWAP = Primitive[:uint48_swap, 6, 2,
- ->(buf, offset, num) { buf.store48swap(offset, num) },
- ->(buf, offset) { buf.loadu48swap(offset) }].freeze
INT64_SWAP = Primitive[:int64_swap, 8, 8,
->(buf, offset, num) { buf.store64swap(offset, num) },
->(buf, offset) { buf.loadi64swap(offset) }].freeze
UINT64_SWAP = Primitive[:uint64_swap, 8, 8,
->(buf, offset, num) { buf.store64swap(offset, num) },
@@ -235,83 +208,7 @@
->(buf, offset, num) { buf.storef32swap(offset, num) },
->(buf, offset) { buf.loadf32swap(offset) }].freeze
DOUBLE_SWAP = Primitive[:double_swap, 8, 8,
->(buf, offset, num) { buf.storef64swap(offset, num) },
->(buf, offset) { buf.loadf64swap(offset) }].freeze
- end
-
- class Model
- TYPEMAP = {
- size_t: Primitives::SIZE_T,
- ssize_t: Primitives::SSIZE_T,
- intptr_t: Primitives::INTPTR_T,
- uintptr_t: Primitives::UINTPTR_T,
- int8_t: Primitives::INT8_T,
- uint8_t: Primitives::UINT8_T,
- int16_t: Primitives::INT16_T,
- uint16_t: Primitives::UINT16_T,
- int24_t: Primitives::INT24_T,
- uint24_t: Primitives::UINT24_T,
- int32_t: Primitives::INT32_T,
- uint32_t: Primitives::UINT32_T,
- int48_t: Primitives::INT48_T,
- uint48_t: Primitives::UINT48_T,
- int64_t: Primitives::INT64_T,
- uint64_t: Primitives::UINT64_T,
- int16_be: Primitives::INT16_BE,
- uint16_be: Primitives::UINT16_BE,
- int24_be: Primitives::INT24_BE,
- uint24_be: Primitives::UINT24_BE,
- int32_be: Primitives::INT32_BE,
- uint32_be: Primitives::UINT32_BE,
- int48_be: Primitives::INT48_BE,
- uint48_be: Primitives::UINT48_BE,
- int64_be: Primitives::INT64_BE,
- uint64_be: Primitives::UINT64_BE,
- int16_le: Primitives::INT16_LE,
- uint16_le: Primitives::UINT16_LE,
- int24_le: Primitives::INT24_LE,
- uint24_le: Primitives::UINT24_LE,
- int32_le: Primitives::INT32_LE,
- uint32_le: Primitives::UINT32_LE,
- int48_le: Primitives::INT48_LE,
- uint48_le: Primitives::UINT48_LE,
- int64_le: Primitives::INT64_LE,
- uint64_le: Primitives::UINT64_LE,
- int16_swap: Primitives::INT16_SWAP,
- uint16_swap: Primitives::UINT16_SWAP,
- int24_swap: Primitives::INT24_SWAP,
- uint24_swap: Primitives::UINT24_SWAP,
- int32_swap: Primitives::INT32_SWAP,
- uint32_swap: Primitives::UINT32_SWAP,
- int48_swap: Primitives::INT48_SWAP,
- uint48_swap: Primitives::UINT48_SWAP,
- int64_swap: Primitives::INT64_SWAP,
- uint64_swap: Primitives::UINT64_SWAP,
- char: Primitives::CHAR,
- uchar: Primitives::UCHAR,
- short: Primitives::SHORT,
- ushort: Primitives::USHORT,
- int: Primitives::INT,
- uint: Primitives::UINT,
- long: Primitives::LONG,
- ulong: Primitives::ULONG,
- longlong: Primitives::LONGLONG,
- ulonglong: Primitives::ULONGLONG,
- float: Primitives::FLOAT,
- double: Primitives::DOUBLE,
- float_be: Primitives::FLOAT_BE,
- double_be: Primitives::DOUBLE_BE,
- float_le: Primitives::FLOAT_LE,
- double_le: Primitives::DOUBLE_LE,
- float_swap: Primitives::FLOAT_SWAP,
- double_swap: Primitives::DOUBLE_SWAP,
- }
-
- TYPEMAP[:unsigned_char] = TYPEMAP[:uchar]
- TYPEMAP[:unsigned_short] = TYPEMAP[:ushort]
- TYPEMAP[:unsigned_int] = TYPEMAP[:uint]
- TYPEMAP[:unsigned_long] = TYPEMAP[:ulong]
- TYPEMAP[:unsigned_long_long] = TYPEMAP[:ulonglong]
- TYPEMAP[:long_long] = TYPEMAP[:longlong]
end
end