Skip to content

Commit

Permalink
Merge pull request #331 from howardpen9/main-4
Browse files Browse the repository at this point in the history
Update crc32.md content, adding Typescript example
  • Loading branch information
reveloper authored Aug 21, 2023
2 parents 1dd4206 + 01cd49d commit 327ec1d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/develop/data-formats/crc32.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,21 @@ func main() {
binary.BigEndian.PutUint32(b_data, crc)
var res = hex.EncodeToString(b_data)
fmt.Println(res)
}
```

### TypeScript
```typescript
import * as crc32 from 'crc-32';

function calculateRequestOpcode_1(str: string): string {
return (BigInt(crc32.str(str)) & BigInt(0x7fffffff)).toString(16);
}

function calculateResponseOpcode_2(str: string): string {
const a = BigInt(crc32.str(str));
const b = BigInt(0x80000000);
return ((a | b) < 0 ? (a | b) + BigInt('4294967296') : a | b).toString(16);
}
```

0 comments on commit 327ec1d

Please sign in to comment.