Skip to content

Why don't write when enum field value is 0 #77

Description

@skysbird

valueTest = `opts.writeDefaults === true || (obj.${name} != null && __${fieldDef.type}Values[obj.${name}] !== 0)`

message HopMessage {
   enum Type {
     RESERVE = 0;
     CONNECT = 1;
     STATUS = 2;
 }
  required Type type = 1;
  optional Peer peer = 2;
  optional Reservation reservation = 3;
  optional Limit limit = 4;
  optional Status status = 5;
   }

When I protons this proto, it will gnenerate the code like this:

export const codec = (): Codec<HopMessage> => {
if (_codec == null) {
  _codec = message<HopMessage>((obj, w, opts = {}) => {
    if (opts.lengthDelimited !== false) {
      w.fork()
    }

    if (opts.writeDefaults === true || (obj.type != null && ___TypeValues[obj.type] !== 0) {
      w.uint32(8)
      HopMessage.Type.codec().encode(obj.type, w)
    }

This will cause the wrong binary data(MALFORM) when I encode the HopMessage with type value is RESERVE when the relay node is kubo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions