mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-03-10 16:14:39 +00:00
The v1 wire marshaler sorts fields as follows: - All extensions, sorted by field number. - All non-oneof fields, sorted by field number. - All oneof fields, in indeterminate order. We already make some steps toward supporting this ordering: The fast path encoder places extensions in sorted order at the start of the message. This commit moves oneof fields to the end of the message, makes the reflection-based encoder use this ordering when deterministic marshaling is enabled, and adds a test to catch unintentional changes to the ordering. Users SHOULD NOT depend on stability of the marshal output. It is subject to change over time. Without deterministic marshaling enabled, it is subject to change over calls to Marshal. Change-Id: I6cfd89090d790a3bb50785f32b94d2781d7d08db Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/206800 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
30 lines
604 B
Protocol Buffer
30 lines
604 B
Protocol Buffer
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Messages in this file are used to test wire encoding order.
|
|
|
|
syntax = "proto2";
|
|
|
|
package goproto.proto.order;
|
|
|
|
option go_package = "google.golang.org/protobuf/internal/testprotos/order";
|
|
|
|
message Message {
|
|
optional string field_2 = 2;
|
|
optional string field_1 = 1;
|
|
|
|
oneof oneof_1 {
|
|
string field_10 = 10;
|
|
}
|
|
|
|
extensions 30 to 40;
|
|
|
|
optional string field_20 = 20;
|
|
}
|
|
|
|
extend Message {
|
|
optional string field_30 = 30;
|
|
optional string field_31 = 31;
|
|
optional string field_32 = 32;
|
|
}
|