vendor/google.golang.org/protobuf/proto/encode.go
changeset 260 445e01aede7e
parent 256 6d9efbef00a9
equal deleted inserted replaced
259:db4911b0c721 260:445e01aede7e
    14 )
    14 )
    15 
    15 
    16 // MarshalOptions configures the marshaler.
    16 // MarshalOptions configures the marshaler.
    17 //
    17 //
    18 // Example usage:
    18 // Example usage:
    19 //   b, err := MarshalOptions{Deterministic: true}.Marshal(m)
    19 //
       
    20 //	b, err := MarshalOptions{Deterministic: true}.Marshal(m)
    20 type MarshalOptions struct {
    21 type MarshalOptions struct {
    21 	pragma.NoUnkeyedLiterals
    22 	pragma.NoUnkeyedLiterals
    22 
    23 
    23 	// AllowPartial allows messages that have missing required fields to marshal
    24 	// AllowPartial allows messages that have missing required fields to marshal
    24 	// without returning an error. If AllowPartial is false (the default),
    25 	// without returning an error. If AllowPartial is false (the default),
    99 
   100 
   100 // emptyBytesForMessage returns a nil buffer if and only if m is invalid,
   101 // emptyBytesForMessage returns a nil buffer if and only if m is invalid,
   101 // otherwise it returns a non-nil empty buffer.
   102 // otherwise it returns a non-nil empty buffer.
   102 //
   103 //
   103 // This is to assist the edge-case where user-code does the following:
   104 // This is to assist the edge-case where user-code does the following:
       
   105 //
   104 //	m1.OptionalBytes, _ = proto.Marshal(m2)
   106 //	m1.OptionalBytes, _ = proto.Marshal(m2)
       
   107 //
   105 // where they expect the proto2 "optional_bytes" field to be populated
   108 // where they expect the proto2 "optional_bytes" field to be populated
   106 // if any only if m2 is a valid message.
   109 // if any only if m2 is a valid message.
   107 func emptyBytesForMessage(m Message) []byte {
   110 func emptyBytesForMessage(m Message) []byte {
   108 	if m == nil || !m.ProtoReflect().IsValid() {
   111 	if m == nil || !m.ProtoReflect().IsValid() {
   109 		return nil
   112 		return nil