mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
state: serialize string as bytes instead of protobuf string.
Protobuf strings have to be UTF-8 encoded or 7-bit ASCII. PiperOrigin-RevId: 195902557 Change-Id: I9800afd47ecfa6615e28a2cce7f2532f04f10763
This commit is contained in:
+1
-1
@@ -335,7 +335,7 @@ func (ds *decodeState) decodeObject(os *objectState, obj reflect.Value, object *
|
||||
case *pb.Object_BoolValue:
|
||||
obj.SetBool(x.BoolValue)
|
||||
case *pb.Object_StringValue:
|
||||
obj.SetString(x.StringValue)
|
||||
obj.SetString(string(x.StringValue))
|
||||
case *pb.Object_Int64Value:
|
||||
obj.SetInt(x.Int64Value)
|
||||
if obj.Int() != x.Int64Value {
|
||||
|
||||
+1
-1
@@ -308,7 +308,7 @@ func (es *encodeState) encodeObject(obj reflect.Value, mapAsValue bool, format s
|
||||
}}}
|
||||
}
|
||||
case reflect.String:
|
||||
object = &pb.Object{Value: &pb.Object_StringValue{obj.String()}}
|
||||
object = &pb.Object{Value: &pb.Object_StringValue{[]byte(obj.String())}}
|
||||
case reflect.Ptr:
|
||||
if obj.IsNil() {
|
||||
// Handled specially in decode; store as a nil value.
|
||||
|
||||
@@ -114,7 +114,7 @@ message Float32s {
|
||||
message Object {
|
||||
oneof value {
|
||||
bool bool_value = 1;
|
||||
string string_value = 2;
|
||||
bytes string_value = 2;
|
||||
int64 int64_value = 3;
|
||||
uint64 uint64_value = 4;
|
||||
double double_value = 5;
|
||||
|
||||
@@ -30,7 +30,7 @@ func format(graph uint64, depth int, object *pb.Object, html bool) (string, bool
|
||||
case *pb.Object_BoolValue:
|
||||
return fmt.Sprintf("%t", x.BoolValue), x.BoolValue != false
|
||||
case *pb.Object_StringValue:
|
||||
return fmt.Sprintf("\"%s\"", x.StringValue), x.StringValue != ""
|
||||
return fmt.Sprintf("\"%s\"", string(x.StringValue)), len(x.StringValue) != 0
|
||||
case *pb.Object_Int64Value:
|
||||
return fmt.Sprintf("%d", x.Int64Value), x.Int64Value != 0
|
||||
case *pb.Object_Uint64Value:
|
||||
|
||||
@@ -430,6 +430,7 @@ func TestTypes(t *testing.T) {
|
||||
"",
|
||||
"foo",
|
||||
"bar",
|
||||
"\xa0",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user