title: Go Protobuf declarations and optional Fields in Go Struct (string pointers)
body: <p>I am running into a bit of a problem with Protoc and my existing struct that contains nullable string fields.</p>
  
  <p>The struct I am trying to serialize for transmission contains a bunch of fields that are nullable in json (so we can distinguish between <code>null</code>, <code>""</code> and a set value).</p>
  
  <pre><code>type Message struct {
    Path *string `json:"path"`
  }
  </code></pre>
  
  <p>So if a user sends a empty json string <code>{}</code> the Path will be <code>nil</code> and not <code>""</code>, whereas <code>{"path":""}</code> is also valid and a different case from <code>{"path": null}</code>.</p>
  
  <p>The <code>proto3</code> declaration I came up with obviously looks like this (and is optional as <code>required</code> and <code>optional</code> got dropped from proto3:</p>
  
  <pre><code>syntax = "proto3";
  message Message {
    string Path = 1;
  }
  </code></pre>
  
  <p>After running Protoc I end up with a struct that looks like this and all values are <code>string</code> and no way to declare them as <code>*string</code>:</p>
  
  <pre><code>type Message struct {
    Path string `protobuf:"bytes,1,opt,name=Path,proto3" json:"Path,omitempty"`
  }
  </code></pre>
  
  <p>Obviously I can't assign to this array from my existing struct. But even if I were to write the tedious mapping code with <code>target.Path = *source.Path</code> with the appropriate null pointer checks etc I'd loose the triple meaning of my source struct (<code>nil</code>, <code>""</code>, <code>"value"</code>). </p>
  
  <p>Any suggestions on how to proceed here or if there is an extension to the Go Protobuf to do this? Or how would one go about describing this proto declaration?</p>