question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass `InputStream` to `Protobuf.load`

See original GitHub issue

What is your use-case and why do you need this feature?

AFAIU, currently I can only to pass a ByteArray when deserializing data. I wonder if it would be possible to pass an InputStream instead.

I want to deserialize a variable-size data structure coming from the network, so I don’t know the exact size beforehand to create a ByteArray.

(I’m sorry if I missed some important information about the design that invalidates this question.)

Describe the solution you’d like

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fsantannacommented, Feb 13, 2020

@AlexanderShniperson ,

This is how I’m doing:

import kotlinx.serialization.protobuf.ProtoBuf

@Serializable
data class MyData (...)

val myData = MyData(...)

// from data to bytearray
val bytes: ByteArray = ProtoBuf.dump(MyData.serializer(), myData)

// from bytearray back to data
val myData2 = ProtoBuf.load(MyData.serializer(), bytes)

It’s actually very straightforward.

0reactions
qwwdfsadcommented, Jul 13, 2020

Closing as duplicate

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to parse from InputStream using Protocol Buffers when ...
I have defined in my .proto file different messages like 'Login', 'Logout', etc. and generated the java file.
Read more >
Protocol Buffer Basics: Java - Google Developers
This tutorial provides a basic Java programmer's introduction to working with protocol buffers. By walking through creating a simple example application, ...
Read more >
How to resolve a custom option in a protocol buffer ...
I'm using protocol buffers 2.5 with Java. I have a proto file that defines a custom option. Another proto file uses that custom...
Read more >
Protocol Buffers & A Spring Boot Example
Protocol buffers is a method of serializing data , like XML and JSON. ... convert protocol buffer messages in the form of an...
Read more >
TIBCO Adapters for Google Protocol Buffers Sample
Running the Protobuf Sample in StreamBase Studio · In the Project Explorer view, open the sample you just loaded. · Open the src/main/eventflow/...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found