在golang中为proto buf类型编写自定义的Marshall和Unmarshaller

I have custom type that I wrote my own Marshall and Unmarshaller And the problem is I Want to do the same using protobuf

I just want to implement the same using protobuf, so that I can implement my own Marshall and Unmarshaller

syntax="proto3";

package main;

message NullInt64{
    bool Valid = 1;
    int64 Int64 = 2;
}

In the way that if the Valid value is false in return the null string

type NullInt64 struct {
    Int64 int64
    Valid bool
}

// MarshalJSON try to marshaling to json
func (nt NullInt64) MarshalJSON() ([]byte, error) {
    if nt.Valid {
        return []byte(fmt.Sprintf(`%d`, nt.Int64)), nil
    }

    return []byte("null"), nil
}

// UnmarshalJSON try to unmarshal dae from input
func (nt *NullInt64) UnmarshalJSON(b []byte) error {
    text := strings.ToLower(string(b))
    if text == "null" {
        nt.Valid = false

        return nil
    }

    err := json.Unmarshal(b, &nt.Int64)
    if err != nil {
        return err
    }

    nt.Valid = true
    return nil
}