Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Msgsize and msgp:size ignore directive #140

Open
pierrec opened this issue Dec 1, 2015 · 0 comments
Open

Msgsize and msgp:size ignore directive #140

pierrec opened this issue Dec 1, 2015 · 0 comments

Comments

@pierrec
Copy link

pierrec commented Dec 1, 2015

Hello,

When the "msg:size ignore Type" directive is used the tests still contain a reference to the Msgsize method, which does not exist.

For instance:

//msgp:size ignore Type
package main

type Type struct {
  A int
}

func main() {
  t := &Type{}
  _ = t
}

generates the following test file:

package main

// NOTE: THIS FILE WAS PRODUCED BY THE
// MSGP CODE GENERATION TOOL (github.com/tinylib/msgp)
// DO NOT EDIT

import (
    "bytes"
    "testing"

    "github.com/tinylib/msgp/msgp"
)

func TestEncodeDecodeType(t *testing.T) {
    v := Type{}
    var buf bytes.Buffer
    msgp.Encode(&buf, &v)

    m := v.Msgsize()
    if buf.Len() > m {
        t.Logf("WARNING: Msgsize() for %v is inaccurate", v)
    }

    vn := Type{}
    err := msgp.Decode(&buf, &vn)
    if err != nil {
        t.Error(err)
    }

    buf.Reset()
    msgp.Encode(&buf, &v)
    err = msgp.NewReader(&buf).Skip()
    if err != nil {
        t.Error(err)
    }
}

func BenchmarkEncodeType(b *testing.B) {
    v := Type{}
    var buf bytes.Buffer
    msgp.Encode(&buf, &v)
    b.SetBytes(int64(buf.Len()))
    en := msgp.NewWriter(msgp.Nowhere)
    b.ReportAllocs()
    b.ResetTimer()
    for i := 0; i < b.N; i++ {
        v.EncodeMsg(en)
    }
    en.Flush()
}

func BenchmarkDecodeType(b *testing.B) {
    v := Type{}
    var buf bytes.Buffer
    msgp.Encode(&buf, &v)
    b.SetBytes(int64(buf.Len()))
    rd := msgp.NewEndlessReader(buf.Bytes(), b)
    dc := msgp.NewReader(rd)
    b.ReportAllocs()
    b.ResetTimer()
    for i := 0; i < b.N; i++ {
        err := v.DecodeMsg(dc)
        if err != nil {
            b.Fatal(err)
        }
    }
}

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant