1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package filepb
import (
"google.golang.org/protobuf/encoding/prototext"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
// --- Mock of a generated user.pb.go file ---
type PatchError struct {
// Note: The `XXX_` fields are part of the older struct tags,
// but the reflection logic comes from the modern API.
// In a real generated file, you wouldn't see these tags.
UserName string `protobuf:"bytes,1,opt,name=user_name,json=userName,proto3" json:"user_name,omitempty"`
UserId int64 `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
LastLogin *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=last_login,json=lastLogin,proto3" json:"last_login,omitempty"`
}
func (x *PatchError) Reset() { *x = PatchError{} }
func (x *PatchError) String() string { return prototext.Format(x) } // Modern way to implement String()
func (*PatchError) ProtoMessage() {}
// In a real generated file, ProtoReflect() would be fully implemented.
// For this example, we don't need it as the marshallers will use reflection.
func (x *PatchError) ProtoReflect() protoreflect.Message { return nil }
// --- End of mock ---
/*
user := &User{
UserName:"jdoe",
UserId: 12345,
Email: "[email protected]",
LastLogin: timestamppb.Now(),
}
fmt.Println"==========================================================")
fmt.Println"1. The Best Method: prototext.Format (like spew.Dump)")
fmt.Println"==========================================================")
// The prototext.Format function is the most direct equivalent.
outText := prototext.Format(user)
fmt.Println(outText)
*/
|