Proposal for a new API to get type and size info without unpack #119
Comments
|
Just FYI, I'm implementing similar feature (but C layer) https://github.com/nurse/msgpack-ruby/blob/94af4e565a1a849740acd11ba7623df2faa0f84c/ext/msgpack/unpacker.c#L918 |
|
I found that what I really want is a method to know how many msgpack objects exist in a binary. Hmm. |
|
@nurse I updated the description above. Is it still similar to yours? |
|
Your proposal needs a cursor (or an API to really skip objects without allocating objects). Mime contains such implementation as a cursor, but yours seems to want to move the unpacker's position. |
|
Doesn't
|
|
Returning a class instance (immutable struct) is better than Hash in terms of performance. class Unpacker
#
# Returns type of next value.
# This peeks 1 byte from the underlaying internal buffer.
#
# :nil, :string. :integer, :float, :array, :map, ...
#
# @return Symbol
def peek_next_type
end
#
# Returns ValueInfo of next value.
# This peeks 1 - 5 bytes from the underlaying internal buffer.
#
# @return ValueInfo or its subclass
def peek_next_value_info
end
end
class ValueInfo
# Returns type of the value (:string, :binary, :integer, ...)
def type
end
# Returns of size of string, binary, or extention value
def size
end
alias_method :length, :size
# Returns type id of extension value
def ext_type_id
end
# Returns true if type is :string or :binary
def raw?
end
# Returns true if type is :integer or :float
def number?
end
endThese are optional (My bet is that NOT adding them until some actually need them):
This is how msgpack-java designs data model around types: |
|
I think it's NOT good idea to add Adding such method as like msgpack-java does is another idea but it will need |
MessagePack (serialized) binary has type info and size of (str/bin, array, map) at the header of whole binary.
When we want to know these, it's only way to unpack whole data. But it requires much computing power.
I propose a new API call to return an array of Hash object which contains:
A hash represents info of a msgpack object. The method scans all binary to build an array of it.
How do you think about this idea? @frsyuki
The text was updated successfully, but these errors were encountered: