Skip to content

Which JS types are valid in fromObject, create, and encode? #719

@seishun

Description

@seishun

For instance, in which cases am I allowed to specify enum values as strings rather than numbers?

syntax = "proto3";

message DeviceReadings {
  enum Foo {
    ONE = 0;
    TWO = 1;
  } 

  Foo foo = 1;
}

When I use a string in encode it seems to fall back to the default value:

> DeviceReadings.decode(DeviceReadings.encode({foo: 'TWO'}).finish())
DeviceReadings { foo: 0 }

But if I go through fromObject first then it works:

> DeviceReadings.decode(DeviceReadings.encode(DeviceReadings.fromObject({foo: 'TWO'})).finish())
DeviceReadings { foo: 1 }

But with create it works the same as encode alone:

> DeviceReadings.decode(DeviceReadings.encode(DeviceReadings.create({foo: 'TWO'})).finish())
DeviceReadings { foo: 0 }

Is all that documented somewhere?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions