summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZhaozhong Ni <nzz@google.com>2018-05-08 17:23:06 -0700
committerShentubot <shentubot@google.com>2018-05-08 17:23:50 -0700
commitad278d69447ddca9c6923e5e830c12f1329438b9 (patch)
tree64de050fb8971a2e9f731e1b15b85c45b5597659
parent10a2cfc6a9216cb32e3a930016178d3c15ccc383 (diff)
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
-rw-r--r--pkg/state/decode.go2
-rw-r--r--pkg/state/encode.go2
-rw-r--r--pkg/state/object.proto2
-rw-r--r--pkg/state/printer.go2
-rw-r--r--pkg/state/state_test.go1
5 files changed, 5 insertions, 4 deletions
diff --git a/pkg/state/decode.go b/pkg/state/decode.go
index 05758495b..33ec926c7 100644
--- a/pkg/state/decode.go
+++ b/pkg/state/decode.go
@@ -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 {
diff --git a/pkg/state/encode.go b/pkg/state/encode.go
index eb6527afc..1cec14f24 100644
--- a/pkg/state/encode.go
+++ b/pkg/state/encode.go
@@ -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.
diff --git a/pkg/state/object.proto b/pkg/state/object.proto
index 6595c5519..c78efed2a 100644
--- a/pkg/state/object.proto
+++ b/pkg/state/object.proto
@@ -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;
diff --git a/pkg/state/printer.go b/pkg/state/printer.go
index c61ec4a26..881125ddd 100644
--- a/pkg/state/printer.go
+++ b/pkg/state/printer.go
@@ -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:
diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go
index d5a739f18..38ad9da9c 100644
--- a/pkg/state/state_test.go
+++ b/pkg/state/state_test.go
@@ -430,6 +430,7 @@ func TestTypes(t *testing.T) {
"",
"foo",
"bar",
+ "\xa0",
},
},
{