hyperweb-io / hyperweb-io/telescope

struct wrap and unwrap

Open
#41 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
154
Forks
53
PR merge metrics
No merged PRs in 30d

Description

Things that use `Struct` have special handling

```js
// from ts-proto codebase
const unwrap = (decodedValue: any): Code => {
if (isListValueType(field) || isStructType(field) || isAnyValueType(field) || isFieldMaskType(field)) {
return code`${type}.unwrap(${decodedValue})`;
}
return code`${decodedValue}.value`;
};
```

https://github.com/pyramation/protobuf-example-reference/blob/master/ts/google/api/servicecontrol/v1/log_entry.ts#L205

```js
wrap(object: {
[key: string]: any;
} | undefined): Struct {
const struct = createBaseStruct();

if (object !== undefined) {
Object.keys(object).forEach(key => {
struct.fields[key] = object[key];
});
}

return struct;
},

unwrap(message: Struct): {
[key: string]: any;
} {
const object: {
[key: string]: any;
} = {};
Object.keys(message.fields).forEach(key => {
object[key] = message.fields[key];
});
return object;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.