Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:13:08+00:00 2026-06-10T06:13:08+00:00

Play lets you return a number of different types directly in your controllers, such

  • 0

Play lets you return a number of different types directly in your controllers, such as JsValue or XML along with plain text. I would like to extend this to accept protocol buffers, so I can write:

def page = Action {
    val protobuf = //...
    Ok(protobuf)
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:13:09+00:00Added an answer on June 10, 2026 at 6:13 am

    Protocol buffers in Java all inherit from a single com.google.protobuf.Message class.

    Add the following implicit conversions within the scope of your application controller:

    implicit def contentTypeOf_Protobuf: ContentTypeOf[Message] = {
      ContentTypeOf[Message](Some("application/x-protobuf"))
    }
    implicit def writeableOf_Protobuf: Writeable[Message] = {
      Writeable[Message](message => message.toByteArray())
    }
    

    These will allow Play to serialize buffers directly in a response given by a status such as Ok(protobuf)

    Update:

    I have posted a working example of the reverse situation, where the incoming request can be parsed and a protobuf can be extracted automatically.

    • https://gist.github.com/3455432

    The parser takes the form of an action in this example, tho you could also code a body parser:

    object Put extends Controller {
      def index = DecodeProtobuf(classOf[MyProtobuf]) { stack :MyProtobuf =>
        Action {
          // do something with stack
        }
      }
    }
    

    The client sending the request should serialize the buffer as a byte array, and pass it directly in the body of the request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For OneToMany relationships, play framework lets the master keep a list of slaves. A
Lets say I have image1 as Play Icon.png and image2 as pause.png . I
Play tutorial shows a way to bind dynamic parameter to URL: GET /clients/:id controllers.Clients.show(id:
in play functional tests I am executing a request to some of my controllers
I've written small gui-frontend in Python that lets users play internet radio channels. The
I made a very minimal javascript bookmarklet (~1 KB minified) that lets me play
I am relatively new to rails. I understand that rails lets you play with
Play! framework really lets you get up and running quickly, but I wonder how
I want to implement a kind of favorites list. Lets take a play list
play framework: 1.2.3 Hi, I am trying to purge my database by using play's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.