Giter Site home page Giter Site logo

Comments (6)

vasanth-kandasamy avatar vasanth-kandasamy commented on July 19, 2024

@vmg / @jasonlong Could you please check the above issue.

from vtprotobuf.

viswajithiii avatar viswajithiii commented on July 19, 2024

Can confirm that I am seeing this as well.

from vtprotobuf.

mattrobenolt avatar mattrobenolt commented on July 19, 2024

To confirm, is this from encoding a message like, OptionalByte{Value: nil} or OptionalByte{Value: []byte{}} ?

I would suspect these encode differently since optional fields are ignored from the proto encoding when the value doesn't exist.

I can check into this later, but that's what stands out to me without any other investigation.

from vtprotobuf.

mattrobenolt avatar mattrobenolt commented on July 19, 2024

Ah, ok, so I see the difference and can confirm slightly different behavior.

package main

import (
	"vtprotobuftest/test"
	"fmt"
	"google.golang.org/protobuf/proto"
)

func main() {
	a := test.OptionalByte{
		Value: nil,
	}
	b := test.OptionalByte{
		Value: []byte{},
	}
	fmt.Println("proto.Marshal:")
	fmt.Printf("%#v\n", must(proto.Marshal(&a)))
	fmt.Printf("%#v\n", must(proto.Marshal(&b)))

	fmt.Println()
	fmt.Println("vtproto:")
	fmt.Printf("%#v\n", must((&a).MarshalVT()))
	fmt.Printf("%#v\n", must((&b).MarshalVT()))
}

func must[T any](v T, err error) T {
	if err != nil {
		panic(err)
	}
	return v
}

Is my test script, just using the proto from the OP.

Output is:

proto.Marshal:
[]byte{}
[]byte{0xa, 0x0}

vtproto:
[]byte{}
[]byte{}

So it's the empty byte array case, not a nil byte array. Lemme see if I can dig in and see where we differ.

from vtprotobuf.

mattrobenolt avatar mattrobenolt commented on July 19, 2024

So this also seems to be explicitly for when optional is used, when it's just bytes value = 1;, it does marshal to no bytes. So I'm guessing the standard encoder need to explicitly say "this is missing" vs "there are no bytes".

from vtprotobuf.

viswajithiii avatar viswajithiii commented on July 19, 2024

Yeah exactly. That's the purpose of optional.

from vtprotobuf.

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.