Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value is not set for uint32 fields when using decorators #1809

Open
azerum opened this issue Sep 14, 2022 · 0 comments
Open

Default value is not set for uint32 fields when using decorators #1809

azerum opened this issue Sep 14, 2022 · 0 comments

Comments

@azerum
Copy link

azerum commented Sep 14, 2022

protobuf.js version: 7.10.1

Please describe the expected and actual behavior

If I create Vector message instance without setting fields, they will have default value for numbers - 0:

@Type.d()
export class Vector extends Message<Vector> {
    @Field.d(1, 'double')
    x: number;

    @Field.d(2, 'double')
    y: number;
}

const v = new Vector();
console.log(v.x, v.y); //0, 0

However, if I change types to uint32, fields are undefined:

@Type.d()
export class Vector extends Message<Vector> {
    @Field.d(1, 'uint32')
    x: number;

    @Field.d(2, 'uint32')
    y: number;
}

const v = new Vector();
console.log(v.x, v.y); //undefined, undefined

Is this intended?

P.S.

As I understand, in proto3 all fields are 'optional' in sense
that sender can omit them. However, receiver will always have a message that has
all fields set: if field was not set by the sender, it will get a default value fitting it's type (null for message types, 0 for number, false for boolean etc). Is this correct?

Also, when using decorators, does protobufjs work in proto3 or proto2 mode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant