Coder Social home page Coder Social logo

What is encoding of string? about grpc-go HOT 7 CLOSED

grpc avatar grpc commented on July 19, 2024
What is encoding of string?

from grpc-go.

Comments (7)

iamqizhao avatar iamqizhao commented on July 19, 2024

If you change

fmt.Println(person)

to

fmt.Println(person.Name)

it works fine. This means fmt.Println does not work well with proto message. gRPC is just fine. I am going to to talk to goprotobuf team to get help.

from grpc-go.

dsymonds avatar dsymonds commented on July 19, 2024

Are you sure that's not your terminal setup, @mattn? The protobuf package treats strings as opaque byte sequences. I don't think this has anything to do with fmt.Println or proto messages.

from grpc-go.

iamqizhao avatar iamqizhao commented on July 19, 2024

Hi David,

Simply on my desktop, I got

person := &pb.Person{
Name: "ほげ",
Age: int32(1),
}
fmt.Println(person)

output:
name:"\343\201\273\343\201\222" age:1

fmt.Println(person.Name)

output:
ほげ

On Fri, Feb 27, 2015 at 2:30 PM, David Symonds [email protected]
wrote:

Are you sure that's not your terminal setup, @mattn
https://github.com/mattn? The protobuf package treats strings as opaque
byte sequences. I don't think this has anything to do with fmt.Println or
proto messages.


Reply to this email directly or view it on GitHub
#84 (comment).

from grpc-go.

dsymonds avatar dsymonds commented on July 19, 2024

fmt.Println(person) is rendering the protobuf message in the standardised text format, which specifies using octal escapes for non-ASCII (see https://github.com/golang/protobuf/blob/master/proto/text.go#L476). This is working as intended.

from grpc-go.

mattn avatar mattn commented on July 19, 2024

http://play.golang.org/p/ENZjynLjV_

Ah, right. protobuf's textWriter seems to avoid to print non-ASCII as @dsymonds says. Should be used unicode.IsPrint instead?

from grpc-go.

dsymonds avatar dsymonds commented on July 19, 2024

from grpc-go.

mattn avatar mattn commented on July 19, 2024

fair enoguh.

from grpc-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.