Ejemplo n.º 1
0
void FieldGenerator::generateOptionalProperty(
    google::protobuf::io::Printer& p) {
  p.Print(variables_, "$i$$type$.prototype.get$capital_name$ = function() {\n");

  if (oneof_) {
    p.Print(variables_,
            "$i$  if (this.$oneof_camel$Case != "
            "type.$oneof_capital$Case.$all_capital_name$) {\n"
            "$i$    return undefined;\n"
            "$i$  } else {\n");
    indentUp();
    indentUp();
    genGet(p);
    indentDown();
    indentDown();
    // TODO: Currently, if undefined is passed to oneof field, the entire oneof
    // is cleared. It may better to ignore undefined value if the4 field is not
    // the active value at the time.
    p.Print(variables_,
            "    }\n"
            "  };\n"
            "$i$$type$.prototype.set$capital_name$ = function(value) {\n"
            "$i$  this.clear$oneof_capital$();\n"
            "$i$  this._oneofs[$oneof_index$] = "
            "type.$oneof_capital$Case.$all_capital_name$;\n");
  } else {
    indentUp();
    genGet(p);
    indentDown();
    p.Print(variables_,
            "$i$}\n"
            "$i$$type$.prototype.set$capital_name$ = function(value) {\n");
  }

  indentUp();
  genSet(p);
  indentDown();

  p.Print(variables_,
          "$i$};\n"
          "$i$$type$.prototype.clear$capital_name$ = function() {\n");
  indentUp();
  genClear(p);
  indentDown();
  if (oneof_) {
    p.Print(variables_,
            "$i$  if (this.$oneof_camel$Case == "
            "type.$oneof_capital$Case.$all_capital_name$) {\n"
            "$i$    this._oneofs[$oneof_index$] = "
            "type.$oneof_capital$Case.$oneof_all_capital$_NOT_SET;\n"
            "$i$  }\n");
  }
  p.Print(variables_,
          "$i$};\n"
          "$i$Object.defineProperty(type.prototype, '$name$', {\n"
          "$i$  get: $type$.prototype.get$capital_name$,\n"
          "$i$  set: $type$.prototype.set$capital_name$,\n"
          "$i$});\n\n");
}
Ejemplo n.º 2
0
uint32_t TDebugProtocol::writeSetEnd() {
  indentDown();
  write_state_.pop_back();
  uint32_t size = 0;
  size += writeIndented("}");
  size += endItem();
  return size;
}
Ejemplo n.º 3
0
uint32_t TDebugProtocol::writeMessageEnd() {
  indentDown();
  return writeIndented(")\n");
}
Ejemplo n.º 4
0
void DebugProtocolWriter::popState() {
  CHECK(!writeState_.empty());
  writeState_.pop_back();
  indentDown();
}
Ejemplo n.º 5
0
uint32_t DebugProtocolWriter::writeMessageEnd() {
  indentDown();
  writeIndented(")\n");
  return 0;
}