How to hexlify the serialized data?

Issue #1 closed
created an issue

Hi, I just read the post , and I know we could serialize and deserialize by both racket:

$ racket serialize.rkt | racket deserialize.rkt

I was wondering how could I serialize in Racket and deserialize in another language like python?

For example, in python

$ cat personinfo.proto
syntax = "proto2";
package personinfo;

message Person {
    required string name = 1;

And using python to serialize it

import personinfo_pb2
import binascii

person = personinfo_pb2.Person() = "Holy"
packed_data = person.SerializeToString()
print binascii.hexlify(packed_data)

Is there function like SerializeToString of python?

Comments (5)

  1. liweijian reporter

    En, but actually it just show Holy"", but not 0a04486f6c79 as expected.

    #lang racket
    (require (planet murphy/protobuf))
    (require "personinfo.rkt")
    (require file/sha1)
    (define p (person* #:name "Holy"))
      (λ (out) 
        (serialize p))))

    With personinfo.rkt

    #lang racket/base
    ;; Generated using protoc-gen-racket v1.1
    (require (planet murphy/protobuf:1/syntax))
    (define-message-type person ((required primitive:string name 1)))
    (provide (all-defined-out))
  2. Thomas Chust repo owner

    Creating a byte string output port but not writing to that port is, of course, not very helpful.

    Scheme I/O procedures usually accept a port to operate on as an optional argument and use the standard input or output port if no port is given explicitly. serialize is no exception and here it should be used like this:

      (λ (out) 
        (serialize p out))))

    Or like this:

      (λ () 
        (serialize p))))

    Of course, spending a minute to actually read some basic documentation would have prevented this kind of mistake :-/

  3. Log in to comment