Coder Social home page Coder Social logo

Comments (9)

ugorji avatar ugorji commented on July 17, 2024

I'm struggling with this feature request, but I think it has some merit.

The c/c++ msgpack lib is somewhat complicated, but the MSGPACK_DEFINE macro may be something that may help give a hint to the library, possibly allowing it encode a struct as a map.

However, there is still merit on the Go library to decode to support decoding an encoded array in to a struct. After some thoughts and prototyping it, I'd add support for the feature and let you know when to test it.

Thanks.

from go.

ugorji avatar ugorji commented on July 17, 2024

Please test this out and let me know that it worked for you.

from go.

zx9597446 avatar zx9597446 commented on July 17, 2024

hi, I've test this feature, it works well both with encoded map and encoded array, without any change in my test code, thanks!
however, after reading souce code that you commited, I realized that I also need an option can encode a struct to encoded array, for communation with msgpack cpp lib.
I understand that the cpp lib would be better accept encoded map as struct, but cpp is complicated, so I think better provide this option in golang lib.
comment?

from go.

ugorji avatar ugorji commented on July 17, 2024

Hi,

I'm not comfortable with the idea of supporting a feature so that it works as the cpp library works. I'm more comfortable is we can defend the feature on its own merits.

Let me think about it and follow up.

from go.

ugorji avatar ugorji commented on July 17, 2024

I thought about this, and the feature has merit on its own.

It allows user to create a non-homogenous but fully typed array in code.

For example, if you expect a 4-element array of integer, bool, string and map[string]int, you can define it using a type like:

type MyRequest struct {
  _struct bool `codec:",toarray"`
  Num int
  Flag bool
  Name string
  Properties map[string]int
}

Usage model is via one of the following:

type mh codec.MsgpackHandle
mh.StructToArray = true
// ...

Or by defining it in the struct tag:

type Mystruct struct {
  _struct bool `codec:",toarray"`
  // ...
}

Please test out and let me know if this works for you.

from go.

zx9597446 avatar zx9597446 commented on July 17, 2024

great! that's all I wanted.
I'll test this feature later.

from go.

ugorji avatar ugorji commented on July 17, 2024

FYI: I've fixed the bugs I found while testing. Specifically, we have to use the same consistent logic during encoding and decoding. Please test out and let me know so I can close the issue.

Thanks.

from go.

zx9597446 avatar zx9597446 commented on July 17, 2024

I've test encode struct as array, it works fine with cpp lib.

thanks for providing these great features!

from go.

ugorji avatar ugorji commented on July 17, 2024

Made more robust with change b25a055 .

from go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.