~bigbes/tarantool

tarantool-protobuf

9ee21c091d83431b7490d4ea3960df4b33f5f65c — Eugene Blikh 3 months ago 07eef11
codegen: inline 1-byte varint length prefix at every LEN emit site

Eliminates the wire.encode_varint(#body) call + dispatch for every
length-delimited field in mode=full codegen. Profile flagged the
out[n] = wire.encode_varint(#_b) line as ~33% of hello.Person 1KB
encode time, with another ~17% in encode_varint dispatch — together
~50% of encode time. Lifting the 1-byte fast path (the dominant case
for proto strings and small message bodies) to the call site removes
the function frame entirely for lengths < 128.

Applied at every LEN emit site: singular/repeated message body,
singular/repeated string|bytes, packed scalar bundle, packed enum
bundle, map entry. Map value pieces (emitMapPiece message branch)
left as-is — they sit inside a single slot assignment that would
require a deeper restructure, and maps are not on the current hot
benchmark.

Results (hello.Person full encode, msgs/s): 10B +6.9%, 100B +7.9%,
1KB +25.7%, 10KB +48.1%, 100KB +31.9%. Decode flat (unchanged path).
Runtime mode flat (descriptor dispatch still calls encode_varint).
JIT trace gate: 37/37. Test suite: 745/745.

Bench history saved to bench/PERF_LOG.md with full numbers and the
workflow this iteration follows.

beads-tarantool-protobuf-h8v
A bench/PERF_LOG.md => bench/PERF_LOG.md +170 -0
@@ 0,0 1,170 @@
# Performance optimization log

Iterative log of optimization work on tarantool-protobuf encode/decode hot paths.
Each entry captures: what changed, why, measured before/after, and any caveats.

## Workflow

For each beads task on the optimization track:

1. **Implement** — `bd update <id> --claim`, write the change.
2. **Test** — `just test`. Fix any breakage before measuring anything.
3. **Benchmark** — `just bench` (and `just jit-trace` if the change touches hot
   wire paths). Capture full output, compute deltas vs. previous entry's
   "after" numbers, and append a new entry to this file.
4. **Commit** — single commit per task, including the PERF_LOG.md update.
   `bd close <id>` afterwards.
5. **Next** — pick the next P1 (or whatever's at the top of `bd ready` in the
   perf bucket) and repeat from step 1.

Notes:
- "Before" for each entry equals the previous entry's "After" — single
  contiguous history, no per-task baselines.
- Always run `just bench` on a quiet machine; numbers can swing 5-10% from
  background noise on macOS. Re-run if a number looks suspicious.
- If a change regresses a workload (any cell drops >5%), document it
  honestly. A regression that buys 2× somewhere else is a tradeoff worth
  recording, not a failure to hide.
- Decoder, encoder, and the proto2 `BenchPayload` schemas are tracked
  separately because optimizations rarely move all three uniformly.

## Schemas tracked

- **hello.Person** at 10B / 100B / 1KB / 10KB / 100KB.
  Real-world-shaped: string fields, nested messages, repeated emails. Both
  `full` (inlined codegen) and `runtime` (descriptor dispatch) modes.
- **proto2_basic.BenchPayload** at `min` / `mid`. Pins proto2 extension and
  default-value paths.

## Baseline — 2026-05-18

Pre-optimization snapshot. Tarantool 3.7.0-0-g1f1ec9fdf, LuaJIT 2.1.0-beta3,
macOS arm64.

### hello.Person — encode

| mode    | size   | msgs/s    | MB/s   | alloc B/op |
|---------|--------|-----------|--------|------------|
| full    | 10B    | 2,250,858 | 22.5   | 136        |
| full    | 100B   | 2,215,919 | 208.3  | 136        |
| full    | 1KB    | 240,381   | 223.6  | 1368       |
| full    | 10KB   | 43,240    | 416.6  | 8540       |
| full    | 100KB  | 4,920     | 475.7  | 131605     |
| runtime | 10B    | 1,098,666 | 11.0   | 136        |
| runtime | 100B   | 1,089,811 | 102.4  | 136        |
| runtime | 1KB    | 186,459   | 173.4  | 1368       |
| runtime | 10KB   | 39,600    | 381.5  | 8540       |
| runtime | 100KB  | 4,433     | 428.5  | 131605     |

### hello.Person — decode

| mode    | size   | msgs/s    | MB/s   | alloc B/op |
|---------|--------|-----------|--------|------------|
| full    | 10B    | 2,476,811 | 24.8   | 112        |
| full    | 100B   | 2,091,875 | 196.6  | 112        |
| full    | 1KB    | 109,479   | 101.8  | 1000       |
| full    | 10KB   | 14,961    | 144.1  | 4840       |
| full    | 100KB  | 1,461     | 141.3  | 33512      |
| runtime | 10B    | 2,103,514 | 21.0   | 112        |
| runtime | 100B   | 1,843,624 | 173.3  | 112        |
| runtime | 1KB    | 103,503   | 96.3   | 1000       |
| runtime | 10KB   | 13,710    | 132.1  | 4840       |
| runtime | 100KB  | 1,336     | 129.1  | 33512      |

### proto2_basic.BenchPayload

| mode    | size | enc msgs/s | enc MB/s | dec msgs/s | dec MB/s |
|---------|------|------------|----------|------------|----------|
| full    | min  | 1,485,112  | 7.4      | 846,439    | 4.2      |
| full    | mid  | 181,413    | 110.5    | 73,650     | 44.9     |
| runtime | min  | 1,163,210  | 5.8      | 982,154    | 4.9      |
| runtime | mid  | 162,481    | 99.0     | 73,952     | 45.0     |

---

<!-- Append new entries below this line. Newest at the top. -->

## 2026-05-18 — h8v: inline 1-byte varint length prefix at codegen sites

**Task:** [tarantool-protobuf-h8v] Encoder: codegen-time inline FFI writes (mode=full)
— first slice. Full FFI-buffer rewrite is still future work; this attacks
the single hottest line identified by jit.p profiling.

**Change:** In `cmd/protoc-gen-tarantool/internal/gen/inline.go`, every
length-prefixed emit site (singular/repeated message, singular/repeated
string|bytes, packed scalar bundle, packed enum bundle, map entry) now
inlines the 1-byte varint fast path:

```lua
-- Before:
n = n + 1; out[n] = wire.encode_varint(#_b)

-- After:
local _len = #_b
if _len < 128 then
    n = n + 1; out[n] = string.char(_len)
else
    n = n + 1; out[n] = wire.encode_varint(_len)
end
```

Eliminates the function call + dispatch for every length prefix under 128
bytes — which is the dominant case for proto strings, message bodies, and
packed scalar bundles. Profile flagged this as ~33% of encode time
(`out[n] = wire.encode_varint(#_b)`) + another ~17% in encode_varint
dispatch.

**Tests:** 745/745 pass. JIT trace gate: 37/37 (no regressions).

**Bench (hello.Person — full encode, msgs/s and Δ vs baseline):**

| size  | before    | after     | Δ        |
|-------|-----------|-----------|----------|
| 10B   | 2,250,858 | 2,405,176 | +6.9%    |
| 100B  | 2,215,919 | 2,389,715 | +7.9%    |
| 1KB   | 240,381   | 302,117   | **+25.7%** |
| 10KB  | 43,240    | 64,052    | **+48.1%** |
| 100KB | 4,920     | 6,487     | **+31.9%** |

**Bench (hello.Person — full decode):** flat (±1%). Expected; decode path
unchanged.

**Bench (runtime mode):** flat (±2%). Expected; only `mode=full` codegen
touched, runtime mode dispatches through `pb.codec.encode_field` which
still calls into `wire.encode_varint` for length prefixes.

**Bench (proto2_basic.BenchPayload — full):**

| size | dir | before    | after     | Δ      |
|------|-----|-----------|-----------|--------|
| min  | enc | 1,485,112 | 1,502,031 | +1.1%  |
| mid  | enc | 181,413   | 203,832   | +12.4% |
| min  | dec | 846,439   | 897,014   | +6.0%  |
| mid  | dec | 73,650    | 71,496    | -2.9%  |

`mid` decode -2.9% is within run-to-run noise (proto2 mid has no string
fields touched by this change; the wider distribution at 73K msgs/s
swings ±5%).

**Alloc/op:** unchanged (table-of-strings model preserved). Future h8v
slices targeting the per-field table writes themselves would move this.

**Caveats / leftovers:**
- The 1-byte ceiling at 128 bytes matches the proto3 varint boundary; the
  `100KB` Person bench has email-string + name-string lengths above 128,
  so it pays the slow path for those — but message-body lengths there
  are still mostly < 128 because they wrap individual nested messages.
  Net result is still +32%.
- Map encode still uses `table.concat(entry)` then inlined length prefix.
  Per-piece `wire.encode_len(...)` inside map _values_ (`emitMapPiece`
  message branch) was not rewritten — the call sits inside a single
  `out[idx] = ...` slot assignment and untangling it would require
  separating value-build from value-write. Map fields are not on the
  current hot benchmark; deferred.
- Runtime mode (descriptor dispatch via `pb.codec.encode_field`) does
  not benefit. The corresponding follow-up is **21d** (codec dispatch
  fragmenting traces); independent route to similar wins.

**Commit:** see git history for SHA.

---

M cmd/protoc-gen-tarantool/internal/gen/inline.go => cmd/protoc-gen-tarantool/internal/gen/inline.go +34 -9
@@ 86,6 86,29 @@ func emitInlineEncode(w *writer, name string, m *protogen.Message, file *protoge
	w.line("")
}

// emitInlineLenPrefix emits the length-prefix append for a length-delimited
// field (LEN wire type: string, bytes, message body, packed scalars).
//
// Lifts the 1-byte varint fast path out of wire.encode_varint and inlines it
// at the call site. Eliminates the function call + dispatch on the dominant
// short-payload case (length < 128). encode_varint dispatch alone was ~17%
// of encode time on the hello.Person 1KB benchmark before this; the
// surrounding `out[n] = wire.encode_varint(#_b)` was another ~33%.
//
// `indent` is the Lua indentation string (e.g. "    " or "        ") that
// each emitted line starts with. `bodyExpr` is the Lua expression for the
// payload local (typically "v" or "_b"); its length is read once into a
// local so `#bodyExpr` doesn't re-evaluate. Caller is responsible for
// emitting the tag and the body itself around this call.
func emitInlineLenPrefix(w *writer, indent, bodyExpr string) {
	w.line("%slocal _len = #%s", indent, bodyExpr)
	w.line("%sif _len < 128 then", indent)
	w.line("%s    n = n + 1; out[n] = string.char(_len)", indent)
	w.line("%selse", indent)
	w.line("%s    n = n + 1; out[n] = wire.encode_varint(_len)", indent)
	w.line("%send", indent)
}

// realOneofs returns the message's non-synthetic oneofs (skips the ones
// proto3 expands explicit `optional` into).
func realOneofs(m *protogen.Message) []*protogen.Oneof {


@@ 165,7 188,7 @@ func emitInlineEncodeField(w *writer, f *protogen.Field, file *protogen.File, se
			w.line("    if %s then", gate)
			w.line("        local _b = %s(v)", ref)
			w.line("        n = n + 1; out[n] = %s", tag)
			w.line("        n = n + 1; out[n] = wire.encode_varint(#_b)")
			emitInlineLenPrefix(w, "        ", "_b")
			w.line("        n = n + 1; out[n] = _b")
			w.line("    end")
		}


@@ 205,7 228,7 @@ func emitInlineEncodeField(w *writer, f *protogen.Field, file *protogen.File, se
			// concatenate the length prefix and body — emit them as
			// separate `out` slots instead and let table.concat join.
			w.line("        n = n + 1; out[n] = %s", tag)
			w.line("        n = n + 1; out[n] = wire.encode_varint(#v)")
			emitInlineLenPrefix(w, "        ", "v")
			w.line("        n = n + 1; out[n] = v")
		} else {
			w.line("        n = n + 1; out[n] = %s", tag)


@@ 227,7 250,7 @@ func emitInlineEncodeRequiredField(w *writer, f *protogen.Field, tag string, fil
		ref := typeRef(file, f.Message.Desc, selfPath, imports, "_encode", prefix)
		w.line("    local _b = %s(v)", ref)
		w.line("    n = n + 1; out[n] = %s", tag)
		w.line("    n = n + 1; out[n] = wire.encode_varint(#_b)")
		emitInlineLenPrefix(w, "    ", "_b")
		w.line("    n = n + 1; out[n] = _b")
	case f.Enum != nil:
		enumLocal := typeRef(file, f.Enum.Desc, selfPath, imports, "", prefix)


@@ 248,7 271,7 @@ func emitInlineEncodeRequiredField(w *writer, f *protogen.Field, tag string, fil
		}
		if st == "string" || st == "bytes" {
			w.line("    n = n + 1; out[n] = %s", tag)
			w.line("    n = n + 1; out[n] = wire.encode_varint(#v)")
			emitInlineLenPrefix(w, "    ", "v")
			w.line("    n = n + 1; out[n] = v")
		} else {
			w.line("    n = n + 1; out[n] = %s", tag)


@@ 278,7 301,7 @@ func emitInlineEncodeRepeated(w *writer, f *protogen.Field, tag, fname string, f
			w.line("        for _i = 1, #v do")
			w.line("            local _b = %s(v[_i])", ref)
			w.line("            n = n + 1; out[n] = _tag")
			w.line("            n = n + 1; out[n] = wire.encode_varint(#_b)")
			emitInlineLenPrefix(w, "            ", "_b")
			w.line("            n = n + 1; out[n] = _b")
			w.line("        end")
			w.line("    end")


@@ 299,7 322,7 @@ func emitInlineEncodeRepeated(w *writer, f *protogen.Field, tag, fname string, f
		w.line("        end")
		w.line("        local _b = table.concat(parts)")
		w.line("        n = n + 1; out[n] = %s", tag)
		w.line("        n = n + 1; out[n] = wire.encode_varint(#_b)")
		emitInlineLenPrefix(w, "        ", "_b")
		w.line("        n = n + 1; out[n] = _b")
		w.line("    end")
	default:


@@ 313,7 336,7 @@ func emitInlineEncodeRepeated(w *writer, f *protogen.Field, tag, fname string, f
			w.line("        end")
			w.line("        local _b = table.concat(parts)")
			w.line("        n = n + 1; out[n] = %s", tag)
			w.line("        n = n + 1; out[n] = wire.encode_varint(#_b)")
			emitInlineLenPrefix(w, "        ", "_b")
			w.line("        n = n + 1; out[n] = _b")
			w.line("    end")
		} else if st == "string" || st == "bytes" {


@@ 322,7 345,7 @@ func emitInlineEncodeRepeated(w *writer, f *protogen.Field, tag, fname string, f
			w.line("        for _i = 1, #v do")
			w.line("            local _b = v[_i]")
			w.line("            n = n + 1; out[n] = _tag")
			w.line("            n = n + 1; out[n] = wire.encode_varint(#_b)")
			emitInlineLenPrefix(w, "            ", "_b")
			w.line("            n = n + 1; out[n] = _b")
			w.line("        end")
			w.line("    end")


@@ 547,7 570,9 @@ func emitInlineEncodeMap(w *writer, f *protogen.Field, tag string, file *protoge
	w.line("            end")

	w.line("            n = n + 1; out[n] = _tag")
	w.line("            n = n + 1; out[n] = wire.encode_len(table.concat(entry))")
	w.line("            local _b = table.concat(entry)")
	emitInlineLenPrefix(w, "            ", "_b")
	w.line("            n = n + 1; out[n] = _b")
	w.line("        end")
	w.line("    end")
}

M examples/expected/full/conformance/conformance_pb.lua => examples/expected/full/conformance/conformance_pb.lua +114 -19
@@ 208,21 208,36 @@ function M.TestStatus_encode(t)
    v = t.name
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 2: failure_message
    v = t.failure_message
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 3: matched_name
    v = t.matched_name
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x1a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    local _exts = t._extensions


@@ 312,7 327,12 @@ function M.FailureSet_encode(t)
        for _i = 1, #v do
            local _b = M.TestStatus_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 399,28 419,48 @@ function M.ConformanceRequest_encode(t)
    v = t.protobuf_payload
    if _of_payload == "protobuf_payload" then
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 2: json_payload
    v = t.json_payload
    if _of_payload == "json_payload" then
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 7: jspb_payload
    v = t.jspb_payload
    if _of_payload == "jspb_payload" then
        n = n + 1; out[n] = "\x3a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 8: text_payload
    v = t.text_payload
    if _of_payload == "text_payload" then
        n = n + 1; out[n] = "\x42"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 3: requested_output_format


@@ 440,7 480,12 @@ function M.ConformanceRequest_encode(t)
    v = t.message_type
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x22"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 5: test_category


@@ 461,7 506,12 @@ function M.ConformanceRequest_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.JspbEncodingConfig_encode(v)
        n = n + 1; out[n] = "\x32"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 9: print_unknown_fields


@@ 605,63 655,108 @@ function M.ConformanceResponse_encode(t)
    v = t.parse_error
    if _of_result == "parse_error" then
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 6: serialize_error
    v = t.serialize_error
    if _of_result == "serialize_error" then
        n = n + 1; out[n] = "\x32"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 9: timeout_error
    v = t.timeout_error
    if _of_result == "timeout_error" then
        n = n + 1; out[n] = "\x4a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 2: runtime_error
    v = t.runtime_error
    if _of_result == "runtime_error" then
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 3: protobuf_payload
    v = t.protobuf_payload
    if _of_result == "protobuf_payload" then
        n = n + 1; out[n] = "\x1a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 4: json_payload
    v = t.json_payload
    if _of_result == "json_payload" then
        n = n + 1; out[n] = "\x22"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 5: skipped
    v = t.skipped
    if _of_result == "skipped" then
        n = n + 1; out[n] = "\x2a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 7: jspb_payload
    v = t.jspb_payload
    if _of_result == "jspb_payload" then
        n = n + 1; out[n] = "\x3a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 8: text_payload
    v = t.text_payload
    if _of_result == "text_payload" then
        n = n + 1; out[n] = "\x42"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    local _exts = t._extensions

M examples/expected/full/hello/hello_pb.lua => examples/expected/full/hello/hello_pb.lua +174 -28
@@ 229,7 229,12 @@ function M.Result_encode(t)
    v = t.text
    if _of_outcome == "text" then
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 3: code


@@ 243,7 248,12 @@ function M.Result_encode(t)
    if _of_outcome == "details" then
        local _b = M.Address_encode(v)
        n = n + 1; out[n] = "\x22"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    local _exts = t._extensions


@@ 345,7 355,12 @@ function M.HelloRequest_encode(t)
    v = t.name
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    local _exts = t._extensions


@@ 424,7 439,12 @@ function M.HelloReply_encode(t)
    v = t.greeting
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    local _exts = t._extensions


@@ 503,7 523,12 @@ function M.Event_encode(t)
    v = t.title
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 2: created_at


@@ 511,7 536,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Timestamp_encode(v)
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 3: duration


@@ 519,7 549,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Duration_encode(v)
        n = n + 1; out[n] = "\x1a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 4: ack


@@ 527,7 562,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Empty_encode(v)
        n = n + 1; out[n] = "\x22"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 5: retry_count


@@ 535,7 575,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Int32Value_encode(v)
        n = n + 1; out[n] = "\x2a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 6: note


@@ 543,7 588,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.StringValue_encode(v)
        n = n + 1; out[n] = "\x32"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 7: is_admin


@@ 551,7 601,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.BoolValue_encode(v)
        n = n + 1; out[n] = "\x3a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 8: payload


@@ 559,7 614,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Struct_encode(v)
        n = n + 1; out[n] = "\x42"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 9: attribute


@@ 567,7 627,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Value_encode(v)
        n = n + 1; out[n] = "\x4a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 10: tags


@@ 575,7 640,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.ListValue_encode(v)
        n = n + 1; out[n] = "\x52"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 11: extension


@@ 583,7 653,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Any_encode(v)
        n = n + 1; out[n] = "\x5a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 12: update_mask


@@ 591,7 666,12 @@ function M.Event_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.FieldMask_encode(v)
        n = n + 1; out[n] = "\x62"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    local _exts = t._extensions


@@ 714,14 794,24 @@ function M.Address_encode(t)
    v = t.street
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 2: city
    v = t.city
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 3: zip


@@ 734,7 824,12 @@ function M.Address_encode(t)
    v = t.apartment
    if v ~= nil then
        n = n + 1; out[n] = "\x22"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    local _exts = t._extensions


@@ 830,7 925,12 @@ function M.Person_encode(t)
    v = t.name
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 2: age


@@ 846,7 946,12 @@ function M.Person_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 868,7 973,12 @@ function M.Person_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.Address_encode(v)
        n = n + 1; out[n] = "\x2a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 6: friends


@@ 878,7 988,12 @@ function M.Person_encode(t)
        for _i = 1, #v do
            local _b = M.Person_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 891,14 1006,24 @@ function M.Person_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x3a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 8: avatar
    v = t.avatar
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x42"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 9: user_id


@@ 934,7 1059,14 @@ function M.Person_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_int32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 14: nickname_by_age


@@ 952,7 1084,14 @@ function M.Person_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_string(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 15: addresses_by_label


@@ 970,7 1109,14 @@ function M.Person_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_len(M.Address_encode(_val))
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    local _exts = t._extensions

M examples/expected/full/proto2_basic/proto2_basic_pb.lua => examples/expected/full/proto2_basic/proto2_basic_pb.lua +66 -11
@@ 252,7 252,12 @@ function M.Defaults_encode(t)
    v = t.s
    if v ~= nil then
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 3: b


@@ 289,7 294,12 @@ function M.Defaults_encode(t)
    v = t.by
    if v ~= nil then
        n = n + 1; out[n] = "\x42"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 9: color


@@ 483,7 493,12 @@ function M.Cardinality_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x22"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 5: explicitly_unpacked


@@ 634,14 649,24 @@ function M.Nested_encode(t)
    end
    local _b = M.Nested_Inner_encode(v)
    n = n + 1; out[n] = "\x0a"
    n = n + 1; out[n] = wire.encode_varint(#_b)
    local _len = #_b
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = _b
    -- field 2: inner_opt
    v = t.inner_opt
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.Nested_Inner_encode(v)
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    local _exts = t._extensions


@@ 930,7 955,12 @@ function M.WithGroup_SingleGroup_encode(t)
    v = t.s
    if v ~= nil then
        n = n + 1; out[n] = "\x1a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    local _exts = t._extensions


@@ 1113,7 1143,12 @@ function M.BenchPayload_encode(t)
    v = t.name
    if v ~= nil then
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 3: retries


@@ 1131,7 1166,12 @@ function M.BenchPayload_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x22"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 5: tags


@@ 1141,7 1181,12 @@ function M.BenchPayload_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1150,7 1195,12 @@ function M.BenchPayload_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.BenchPayload_Inner_encode(v)
        n = n + 1; out[n] = "\x32"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 7: stats


@@ 1405,7 1455,12 @@ function M.BenchPayload_Inner_encode(t)
        error("required field missing on encode: proto2_basic.BenchPayload.Inner.key", 0)
    end
    n = n + 1; out[n] = "\x0a"
    n = n + 1; out[n] = wire.encode_varint(#v)
    local _len = #v
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = v
    -- field 2: weight
    v = t.weight

M examples/expected/full/protobuf_test_messages/proto2/test_messages_proto2_pb.lua => examples/expected/full/protobuf_test_messages/proto2/test_messages_proto2_pb.lua +522 -80
@@ 996,14 996,24 @@ function M.TestAllTypesProto2_encode(t)
    v = t.optional_string
    if v ~= nil then
        n = n + 1; out[n] = "\x72"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 15: optional_bytes
    v = t.optional_bytes
    if v ~= nil then
        n = n + 1; out[n] = "\x7a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 18: optional_nested_message


@@ 1011,7 1021,12 @@ function M.TestAllTypesProto2_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.TestAllTypesProto2_NestedMessage_encode(v)
        n = n + 1; out[n] = "\x92\x01"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 19: optional_foreign_message


@@ 1019,7 1034,12 @@ function M.TestAllTypesProto2_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.ForeignMessageProto2_encode(v)
        n = n + 1; out[n] = "\x9a\x01"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 21: optional_nested_enum


@@ 1048,14 1068,24 @@ function M.TestAllTypesProto2_encode(t)
    v = t.optional_string_piece
    if v ~= nil then
        n = n + 1; out[n] = "\xc2\x01"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 25: optional_cord
    v = t.optional_cord
    if v ~= nil then
        n = n + 1; out[n] = "\xca\x01"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 27: recursive_message


@@ 1063,7 1093,12 @@ function M.TestAllTypesProto2_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.TestAllTypesProto2_encode(v)
        n = n + 1; out[n] = "\xda\x01"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 31: repeated_int32


@@ 1190,7 1225,12 @@ function M.TestAllTypesProto2_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1201,7 1241,12 @@ function M.TestAllTypesProto2_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1212,7 1257,12 @@ function M.TestAllTypesProto2_encode(t)
        for _i = 1, #v do
            local _b = M.TestAllTypesProto2_NestedMessage_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1223,7 1273,12 @@ function M.TestAllTypesProto2_encode(t)
        for _i = 1, #v do
            local _b = M.ForeignMessageProto2_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1242,7 1297,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x98\x03"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 52: repeated_foreign_enum


@@ 1260,7 1320,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xa0\x03"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 54: repeated_string_piece


@@ 1270,7 1335,12 @@ function M.TestAllTypesProto2_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1281,7 1351,12 @@ function M.TestAllTypesProto2_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1294,7 1369,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xda\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 76: packed_int64


@@ 1306,7 1386,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xe2\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 77: packed_uint32


@@ 1318,7 1403,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xea\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 78: packed_uint64


@@ 1330,7 1420,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xf2\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 79: packed_sint32


@@ 1342,7 1437,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xfa\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 80: packed_sint64


@@ 1354,7 1454,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x82\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 81: packed_fixed32


@@ 1366,7 1471,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x8a\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 82: packed_fixed64


@@ 1378,7 1488,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x92\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 83: packed_sfixed32


@@ 1390,7 1505,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x9a\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 84: packed_sfixed64


@@ 1402,7 1522,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xa2\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 85: packed_float


@@ 1414,7 1539,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xaa\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 86: packed_double


@@ 1426,7 1556,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xb2\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 87: packed_bool


@@ 1438,7 1573,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xba\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 88: packed_nested_enum


@@ 1456,7 1596,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xc2\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 89: unpacked_int32


@@ 1591,7 1736,12 @@ function M.TestAllTypesProto2_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xb0\x06"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 56: map_int32_int32


@@ 1609,7 1759,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_int32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 57: map_int64_int64


@@ 1627,7 1784,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_int64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 58: map_uint32_uint32


@@ 1645,7 1809,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_uint32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 59: map_uint64_uint64


@@ 1663,7 1834,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_uint64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 60: map_sint32_sint32


@@ 1681,7 1859,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_sint32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 61: map_sint64_sint64


@@ 1699,7 1884,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_sint64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 62: map_fixed32_fixed32


@@ 1717,7 1909,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_fixed32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 63: map_fixed64_fixed64


@@ 1735,7 1934,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_fixed64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 64: map_sfixed32_sfixed32


@@ 1753,7 1959,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_sfixed32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 65: map_sfixed64_sfixed64


@@ 1771,7 1984,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_sfixed64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 104: map_int32_bool


@@ 1789,7 2009,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_bool(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 66: map_int32_float


@@ 1807,7 2034,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_float(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 67: map_int32_double


@@ 1825,7 2059,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_double(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 103: map_int32_nested_message


@@ 1843,7 2084,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_len(M.TestAllTypesProto2_NestedMessage_encode(_val))
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 68: map_bool_bool


@@ 1861,7 2109,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_bool(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 69: map_string_string


@@ 1879,7 2134,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_string(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 70: map_string_bytes


@@ 1897,7 2159,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_bytes(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 71: map_string_nested_message


@@ 1915,7 2184,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_len(M.TestAllTypesProto2_NestedMessage_encode(_val))
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 72: map_string_foreign_message


@@ 1933,7 2209,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_len(M.ForeignMessageProto2_encode(_val))
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 73: map_string_nested_enum


@@ 1956,7 2239,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_int32(_nv)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 74: map_string_foreign_enum


@@ 1979,7 2269,14 @@ function M.TestAllTypesProto2_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_int32(_nv)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 111: oneof_uint32


@@ 1993,21 2290,36 @@ function M.TestAllTypesProto2_encode(t)
    if _of_oneof_field == "oneof_nested_message" then
        local _b = M.TestAllTypesProto2_NestedMessage_encode(v)
        n = n + 1; out[n] = "\x82\x07"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 113: oneof_string
    v = t.oneof_string
    if _of_oneof_field == "oneof_string" then
        n = n + 1; out[n] = "\x8a\x07"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 114: oneof_bytes
    v = t.oneof_bytes
    if _of_oneof_field == "oneof_bytes" then
        n = n + 1; out[n] = "\x92\x07"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 115: oneof_bool


@@ 2141,14 2453,24 @@ function M.TestAllTypesProto2_encode(t)
    v = t.default_string
    if v ~= nil then
        n = n + 1; out[n] = "\xf2\x0f"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 255: default_bytes
    v = t.default_bytes
    if v ~= nil then
        n = n + 1; out[n] = "\xfa\x0f"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 401: fieldname1


@@ 4180,7 4502,12 @@ function M.TestAllTypesProto2_NestedMessage_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.TestAllTypesProto2_encode(v)
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    local _exts = t._extensions


@@ 4661,7 4988,12 @@ function M.UnknownToTestAllTypes_encode(t)
    v = t.optional_string
    if v ~= nil then
        n = n + 1; out[n] = "\xd2\x3e"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 1003: nested_message


@@ 4669,7 5001,12 @@ function M.UnknownToTestAllTypes_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.ForeignMessageProto2_encode(v)
        n = n + 1; out[n] = "\xda\x3e"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 1004: optionalgroup


@@ 5059,7 5396,12 @@ function M.OneStringProto2_encode(t)
    v = t.data
    if v ~= nil then
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    local _exts = t._extensions


@@ 5149,7 5491,12 @@ function M.ProtoWithKeywords_encode(t)
    v = t.concept
    if v ~= nil then
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 3: requires


@@ 5159,7 5506,12 @@ function M.ProtoWithKeywords_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 5352,7 5704,12 @@ function M.TestAllRequiredTypesProto2_encode(t)
        error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.required_string", 0)
    end
    n = n + 1; out[n] = "\x72"
    n = n + 1; out[n] = wire.encode_varint(#v)
    local _len = #v
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = v
    -- field 15: required_bytes
    v = t.required_bytes


@@ 5360,7 5717,12 @@ function M.TestAllRequiredTypesProto2_encode(t)
        error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.required_bytes", 0)
    end
    n = n + 1; out[n] = "\x7a"
    n = n + 1; out[n] = wire.encode_varint(#v)
    local _len = #v
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = v
    -- field 18: required_nested_message
    v = t.required_nested_message


@@ 5369,7 5731,12 @@ function M.TestAllRequiredTypesProto2_encode(t)
    end
    local _b = M.TestAllRequiredTypesProto2_NestedMessage_encode(v)
    n = n + 1; out[n] = "\x92\x01"
    n = n + 1; out[n] = wire.encode_varint(#_b)
    local _len = #_b
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = _b
    -- field 19: required_foreign_message
    v = t.required_foreign_message


@@ 5378,7 5745,12 @@ function M.TestAllRequiredTypesProto2_encode(t)
    end
    local _b = M.ForeignMessageProto2_encode(v)
    n = n + 1; out[n] = "\x9a\x01"
    n = n + 1; out[n] = wire.encode_varint(#_b)
    local _len = #_b
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = _b
    -- field 21: required_nested_enum
    v = t.required_nested_enum


@@ 5414,7 5786,12 @@ function M.TestAllRequiredTypesProto2_encode(t)
        error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.required_string_piece", 0)
    end
    n = n + 1; out[n] = "\xc2\x01"
    n = n + 1; out[n] = wire.encode_varint(#v)
    local _len = #v
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = v
    -- field 25: required_cord
    v = t.required_cord


@@ 5422,7 5799,12 @@ function M.TestAllRequiredTypesProto2_encode(t)
        error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.required_cord", 0)
    end
    n = n + 1; out[n] = "\xca\x01"
    n = n + 1; out[n] = wire.encode_varint(#v)
    local _len = #v
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = v
    -- field 27: recursive_message
    v = t.recursive_message


@@ 5431,14 5813,24 @@ function M.TestAllRequiredTypesProto2_encode(t)
    end
    local _b = M.TestAllRequiredTypesProto2_encode(v)
    n = n + 1; out[n] = "\xda\x01"
    n = n + 1; out[n] = wire.encode_varint(#_b)
    local _len = #_b
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = _b
    -- field 28: optional_recursive_message
    v = t.optional_recursive_message
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.TestAllRequiredTypesProto2_encode(v)
        n = n + 1; out[n] = "\xe2\x01"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 201: data


@@ 5448,7 5840,12 @@ function M.TestAllRequiredTypesProto2_encode(t)
    end
    local _b = M.TestAllRequiredTypesProto2_Data_encode(v)
    n = n + 1; out[n] = "\xcb\x0c"
    n = n + 1; out[n] = wire.encode_varint(#_b)
    local _len = #_b
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = _b
    -- field 241: default_int32
    v = t.default_int32


@@ 5547,7 5944,12 @@ function M.TestAllRequiredTypesProto2_encode(t)
        error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.default_string", 0)
    end
    n = n + 1; out[n] = "\xf2\x0f"
    n = n + 1; out[n] = wire.encode_varint(#v)
    local _len = #v
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = v
    -- field 255: default_bytes
    v = t.default_bytes


@@ 5555,7 5957,12 @@ function M.TestAllRequiredTypesProto2_encode(t)
        error("required field missing on encode: protobuf_test_messages.proto2.TestAllRequiredTypesProto2.default_bytes", 0)
    end
    n = n + 1; out[n] = "\xfa\x0f"
    n = n + 1; out[n] = wire.encode_varint(#v)
    local _len = #v
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = v
    local _exts = t._extensions
    if _exts ~= nil then


@@ 5825,14 6232,24 @@ function M.TestAllRequiredTypesProto2_NestedMessage_encode(t)
    end
    local _b = M.TestAllRequiredTypesProto2_encode(v)
    n = n + 1; out[n] = "\x12"
    n = n + 1; out[n] = wire.encode_varint(#_b)
    local _len = #_b
    if _len < 128 then
        n = n + 1; out[n] = string.char(_len)
    else
        n = n + 1; out[n] = wire.encode_varint(_len)
    end
    n = n + 1; out[n] = _b
    -- field 3: optional_corecursive
    v = t.optional_corecursive
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.TestAllRequiredTypesProto2_encode(v)
        n = n + 1; out[n] = "\x1a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    local _exts = t._extensions


@@ 6031,7 6448,12 @@ function M.TestLargeOneof_encode(t)
    if _of_large_oneof == "a1" then
        local _b = M.TestLargeOneof_A1_encode(v)
        n = n + 1; out[n] = "\x0a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 2: a2


@@ 6039,7 6461,12 @@ function M.TestLargeOneof_encode(t)
    if _of_large_oneof == "a2" then
        local _b = M.TestLargeOneof_A2_encode(v)
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 3: a3


@@ 6047,7 6474,12 @@ function M.TestLargeOneof_encode(t)
    if _of_large_oneof == "a3" then
        local _b = M.TestLargeOneof_A3_encode(v)
        n = n + 1; out[n] = "\x1a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 4: a4


@@ 6055,7 6487,12 @@ function M.TestLargeOneof_encode(t)
    if _of_large_oneof == "a4" then
        local _b = M.TestLargeOneof_A4_encode(v)
        n = n + 1; out[n] = "\x22"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 5: a5


@@ 6063,7 6500,12 @@ function M.TestLargeOneof_encode(t)
    if _of_large_oneof == "a5" then
        local _b = M.TestLargeOneof_A5_encode(v)
        n = n + 1; out[n] = "\x2a"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    local _exts = t._extensions

M examples/expected/full/protobuf_test_messages/proto3/test_messages_proto3_pb.lua => examples/expected/full/protobuf_test_messages/proto3/test_messages_proto3_pb.lua +632 -99
@@ 691,14 691,24 @@ function M.TestAllTypesProto3_encode(t)
    v = t.optional_string
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x72"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 15: optional_bytes
    v = t.optional_bytes
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x7a"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 18: optional_nested_message


@@ 706,7 716,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.TestAllTypesProto3_NestedMessage_encode(v)
        n = n + 1; out[n] = "\x92\x01"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 19: optional_foreign_message


@@ 714,7 729,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.ForeignMessage_encode(v)
        n = n + 1; out[n] = "\x9a\x01"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 21: optional_nested_enum


@@ 760,14 780,24 @@ function M.TestAllTypesProto3_encode(t)
    v = t.optional_string_piece
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\xc2\x01"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 25: optional_cord
    v = t.optional_cord
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\xca\x01"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 27: recursive_message


@@ 775,7 805,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.TestAllTypesProto3_encode(v)
        n = n + 1; out[n] = "\xda\x01"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 31: repeated_int32


@@ 787,7 822,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xfa\x01"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 32: repeated_int64


@@ 799,7 839,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x82\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 33: repeated_uint32


@@ 811,7 856,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x8a\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 34: repeated_uint64


@@ 823,7 873,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x92\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 35: repeated_sint32


@@ 835,7 890,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x9a\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 36: repeated_sint64


@@ 847,7 907,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xa2\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 37: repeated_fixed32


@@ 859,7 924,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xaa\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 38: repeated_fixed64


@@ 871,7 941,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xb2\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 39: repeated_sfixed32


@@ 883,7 958,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xba\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 40: repeated_sfixed64


@@ 895,7 975,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xc2\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 41: repeated_float


@@ 907,7 992,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xca\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 42: repeated_double


@@ 919,7 1009,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xd2\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 43: repeated_bool


@@ 931,7 1026,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xda\x02"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 44: repeated_string


@@ 941,7 1041,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 952,7 1057,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 963,7 1073,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = M.TestAllTypesProto3_NestedMessage_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 974,7 1089,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = M.ForeignMessage_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 993,7 1113,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x9a\x03"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 52: repeated_foreign_enum


@@ 1011,7 1136,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xa2\x03"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 54: repeated_string_piece


@@ 1021,7 1151,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1032,7 1167,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1045,7 1185,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xda\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 76: packed_int64


@@ 1057,7 1202,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xe2\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 77: packed_uint32


@@ 1069,7 1219,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xea\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 78: packed_uint64


@@ 1081,7 1236,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xf2\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 79: packed_sint32


@@ 1093,7 1253,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xfa\x04"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 80: packed_sint64


@@ 1105,7 1270,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x82\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 81: packed_fixed32


@@ 1117,7 1287,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x8a\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 82: packed_fixed64


@@ 1129,7 1304,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x92\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 83: packed_sfixed32


@@ 1141,7 1321,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\x9a\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 84: packed_sfixed64


@@ 1153,7 1338,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xa2\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 85: packed_float


@@ 1165,7 1355,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xaa\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 86: packed_double


@@ 1177,7 1372,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xb2\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 87: packed_bool


@@ 1189,7 1389,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xba\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 88: packed_nested_enum


@@ 1207,7 1412,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xc2\x05"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 89: unpacked_int32


@@ 1342,7 1552,12 @@ function M.TestAllTypesProto3_encode(t)
        end
        local _b = table.concat(parts)
        n = n + 1; out[n] = "\xb0\x06"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 56: map_int32_int32


@@ 1360,7 1575,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_int32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 57: map_int64_int64


@@ 1378,7 1600,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_int64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 58: map_uint32_uint32


@@ 1396,7 1625,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_uint32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 59: map_uint64_uint64


@@ 1414,7 1650,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_uint64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 60: map_sint32_sint32


@@ 1432,7 1675,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_sint32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 61: map_sint64_sint64


@@ 1450,7 1700,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_sint64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 62: map_fixed32_fixed32


@@ 1468,7 1725,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_fixed32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 63: map_fixed64_fixed64


@@ 1486,7 1750,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_fixed64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 64: map_sfixed32_sfixed32


@@ 1504,7 1775,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_sfixed32(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 65: map_sfixed64_sfixed64


@@ 1522,7 1800,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_sfixed64(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 66: map_int32_float


@@ 1540,7 1825,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_float(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 67: map_int32_double


@@ 1558,7 1850,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_double(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 68: map_bool_bool


@@ 1576,7 1875,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_bool(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 69: map_string_string


@@ 1594,7 1900,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_string(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 70: map_string_bytes


@@ 1612,7 1925,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_bytes(_val)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 71: map_string_nested_message


@@ 1630,7 1950,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_len(M.TestAllTypesProto3_NestedMessage_encode(_val))
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 72: map_string_foreign_message


@@ 1648,7 1975,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_len(M.ForeignMessage_encode(_val))
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 73: map_string_nested_enum


@@ 1671,7 2005,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_int32(_nv)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 74: map_string_foreign_enum


@@ 1694,7 2035,14 @@ function M.TestAllTypesProto3_encode(t)
                _m = _m + 1; entry[_m] = wire.encode_int32(_nv)
            end
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_len(table.concat(entry))
            local _b = table.concat(entry)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end
    -- field 111: oneof_uint32


@@ 1708,21 2056,36 @@ function M.TestAllTypesProto3_encode(t)
    if _of_oneof_field == "oneof_nested_message" then
        local _b = M.TestAllTypesProto3_NestedMessage_encode(v)
        n = n + 1; out[n] = "\x82\x07"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 113: oneof_string
    v = t.oneof_string
    if _of_oneof_field == "oneof_string" then
        n = n + 1; out[n] = "\x8a\x07"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 114: oneof_bytes
    v = t.oneof_bytes
    if _of_oneof_field == "oneof_bytes" then
        n = n + 1; out[n] = "\x92\x07"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 115: oneof_bool


@@ 1776,7 2139,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.BoolValue_encode(v)
        n = n + 1; out[n] = "\xca\x0c"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 202: optional_int32_wrapper


@@ 1784,7 2152,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Int32Value_encode(v)
        n = n + 1; out[n] = "\xd2\x0c"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 203: optional_int64_wrapper


@@ 1792,7 2165,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Int64Value_encode(v)
        n = n + 1; out[n] = "\xda\x0c"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 204: optional_uint32_wrapper


@@ 1800,7 2178,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.UInt32Value_encode(v)
        n = n + 1; out[n] = "\xe2\x0c"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 205: optional_uint64_wrapper


@@ 1808,7 2191,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.UInt64Value_encode(v)
        n = n + 1; out[n] = "\xea\x0c"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 206: optional_float_wrapper


@@ 1816,7 2204,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.FloatValue_encode(v)
        n = n + 1; out[n] = "\xf2\x0c"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 207: optional_double_wrapper


@@ 1824,7 2217,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.DoubleValue_encode(v)
        n = n + 1; out[n] = "\xfa\x0c"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 208: optional_string_wrapper


@@ 1832,7 2230,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.StringValue_encode(v)
        n = n + 1; out[n] = "\x82\x0d"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 209: optional_bytes_wrapper


@@ 1840,7 2243,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.BytesValue_encode(v)
        n = n + 1; out[n] = "\x8a\x0d"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 211: repeated_bool_wrapper


@@ 1850,7 2258,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.BoolValue_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1861,7 2274,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.Int32Value_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1872,7 2290,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.Int64Value_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1883,7 2306,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.UInt32Value_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1894,7 2322,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.UInt64Value_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1905,7 2338,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.FloatValue_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1916,7 2354,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.DoubleValue_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1927,7 2370,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.StringValue_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1938,7 2386,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.BytesValue_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 1947,7 2400,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Duration_encode(v)
        n = n + 1; out[n] = "\xea\x12"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 302: optional_timestamp


@@ 1955,7 2413,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Timestamp_encode(v)
        n = n + 1; out[n] = "\xf2\x12"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 303: optional_field_mask


@@ 1963,7 2426,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.FieldMask_encode(v)
        n = n + 1; out[n] = "\xfa\x12"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 304: optional_struct


@@ 1971,7 2439,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Struct_encode(v)
        n = n + 1; out[n] = "\x82\x13"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 305: optional_any


@@ 1979,7 2452,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Any_encode(v)
        n = n + 1; out[n] = "\x8a\x13"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 306: optional_value


@@ 1987,7 2465,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Value_encode(v)
        n = n + 1; out[n] = "\x92\x13"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 307: optional_null_value


@@ 2008,7 2491,12 @@ function M.TestAllTypesProto3_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = pb.wkt.Empty_encode(v)
        n = n + 1; out[n] = "\xa2\x13"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    -- field 311: repeated_duration


@@ 2018,7 2506,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.Duration_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 2029,7 2522,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.Timestamp_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 2040,7 2538,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.FieldMask_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 2051,7 2554,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.Struct_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 2062,7 2570,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.Any_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 2073,7 2586,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.Value_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 2084,7 2602,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.ListValue_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 2095,7 2618,12 @@ function M.TestAllTypesProto3_encode(t)
        for _i = 1, #v do
            local _b = pb.wkt.Empty_encode(v[_i])
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end


@@ 3921,7 4449,12 @@ function M.TestAllTypesProto3_NestedMessage_encode(t)
    if v ~= nil or type(v) == 'cdata' then
        local _b = M.TestAllTypesProto3_encode(v)
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#_b)
        local _len = #_b
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = _b
    end
    local _exts = t._extensions

M examples/expected/full/quickstart/quickstart_pb.lua => examples/expected/full/quickstart/quickstart_pb.lua +12 -2
@@ 69,7 69,12 @@ function M.User_encode(t)
    v = t.name
    if v ~= nil and v ~= '' then
        n = n + 1; out[n] = "\x12"
        n = n + 1; out[n] = wire.encode_varint(#v)
        local _len = #v
        if _len < 128 then
            n = n + 1; out[n] = string.char(_len)
        else
            n = n + 1; out[n] = wire.encode_varint(_len)
        end
        n = n + 1; out[n] = v
    end
    -- field 3: role


@@ 92,7 97,12 @@ function M.User_encode(t)
        for _i = 1, #v do
            local _b = v[_i]
            n = n + 1; out[n] = _tag
            n = n + 1; out[n] = wire.encode_varint(#_b)
            local _len = #_b
            if _len < 128 then
                n = n + 1; out[n] = string.char(_len)
            else
                n = n + 1; out[n] = wire.encode_varint(_len)
            end
            n = n + 1; out[n] = _b
        end
    end