ExtensionType API incomplete

Open
#49 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
32/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
julia

Research direction

Start with the MsgPack.ExtensionType documentation and the existing test suite, then trace the msgpack_type, to_msgpack, and from_msgpack entry points used in the example. Reproduce the failing unpack test with the provided extension bytes and determine what API behavior is needed for them to produce a Dates.Date rather than MsgPack.Extension.

Written by the indexing model from the issue text.

Description

Is the API for supporting MsgPack extensions complete?

(So as not to waste anyone's time, note that this is an adaptation of a question on Discourse.)

I am trying to write the Julia end of an RPC-over-RabbitMQ relationship. The other side (written in Ruby) uses a MsgPack extension for dates. I receive this:

MsgPack.Extension(1, UInt8[0x07, 0xe6, 0x02, 0x1c])

I can make my end send this with pack, but I can’t make my end convert this to a Date with unpack. This is what I have so far, based on the documentation for MsgPack.ExtensionType:

module test_msg_pack_ext

using Dates
using MsgPack
using Test

function pack_date(date::Date)::MsgPack.Extension
        year_u16 = convert(UInt16, year(date))
        year_hi = UInt8(year_u16 >> 8)
        year_lo = UInt8(year_u16 << 8 >> 8)
        return MsgPack.Extension(0x01, UInt8[year_hi, year_lo, month(date), day(date)])
end

function unpack_date(ext::MsgPack.Extension)::Date
        year = ext.data[1] << 8 | ext.data[2]
        return Date(year, ext.data[3], ext.data[4])
end

MsgPack.msgpack_type(::Type{Dates.Date}) = MsgPack.ExtensionType()
MsgPack.to_msgpack(::MsgPack.ExtensionType, date::Dates.Date) = pack_date(date)
MsgPack.from_msgpack(::Type{Dates.Date}, ext::MsgPack.Extension) = unpack_date(ext)

@test pack(MsgPack.Extension(1, UInt8[0x07, 0xe6, 0x02, 0x1c])) == pack(Date(2022, 2, 28))
@test Date(2022, 2, 28) == unpack(UInt8[0xd6, 0x01, 0x07, 0xe6, 0x02, 0x1c])
    
end

# =>
engine/msg_pack_ext.jl: Test Failed at .../msg_pack_ext.jl:25
  Expression: Date(2022, 2, 28) == unpack(UInt8[0xd6, 0x01, 0x07, 0xe6, 0x02, 0x1c])
   Evaluated: Dates.Date("2022-02-28") == MsgPack.Extension(1, UInt8[0x07, 0xe6, 0x02, 0x1c])

That makes sense to me. I haven’t done anything to map extension type 1 to my code. But I can't see anything in the MsgPack code or test suite that lets me do this. The discussion in #7 makes it look like the contributor was satisfied with receiving a MsgPack.Extension and handling it themselves?

Dominant language
Julia
Stars
68
Forks
20
Avg merge
13d 12h
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaIO/MsgPack.jl

All issues in JuliaIO/MsgPack.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.