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

feat: support optional fields in proto v3 #33

Merged
merged 1 commit into from
Jan 26, 2023
Merged

Conversation

kei2100
Copy link
Owner

@kei2100 kei2100 commented Jan 26, 2023

refs #32

Add support optional fields in proto v3

e.g.

// test/foo.pb

message FooMessage {
  optional string string_val = 1;
}
$ protoc -I. -Itest/ --marshal-zap_out=test/ --go_out=test/ test/foo.proto                                                                                                                  

before

protoc failed
got the following error message

test/foo.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-marshal-zap hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.--marshal-zap_out: 

after

protoc succeeded

// foo.pb.marshal-zap.go

func (x *FooMessage) MarshalLogObject(enc zapcore.ObjectEncoder) error {

	if x.StringVal != nil {
		enc.AddString("string_val", x.GetStringVal())
	}

	return nil
}

@kei2100 kei2100 merged commit 9b2abba into master Jan 26, 2023
@kei2100 kei2100 deleted the support-optional branch January 26, 2023 12:05
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.

1 participant