Giter VIP home page Giter VIP logo

Comments (3)

mtwichel avatar mtwichel commented on May 12, 2024 3

Hey @nosmirck 👋! I was interested in using protobufs as well so I played around with it and it looks totally supported by the current package with existing tools.

Basically, you can using the protoc CLI tool to generate the Dart objects for your protobuf messages, and it generates all your Dart classes.

You can then use those objects with dart_frog like this

import 'package:dart_frog/dart_frog.dart';
import 'package:protobuf_play/model.dart';

Response onRequest(RequestContext context) {
  final person = Person(
    id: 3,
    email: '[email protected]',
    name: 'Tester McTesterson',
    phones: [
      Person_PhoneNumber(
        number: '+14068675309',
        type: Person_PhoneType.HOME,
      )
    ],
  );

  return Response.bytes(
    body: person.writeToBuffer(),
  );
}

All your generated classes also have a factory constructor called fromBuffer which makes them super easy to convert from the Uint8List of bytes back into a useful object on the frontend side of things.

I created a little example repo showing how to use this: https://github.com/mtwichel/protobuf_play. @felangel , let me know if you want me to make a PR adding it as an example in this repo - I'd be happy to clean it up and share 💙

from dart_frog.

felangel avatar felangel commented on May 12, 2024 2

As discussed, closing this issue since the answer provided by @mtwichel is quite thorough and illustrates the steps needed to use protobuf in the context of a Dart Frog application.

from dart_frog.

mtwichel avatar mtwichel commented on May 12, 2024

@felangel Now that we have expanded examples, would it be okay if I merged in my protobuf example and made it a tutorial? I would also make sure it has test coverage and all that jazz.

from dart_frog.

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.