Code Monkey home page Code Monkey logo

Comments (5)

jangko avatar jangko commented on June 6, 2024

fixed, now you can use something like this:

import msgpack4nim, strutils

type
  Guid {.skipUndistinct.} = distinct string

proc pack_type*[ByteStream](s: ByteStream, v: Guid) =
  s.pack_bin(len(v.string))
  s.write(v.string)

var b = Guid("AA")
var s = b.pack
echo s.tohex
echo s.stringify

automatic check for matching procs is not possible right now, Nim compiler still has issue in that particular area.

from msgpack4nim.

zevv avatar zevv commented on June 6, 2024

from msgpack4nim.

zevv avatar zevv commented on June 6, 2024

What about this?

proc pack*[ByteStream, T](s: ByteStream, val: T) =
  when compiles(s.pack_type(val)):
    s.pack_type (val)
  else:
    s.pack_type undistinct(val)

This works for me, without any need for special pragmas.

from msgpack4nim.

jangko avatar jangko commented on June 6, 2024

I already tried that, it only works for simple types.
For some unknown reason, when encountered object variant with self reference, the compiler protest with scary error. that's why I choose to use pragma.
you can try it with tests/test_codec.nim

from msgpack4nim.

zevv avatar zevv commented on June 6, 2024

Fair enough, thanks!

from msgpack4nim.

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.