Skip to content

feat: add full_name callback to proto messages #409

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yordis
Copy link
Contributor

@yordis yordis commented Apr 24, 2025

closes #408

@yordis
Copy link
Contributor Author

yordis commented May 5, 2025

It seems that full_name could be deterministic at compile time

syntax = "proto3";
package demo.v1;

import "google/protobuf/any.proto";

message Example {
  message NestedFirstLevel {
    message NestedSecondLevel {}

    NestedSecondLevel nested_second = 1;
  }

  enum NestedTypes {
    TYPE_UNSPECIFIED = 0;
    TYPE_ONE = 1;
    TYPE_TWO = 2;
  }

  NestedFirstLevel nested_first = 1;
  NestedTypes type = 2;
}

enum TopLevelEnum {
  TOP_LEVEL_UNSPECIFIED = 0;
  TOP_LEVEL_ONE = 1;
  TOP_LEVEL_TWO = 2;
}

message Integration {
  google.protobuf.Any data = 1;
}
package demo__test

import (
	"fmt"
	"github.com/stretchr/testify/assert"
	"google.golang.org/protobuf/reflect/protoreflect"
	"testing"
	demov1 "demo/gen/pb/demo/v1"
)

func TestName(t *testing.T) {
	nestedFirstNestedSecond := &demov1.Example_NestedFirstLevel_NestedSecondLevel{}
	nestedFirst := &demov1.Example_NestedFirstLevel{NestedSecond: nestedFirstNestedSecond}
	example := demov1.Example{NestedFirst: nestedFirst}

	exampleName := fullName(&example)
	fmt.Printf("%v", exampleName)

	nestedFirstName := fullName(example.GetNestedFirst())
	nestedFirstNameTop := fullName(nestedFirst)
	fmt.Printf("%v  --- %v", nestedFirstName, nestedFirstNameTop)
	assert.Equal(t, nestedFirstName, nestedFirstNameTop)

	nestedFirstNestedSecondName := fullName(example.GetNestedFirst().GetNestedSecond())
	nestedFirstNestedSecondNameTop := fullName(nestedFirstNestedSecond)
	fmt.Printf("%v --- %v", nestedFirstNestedSecondName, nestedFirstNestedSecondNameTop)
	assert.Equal(t, nestedFirstNestedSecondName, nestedFirstNestedSecondNameTop)
}

func fullName(msg protoreflect.ProtoMessage) protoreflect.FullName {
	return msg.ProtoReflect().Descriptor().FullName()
}

@yordis
Copy link
Contributor Author

yordis commented May 5, 2025

It seems that Golang does not allow me pass enum values to anypkg, so I think that such full_name isn't in there for the enum values since it always exists inside a message as a type

Screenshot 2025-05-05 at 5 12 40 PM

@yordis yordis force-pushed the fixes-408 branch 6 times, most recently from c828171 to 9c3504b Compare May 5, 2025 21:58
@yordis
Copy link
Contributor Author

yordis commented May 5, 2025

@yordis yordis requested a review from v0idpwn May 31, 2025 02:11
@yordis yordis marked this pull request as ready for review May 31, 2025 02:11
@yordis
Copy link
Contributor Author

yordis commented May 31, 2025

@whatyouhide @v0idpwn I think it is ready to code review, at least adding the fallback to follow up on Any type

@yordis yordis force-pushed the fixes-408 branch 2 times, most recently from 5acfd35 to ffe23ba Compare May 31, 2025 02:13
@yordis
Copy link
Contributor Author

yordis commented May 31, 2025

As far as I can tell package is technically required, a lot of test cases where such information is missing, I wonder if that should be fixed

@yordis
Copy link
Contributor Author

yordis commented Jun 2, 2025

** (RuntimeError) reading from :stdio failed: {:error, {:no_translation, :unicode, :latin1}}

What in the world is that 🤔

@whatyouhide
Copy link
Collaborator

Mh yeah, I have very vague memories of this but no notes on it, sorry 😭 I don't really have cycles to look into this now :(

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

Successfully merging this pull request may close these issues.

[Feature] Add full_name/0 to message module
3 participants