Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Cómo serializar enumeración en borsh-js

Intentando serializar un objeto en Rust y deserializarlo en JS Obtuvimos el hash 000100000031, después de la serialización esto:

 pub enum Service { Stackoverflow, Twitter, Telegram, } pub struct ServiceId { pub service: Service, pub id: ExternalId, }

Cuando intente deserializar en JS, use esto:

 const Service = { Stackoverflow: 0, Twitter: 1, Telegram: 2 } class ServiceId { constructor(service, id) { this.service = service this.id = id } } const value = new ServiceId(Service.Stackoverflow, userId) const schema = new Map([ [ServiceId, { kind: 'struct', fields: [['service', 'u8'], ['id', 'string']] }] ]);

Después de la deserialización, obtuvimos esto, pero es incorrecto porque tenemos un objeto dentro de un objeto y un parámetro de identificación redundante:

 ServiceId { service: { service: undefined, id: '1' }, id: undefined }

En primer lugar, podría deberse a que en Rust tenemos el tipo de enumeración, entonces, ¿cómo podemos usar la enumeración en borsh-js? En segundo lugar, si no, ¿por qué tenemos resultados incorrectos?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Es difícil de entender a partir de la documentación, pero necesita crear su clase de esta manera y todo estará bien.

 class ServiceId { constructor({ service, id }) { this.service = service this.id = id } } new ServiceId({ service: 'lol', id: 'kek' })

Por lo tanto, debe pasar sus parámetros como objeto.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!